openMP并行学习1

来源:互联网 发布:天谕萝莉捏脸数据图 编辑:程序博客网 时间:2024/05/16 08:04

直接新建win32工程,添加C++代码后,在属性语言修改“支持openMP”:

#include "stdafx.h"#include<omp.h>#include <iostream>using namespace std; //循环测试函数void test(){       for(inti=0;i<10000;i++)       {       }} int _tmain(int argc, _TCHAR* argv[]){       cout<<"这是一个并行测试程序!\n";       doublestart = omp_get_wtime( );//获取起始时间        #pragma ompparallel for       for(inti = 0; i < 10000; i++)       {              test();       }        doubleend = omp_get_wtime( );       cout<<"计算耗时为:"<<end -start<<"\n";        cin>>end;       return0;}

并行程序:

//#include "stdafx.h"#include<omp.h>#include<iostream>using namespace std;//循环测试函数void test(){for(int i=0;i<10000;i++){}}int main(){cout<<"这是一个串行测试程序!\n";double start = omp_get_wtime( );//获取起始时间for(int i = 0; i < 10000; i++){test();}double end = omp_get_wtime( );cout<<"计算耗时为:"<<end -start<<"\n";cin>>end;return 0;}

10000*10000啊,真是不做不知道啊,并行原来如此给力!!

原创粉丝点击