我有代码使用OMP与#pragma omp critical
,但没有#pragma omp barrier
。然而,在Visual Studio 2008中我的程序崩溃调试版本与#预编译器插入的#pragma omp barrier?
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();
}
你能后,给你错误的代码?有时关闭支架可能意味着障碍。 – VAndrei 2014-10-17 10:49:16
我不希望OpenMP构造出现在STL中,因此您应该深入研究“Evaluator :: evaluate()”的源代码及其调用的函数并在那里搜索OpenMP障碍。 – 2014-10-17 14:30:58
这只是我自己的代码,我知道没有进一步使用OpenMP。顺便说一句,只有在引发异常时才会出现问题。 – Philipp 2014-10-20 08:18:17