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;
}

运行后会报错或与预料输出不符

image-2022w0101164048058

右键项目名,打开属性面板,调整以下配置

image-2022q0101163731411

调整后再次运行即可

image-20220q101165708649

posted @   嘿,抬头!  阅读(419)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示