一、openMP简单测试

 1、简述

  • openMP很多情况下对于利用多核处理器进行加速是很有效果的,然而,也有一些情况是openMP不但没有效果,甚至还有一些反作用。

  2、简单测试(1)

  • #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;
    }
    View Code

相关文章:

  • 2021-09-24
  • 2021-08-13
  • 2022-12-23
  • 2021-08-20
  • 2022-01-26
  • 2021-09-15
  • 2021-12-05
  • 2022-02-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2021-11-16
  • 2021-10-24
  • 2022-01-14
相关资源
相似解决方案