网上的教程中,一般提供的是Visual Studio配置OpenMP的方法,但是Dev C++轻量简洁的特性使得初学分布式学习的同学更容易上手。那么如何在Dev C++中配置OpenMP呢?
一般来讲,omp.h已经安装在你的电脑上了。所以可以直接调用。但是编译的时候需要加上-fopenmp一句才可以成功编译。具体做法是,工具栏-工具-编译选项-勾选“编译时加入如下命令”-输入“-fopenmp”即可。
配置成功之后不妨运行一下这个程序:
#include<stdio.h>
#include<stdlib.h>
#include "omp.h"
int main(){
int nthreads,tid;
#pragma omp parallel private(nthreads,tid) num_threads(10)
{
tid = omp_get_thread_num();
if(tid == 0){
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
printf("Hello World from thread = %d\n", tid);
return 0;
}