C++ 预处理器插入的pragma omp屏障?

C++ 预处理器插入的pragma omp屏障?,c++,openmp,C++,Openmp,我有使用OMP的代码,带有pragma OMP critical,但没有pragma OMP屏障。然而,在VisualStudio2008中的调试构建中,我的程序在以下情况下崩溃: Fatal User Error 1002: '#pragma omp barrier' improperly nested in '#pragma omp critical' 这样的pragma omp屏障是否可能自动插入,可能是在try/catch块中?是否有任何方法可以获得更多诊断信息,例如,该问题究竟存在于

我有使用OMP的代码,带有pragma OMP critical,但没有pragma OMP屏障。然而,在VisualStudio2008中的调试构建中,我的程序在以下情况下崩溃:

Fatal User Error 1002: '#pragma omp barrier' improperly nested in '#pragma omp critical'
这样的pragma omp屏障是否可能自动插入,可能是在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();            
            }
我在代码中看到四条pragma-omp-critical指令,除了第一条指令外,其他指令都没有遵循紧跟大括号括起的块所需的语法

显示所需的语法:

#pragma omp critical [(name)]
{
   code_block
}

你能发布给你错误的代码吗?有时关闭括号可能意味着障碍。我不希望OpenMP构造出现在STL中,因此您应该深入了解Evaluator::evaluate的源代码及其调用的函数,并在那里搜索OpenMP障碍。这只是我自己的代码,我知道OpenMP没有进一步的用途。顺便说一句,只有在抛出异常时才会出现问题。感谢您的提示,我不知道文档中要求这样做,即使是对于单行块也是如此。不幸的是,它并没有改变行为。的作用域是一个结构化块,可以是一条语句,也可以是一个用大括号括起来的语句块。在前一种情况下不需要大括号。@HristoIliev:如果是这样,您应该提交一个文档错误。因为现在,文档表明大括号是非可选的。