HPMC User Guide v 1.00
© 2026 Bassem W. Jamaleddine
Figure 2.8.1 shows the result of matrix multiplication on the MIC. The plots are for the operations performed on various matrix sizes, considering operations to be performed as FMA on either double precision or single precision.
The result is explicitly drawn from the programming exercise explained in this section.
■ Measuring Gigaflops for Matrix Multiplication with Single Precision on the MIC
This section is not included in the SAMPLE PREVIEW.
■ Measuring Gigaflops for Matrix Multiplication with Double Precision on the MIC
The following program AxBd.c is similar to AxBf.c except we data type for the matrix element is double precision, and the operations performed on the elements are FMA using double as data type.
1. // AxBd.c multiply two matrices - DP double precision 2. 3. #ifndef MIC_DEV 4. #define MIC_DEV 0 5. #endif 6. 7. #include <stdio.h> 8. #include <stdlib.h> 9. #include <omp.h> 10. #include <math.h> 11. #include <sys/time.h> 12. 13. double getTime(void) { 14. struct timeval t; 15. gettimeofday(&t,0); 16. return ((double)t.tv_sec + ((double)t.tv_usec / 1000000.0)); 17. } 18. // ################################ 19. // An OpenMP simple matrix multiply 20. void doMultiplyAxBd(int size, double (* restrict A)[size], double (* restrict B)[size], double (* restrict C)[size]) { 21. 22. #pragma offload target(mic:MIC_DEV) \ 23. in(A:length(size*size)) in( B:length(size*size)) \ 24. out(C:length(size*size)) 25. { 26. // Zero the C matrix 27. #pragma omp parallel for default(none) shared(C,size) 28. for (int i = 0; i < size; ++i) 29. for (int j = 0; j < size; ++j) 30. C[i][j] =0.f; 31. 32. // Compute matrix multiplication. 33. #pragma omp parallel for default(none) shared(A,B,C,size) 34. for (int i = 0; i < size; ++i) 35. for (int k = 0; k < size; ++k) 36. for (int j = 0; j < size; ++j) 37. C[i][j] += A[i][k] * B[k][j]; 38. } 39. } 40. // ################################ 41. int main(int argc, char *argv[]) { 42. if(argc != 4) { 43. fprintf(stderr,"Usage: %s matrixsize numberofthreads iterations\n",argv[0]); 44. return -1; 45. } 46. int i,j,k; 47. int size=atoi(argv[1]); 48. int nThreads=atoi(argv[2]); 49. int iter=atoi(argv[3]); 50. omp_set_num_threads(nThreads); 51. // kmp_set_defaults("KMP_AFFINITY=compact"); 52. 53. double (*restrict A)[size] = malloc(sizeof(double)*size*size); 54. double (*restrict B)[size] = malloc(sizeof(double)*size*size); 55. double (*restrict C)[size] = malloc(sizeof(double)*size*size); 56. 57. // fill the A and B arrays with random doubles 58. #pragma omp parallel for default(none) shared(A,B,size) private(i,j,k) 59. for (i = 0; i < size; ++i) { 60. for (j = 0; j < size; ++j) { 61. A[i][j] = (double)((rand() % 3)-1); 62. B[i][j] = (double)((rand() % 3)-1); 63. } 64. } 65. 66. // warm up with a first operation 67. doMultiplyAxBd(size, A,B,C); 68. double startTime = getTime(); 69. for(int i=0; i < iter; i++) { 70. doMultiplyAxBd(size, A,B,C); 71. } 72. double endTime = getTime(); 73. double lapsed = endTime-startTime; 74. double gigaflops = 2*size*size*size*1e-9 *iter/lapsed; 75. 76. printf("DP %s %d threads %d matrixsize %d iterations in %g elapsed seconds %g GFlop/s\n", 77. argv[0], nThreads, size, iter, lapsed, gigaflops); 78. 79. free(A); free(B); free(C); 80. return 0; 81. } 82.
We compile the program AxBd.c for the MIC
03:50 root@HPMC9: /MIC_PROG/GIGAFLOPS # icc -O3 -mmic -openmp -L /opt/intel/lib/mic -Wno-unknown-pragmas -std=c99 -liomp5 AxBd.c -o AxBd.mic
We repeat the benchmark with the Perl script loopAxBd; however,
This section is not included in the SAMPLE PREVIEW.