标签:library bsp std code view com UI 作用 idt
1、简述
openMP很多情况下对于利用多核处理器进行加速是很有效果的,然而,也有一些情况是openMP不但没有效果,甚至还有一些反作用。
#include<omp.h> #include<time.h> #include<iostream> using namespace std; void openMP() { int i,j; for(i=0; i<200; i++) { for( j = 0; j < 10; j++) j++; } } int main() { time_t start,end1; time( &start ); double omp_start = omp_get_wtime( ); int N = 100000000; int i,j; #pragma omp parallel for(int m = 0; m < N ; m++) { openMP(); } double omp_end = omp_get_wtime( ); time( &end1 ); std::cout<<"used_times "<<end1 - start<<"\n"; std::cout<<"omp_times "<<omp_end - omp_start<<"\n"; return 0; }
#include<omp.h> #include<time.h> #include<iostream> using namespace std; void openMP() { int i,j; for(i=0; i<200000000; i++) { for( j = 0; j < 100; j++) j++; } } int main() { time_t start,end1; time( &start ); double omp_start = omp_get_wtime( ); int N = 1; int i,j; #pragma omp parallel for for(int m = 0; m < N ; m++) { openMP(); } double omp_end = omp_get_wtime( ); time( &end1 ); std::cout<<"used_times "<<end1 - start<<"\n"; std::cout<<"omp_times "<<omp_end - omp_start<<"\n"; return 0; }
Guide into OpenMP : http://bisqwit.iki.fi/story/howto/openmp/
标签:library bsp std code view com UI 作用 idt
原文地址:http://www.cnblogs.com/bamtercelboo/p/7116086.html