我的代码使用OMP与#pragma omp critical
,但没有#pragma omp barrier
。然而,在Visual Studio 2008的调试版本中,我的程序崩溃了
Fatal User Error 1002: '#pragma omp barrier' improperly nested in '#pragma omp critical'
是否有可能自动插入#pragma omp barrier
,可能是在try / catch块中?有没有办法获得更多的诊断信息,例如究竟存在哪个问题?
编辑:这是代码的结构。我使用omp critical
来捕获和记住异常以及访问共享变量时。它是所有单行块。
std::vector<RunResult> runResults;
Evaluator evaluator;
std::vector<std::runtime_error> exceptionsDuringParallelExecution;
SomeType someVariable; //used as private variable later
#pragma omp parallel
{
#pragma omp for private(someVariable)
for (int monteCarloLoopCounter=monteCarloCounterOffset;monteCarloLoopCounter<numMonteCarloRuns+monteCarloCounterOffset;monteCarloLoopCounter++)
{
bool hasException = false;
#pragma omp critical(exceptionAccess)
{
hasException = exceptionsDuringParallelExecution.empty() == false;
}
if (hasException == false)
{
try
{
RunResult runRes;
//some nested loop:
for (unsigned int j = 0;j<10;j++)
{
while (someVariable->condition())
{
for (unsigned int i=0;i<20; i++)
{
if (someCondition)
{
//calculate something
#pragma omp critical
evaluator.evaluate(something);
}
}
}
runRes.setSomeResult();
}
#pragma omp critical
runResults.push_back(runRes);
}
catch (std::exception& e)
{
#pragma omp critical(exceptionAccess)
exceptionsDuringParallelExecution.push_back(std::runtime_error(e.what()));
}
catch (...)
{
#pragma omp critical(exceptionAccess)
exceptionsDuringParallelExecution.push_back(std::runtime_error("Unexpected exception"));
}
}
}
}
if (exceptionsDuringParallelExecution.empty() == false)
{
throw exceptionsDuringParallelExecution.front();
}
答案 0 :(得分:0)
我在你的代码中看到了四个#pragma omp critical
指令(除了第一个之外的所有指令),这些指令不遵循紧跟括号括起来的块所需的语法。
The documentation显示了所需的语法:
#pragma omp critical [(name)]
{
code_block
}