SHARE
TWEET

LV5

a guest Jan 21st, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <omp.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <time.h>
  5. #include <stdlib.h>
  6. using namespace std;
  7. const int dim=2000;
  8.  
  9.  
  10. int main(){
  11.  
  12. double threadTime,duration,t1,t2;
  13. double *A,*B,*C;
  14. //double* A = new double[dim*dim];
  15. //double* B = new double[dim*dim];
  16. //double* C = new double[dim*dim];
  17. //double Aa[dim][dim],Ba[dim][dim],Ca[dim][dim];
  18. int id_niti=0,br_niti=4;
  19. srand(time(NULL));
  20.  
  21. A= new double[dim*dim];
  22. B= new double[dim*dim];
  23. C= new double[dim*dim];
  24.  
  25. for(int i=0;i<dim;i++){
  26.     for(int j=0;j<dim;j++){
  27.     A[i*dim + j]=((double)rand() / RAND_MAX) * 20;
  28.     B[i*dim + j]=((double)rand() / RAND_MAX) * 20;
  29.     //A[i][j]=((double)rand() / RAND_MAX) * 20;
  30.     //B[i][j]=((double)rand() / RAND_MAX) * 20;
  31.     }
  32. }
  33.  
  34. /*for(int i=0;i<dim;i++){
  35.     for(int j=0;j<dim;j++){
  36.     cout<<A[i*dim + j]<<endl;
  37.     cout<<B[i*dim + j]<<endl;
  38.    
  39.     }
  40. }*/
  41.  
  42. omp_set_num_threads(br_niti);
  43. t1=omp_get_wtime();
  44. #pragma omp parallel
  45. {
  46.     int i,j,k;
  47.     threadTime=omp_get_wtime();
  48.     #pragma omp for schedule(dynamic,1) nowait private(i,j,k)
  49.         for(i=0;i<dim;i++) for(j=0;j<dim;j++) for(k=0;k<dim;k++) C[i*dim + j]+=A[i*dim + k]+B[k*dim + j];
  50.         //C[i][j]+=A[i][k]*B[k][j];
  51.     cout<<omp_get_thread_num()<<" thread izvrŇ°ava: "<<omp_get_wtime()-threadTime<<endl;
  52. }
  53.  
  54. t2=omp_get_wtime();
  55.  
  56. duration=t2-t1;
  57.  
  58.  
  59.  
  60. cout<<"Duljina izvodenja: "<<duration<<endl;
  61.  
  62. }
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