Advertisement
AlexMatveev

MatrixMul2

Apr 23rd, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "omp.h"
  3.  
  4. #define N 10000
  5. #define NUM_THREADS 8
  6.  
  7. int main(){
  8.  
  9.     static int a[N][N], b[N][N], c[N][N]={0};
  10.     int i, j, k;
  11.  
  12.     for(i=0;i<N;i++)
  13.         for(j=0;j<N;j++){
  14.             a[i][j] = i + j;
  15.             b[i][j] = N * N - i - j;
  16.         }
  17.    
  18.    
  19.     double start = omp_get_wtime();
  20.    
  21.     omp_set_num_threads(NUM_THREADS);
  22.     #pragma omp parallel for
  23.     for(i = 0; i < N; i++)
  24.         for(j = 0; j < N; j++)
  25.             for(k = 0; k < N; k++)
  26.                 c[i][j] += a[i][k]*b[k][j];
  27.    
  28.     double end = omp_get_wtime();
  29.  
  30.     printf("%f",end-start);
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement