//选修课程啦:简单记录之。 -for_wind
一、简介
OpenMP是一种可用Fortran,C以及C++在共享地址空间上进行编程的API。【本博客内语言采用C/C++】
Open命令提供对并发、同步以及数据处理的支持,但不需要显示设置互斥锁、条件变量、数据范围以及初始化。
OpenMp is an API for shared memory programming.
It is designed for systems in which each thread or process can potentially have access to all available memory.
二、开发环境配置
VS2012下,新建一个项目并右键点击“属性”,依次进入“配置属性”-->“C/C++”-->“语言”,设置右侧的第五个选项,“OpenMP支持”设定为“是(/openmp)”,这样就完成了开发环境的设定;
【特别提醒:每个项目都需要进行如上步骤哦。】
程序没有问题,可调试thread一直为1,查看是否忘记配置环境了。
三、helloword
#include <iostream>
#include <omp.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
omp_set_num_threads(4);
# pragma omp parallel
cout<<"hello world! NO."<<omp_get_thread_num()<<endl;
return 0;
}