VS2019配置OpenMP
VS2019配置OpenMP
新建Cpp文件,输入以下代码
#include <cstdio>
#include <omp.h>
int main(int argc, char *argv[]) {
int nthreads, tid;
/* Fork a team of threads with each thread having a private tid variable */
#pragma omp parallel private(tid)
{
/*Obtain and print thread id*/
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0) {
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
}/*All threads join master thread and terminate */
return 0;
}
运行后会报错或与预料输出不符
右键项目名,打开属性面板,调整以下配置
调整后再次运行即可