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

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

本文关键字:openmp 是否 C++ 何测试 测试      更新时间:2023-10-16

我有一个程序,可以对一堆图像进行独立计算。这似乎是一个使用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"而不是"pararell"。