我有代碼使用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