aboutsummaryrefslogtreecommitdiff
path: root/mt/ar_matmul.c
blob: 2299906cfe127b2b2ef3955c66739a7e68437006 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "stdlib.h"

#include "util.h"

#include "dataset.h"
void __attribute__((noinline)) matmul(const int coreid, const int ncores, const int lda,  const data_t A[], const data_t B[], data_t C[] )
{
   
   // ***************************** //
   // **** ADD YOUR CODE HERE ***** //
   // ***************************** //
   //
   // feel free to make a separate function for MI and MSI versions.
   
   int i, j, k, B_t[32*32], x, y;
   int ALoc, BLoc, CLoc;
//   int ii = 0, done = 0;
   //for(x = coreid*(lda/ncores); x < (coreid+1)*(lda/ncores) && x < lda; x++) {
   for (x = 0; x < lda; x++) {
   		for(y = 0; y < lda; y++) {
   			B_t[y*lda + x] = B[x*lda + y];
   		}
   }
  // for ( ii = lda/4 ; ii < lda ; ii += lda/4)
   //{
//   	   for ( i = coreid*(ii/ncores); i < (coreid+1)*(ii/ncores) && i < ii; i++ )
	   for ( i = coreid*(lda/ncores); i < (coreid+1)*(lda/ncores) && i < lda; i++ )
	   {
   		  ALoc = i*lda;
    	  for ( j = 0; j < lda; j++ ) 
	      {
	      	 BLoc = j*lda;
      		 CLoc = i*lda + j;
    	     for ( k = 0; k < lda; k++ ) 
	         {
            	C[CLoc] += A[ALoc + k] * B_t[BLoc + k];
        	 }
    	  }
	   }
   //}
}