fork(1) download
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #define N 1000
  6. float A[N][N], B[N][N], C[N][N]; // declaring matrices of NxN size
  7. int main ()
  8. {
  9. /* DECLARING VARIABLES */
  10. int i, j, m; // indices for matrix multiplication
  11. float t_1; // Execution time measures
  12. clock_t c_1, c_2;
  13. /* FILLING MATRICES WITH RANDOM NUMBERS */
  14. srand ( time(NULL) );
  15. for(i=0;i<N;i++) {
  16. for(j=0;j<N;j++) {
  17. A[i][j]= (rand()%10);
  18. B[i][j]= (rand()%10);
  19. }
  20. }
  21. /* MATRIX MULTIPLICATION */
  22. printf("Max number of threads: %i \n",omp_get_max_threads());
  23. #pragma omp parallel
  24. printf("Number of threads: %i \n",omp_get_num_threads());
  25. c_1=time(NULL); // time measure: start mm
  26. #pragma omp parallel for private(m,j)
  27. // #pragma omp_set_num_threads(8)
  28. for(i=0;i<N;i++) {
  29. for(j=0;j<N;j++) {
  30. C[i][j]=0.; // set initial value of resulting matrix C = 0
  31. for(m=0;m<N;m++) {
  32. C[i][j]=A[i][m]*B[m][j]+C[i][j];
  33. }
  34. // printf("C: %f \n",C[i][j]);
  35. }
  36. }
  37. /* TIME MEASURE + OUTPUT */
  38. c_2=time(NULL); // time measure: end mm
  39. t_1 = (float)(c_2-c_1); // time elapsed for job row-wise
  40. printf("Execution time: %f \n",t_1);
  41. /* TERMINATE PROGRAM */
  42. return 0;
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:22:59: error: 'omp_get_max_threads' was not declared in this scope
 printf("Max number of threads: %i \n",omp_get_max_threads());
                                                           ^
prog.cpp:24:55: error: 'omp_get_num_threads' was not declared in this scope
 printf("Number of threads: %i \n",omp_get_num_threads());
                                                       ^
stdout
Standard output is empty