-
-
Save wangyu-/b48a05c67dc2adb99afd9c09e2a49664 to your computer and use it in GitHub Desktop.
Revisions
-
metallurgix revised this gist
Jul 15, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,10 +20,10 @@ int main() omp_set_num_threads(omp_get_num_procs()); for (i= 0; i< N; i++) for (j= 0; j< N; j++) { A[i][j] = 2; B[i][j] = 2; } gettimeofday(&tv1, &tz); #pragma omp parallel for private(i,j,k) shared(A,B,C) for (i = 0; i < N; ++i) { -
metallurgix created this gist
Jul 15, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <omp.h> #include <sys/time.h> #define N 1000 int A[N][N]; int B[N][N]; int C[N][N]; int main() { int i,j,k; struct timeval tv1, tv2; struct timezone tz; double elapsed; omp_set_num_threads(omp_get_num_procs()); for (i= 0; i< N; i++) for (j= 0; j< N; j++) { A[i][j] = 2; B[i][j] = 2; } gettimeofday(&tv1, &tz); #pragma omp parallel for private(i,j,k) shared(A,B,C) for (i = 0; i < N; ++i) { for (j = 0; j < N; ++j) { for (k = 0; k < N; ++k) { C[i][j] += A[i][k] * B[k][j]; } } } gettimeofday(&tv2, &tz); elapsed = (double) (tv2.tv_sec-tv1.tv_sec) + (double) (tv2.tv_usec-tv1.tv_usec) * 1.e-6; printf("elapsed time = %f seconds.\n", elapsed); /*for (i= 0; i< N; i++) { for (j= 0; j< N; j++) { printf("%d\t",C[i][j]); } printf("\n"); }*/ }