SHARE
TWEET

Untitled

a guest Jan 21st, 2020 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <omp.h>
  3.     const int n=2000;
  4.     double matrica_rezultat[n][n];
  5.     double t1,t2, t_ukupno_1, t_ukupno_2;
  6.  
  7. using namespace std;
  8. int main(int argc, char* argv[]) {
  9.     t_ukupno_1=omp_get_wtime();
  10.     int br_niti=5;
  11.     double **matrica;
  12.     double **matrica_dva;
  13.     int i,j,k = 0;
  14.     matrica = new double *[n];
  15.     for (int count = 0; count < n; count++)
  16.         matrica[count] = new double [n];
  17.        
  18.     matrica_dva = new double *[n];
  19.     for (int count = 0; count < n; count++)
  20.         matrica_dva[count] = new double [n];
  21.  
  22.     for(i=0;i<n;i++){
  23.         for(j=0;j<n;j++){
  24.             matrica[i][j]=i+1.1555333;
  25.             matrica_dva[i][j]=i+1.178245;
  26.         }
  27.     }
  28.     cout<<endl;
  29.    
  30.     cout << "broj aktivnih niti: "<< omp_get_num_threads() <<endl;
  31.  
  32.     omp_set_num_threads(br_niti);
  33.  
  34.     t1=omp_get_wtime();
  35.     #pragma omp parallel shared(matrica, matrica_dva, matrica_rezultat) private(i, j, k)
  36.        
  37.     {  
  38.      #pragma omp for
  39.      for(i=0; i<n; ++i)
  40.         for(j=0; j<n; ++j)
  41.             for(k=0; k<n; ++k) {
  42.                 matrica_rezultat[i][j]+=matrica[i][k]*matrica_dva[k][j];
  43.             }
  44.     }
  45.     t2=omp_get_wtime();
  46.     cout<<"paralelno vrijeme: "<<t2-t1<<" s"<<endl;
  47.     t_ukupno_2=omp_get_wtime();
  48.     cout<<"Ukupno vrijeme: "<<t_ukupno_2-t_ukupno_1<<" s"<<endl;
  49.     return 0;
  50. }
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