an_matmul.c 910 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "stdlib.h"
  2. #include "util.h"
  3. #include "dataset.h"
  4. void __attribute__((noinline)) matmul(const int coreid, const int ncores, const int lda, const data_t A[], const data_t B[], data_t C[] )
  5. {
  6. // ***************************** //
  7. // **** ADD YOUR CODE HERE ***** //
  8. int i, j, k, limit, end, kblock, iblock, r, jblock;
  9. int tempA1;
  10. int tempB1;
  11. limit = lda / ncores;
  12. j = (coreid)*limit;
  13. end = (coreid+1)*limit;
  14. kblock = 1;
  15. iblock = 1;
  16. jblock = 1;
  17. for (; j < end; j+= jblock)
  18. for ( k = 0; k < lda; k = k + kblock )
  19. {
  20. r = j*lda + k;
  21. tempA1 = A[r];
  22. for ( i = 0; i < lda; i = i + iblock ) {
  23. tempB1 = k*lda + i;
  24. C[i + j*lda] += tempA1*B[tempB1];
  25. }
  26. barrier(ncores);
  27. }
  28. // ***************************** //
  29. //
  30. // feel free to make a separate function for MI and MSI versions.
  31. }