SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int min = 0;
  2. int myr = 0;  
  3. int temp[SIZE][SIZE];
  4. int size = 0;
  5. ...//some initialization
  6.  
  7. omp_set_num_threads(1);
  8. start_time = omp_get_wtime();
  9.     #ifdef _OPENMP
  10.     #pragma omp parallel for firstprivate(min, size) reduction(+:myr)
  11.     #endif
  12.     for(int i = 0; i < size; i++){
  13.         min = INFINITY;
  14.         for(int j = 0; j < size; j++){
  15.                 if (temp[i][j] < min)                
  16.                     min = temp[i][j];                        
  17.         }
  18.         myr+=min;
  19.         for(int j = 0; j < size; j++)
  20.                 temp[i][j]-=min;
  21.     }
  22. end_time = omp_get_wtime();
  23.    
  24. int const size0 = size;
  25. #ifdef _OPENMP
  26. #pragma omp parallel for reduction(+:myr)
  27. #endif
  28. for(int i = 0; i < size0; i++){
  29.     int min = INFINITY;
  30.     int * tmp = temp[i];
  31.     for(int j = 0; j < size0; j++){
  32.             if (tmp[j] < min)                
  33.                 min = tmp[j];                        
  34.     }
  35.     for(int j = 0; j < size0; j++)
  36.             tmp[j]-=min;
  37.     myr+=min;
  38. }
  39.    
  40. #pragma omp parallel private(myr_private) shared(myr)
  41. {
  42.     myr_private = 0;
  43.     #pragma omp for
  44.     for(int i = 0; i < size; i++){
  45.         int min = INFINITY;
  46.         int * tmp = temp[i];
  47.         for(int j = 0; j < size; j++){
  48.             if (tmp[j] < min)                
  49.                 min = tmp[j];                        
  50.         }
  51.         for(int j = 0; j < size; j++)
  52.             tmp[j]-=min;
  53.         myr_private+=min;
  54.     }
  55.     #pragma omp critical
  56.     {
  57.         myr+=myr_private;
  58.     }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top