如何测试 C++ 是否正在使用 openmp?

How can I test whether C++ is using openmp?

我有一个程序可以对一堆图像进行独立计算。这似乎是使用 OpenMP 的好主意:

//file: WoodhamData.cpp
#include <omp.h>

...

void WoodhamData::GenerateLightingDirection() {
    int imageWidth = (this->normalMap)->width();
    int imageHeight = (this->normalMap)->height();
    #pragma omp paralell for num_threads(2)
    for (int r = 0; r < RadianceMaps.size(); r++) {
        if (omp_get_thread_num() == 0){
            std::cout<<"threads="<<omp_get_num_threads()<<std::endl;
        }
        ...
    }
}

为了使用 OpenMP,我将 -fopenmp 添加到我的 makefile,因此它输出:

g++ -g -o test.exe src/test.cpp src/WoodhamData.cpp -pthread -L/usr/X11R6/lib -fopenmp --std=c++0x -lm -lX11 -Ilib/eigen/ -Ilib/CImg

但是,我很遗憾地说,我的程序报告 threads=1(运行 来自终端 ./test.exe ...

有谁知道哪里出了问题?这是我程序中最慢的部分,如果能加快一点就好了。

您的 OpenMP 指令是错误的 - 它是 "parallel" 而不是 "paralell"。