使用cmake配置qt项目时利用openmp

首先,把以下代码加入cmakelists.txt中:

FIND_PACKAGE( OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()


然后cmake编译

加入头文件:

#include <omp.h>
以及如下代码:
#pragma omp parallel
    {
        printf("hello world! ThreadID = %d\n", omp_get_thread_num());
    }
    cout << endl;
编译运行结果如下:


你可能感兴趣的:(qt,cmake,openmp)