并行计算—OpenMP—共享与私有

来源:互联网 发布:提问软件 编辑:程序博客网 时间:2024/05/16 09:29
// OpenMP1.cpp : 定义控制台应用程序的入口点。// 共享变量和私有变量#include "stdafx.h"#include <omp.h>#include <time.h>#include <Windows.h>int _tmain(int argc, _TCHAR* argv[]){omp_set_num_threads(2);int share_a=0;    //共享变量int share_to_private_b=1;    //共享变量int i;       #pragma omp parallel shared(i)   //不能改变for循环中的i是私有的{int private_c=2;           //私有变量        #pragma omp for private(share_to_private_b)for(int i=0;i<10;i++){share_to_private_b=i;printf("ThreadID %d:%d\n",omp_get_thread_num(),share_to_private_b);}}system("pause");return 0;}

运行结果:


0 0
原创粉丝点击