现在的位置: 首页 > 综合 > 正文

openMP-hello word

2018年04月03日 ⁄ 综合 ⁄ 共 423字 ⁄ 字号 评论关闭

这周开始接触openMP,展示第一个openMP程序,以后继续学习。

这个程序测试了openMP中for并行化的作用域,在vs2010中测试,要打开openMP的支持。否则没效果

/*
    功能:循环并行化
	作者:刘荣
	时间:2012.11.15
*/
#include<iostream>
#include<time.h>
#include<windows.h>
//变量声明


int main()
{
	int i;
    #pragma omp parallel for
	for( i = 0; i < 5; i++)
	{
		//Sleep(1000);
		for(int j = 6; j < 10; j++)
		{
			//Sleep(100);
			printf("i = %d, j = %d,\n",i,j);

		}
	}
	printf("\n\n");

	for(int i = 0; i < 2; i++)
	{
		#pragma omp parallel for
		for(int j = 6; j < 10; j++)
		{
			printf("i = %d, j = %d,\n",i,j);

		}
	}

	return 0;
}

 

抱歉!评论已关闭.