/* Nhan ma tran dung MPI */ #include #include #include #define ROW_LOW(id,p,n) ((id)*(n)/(p)) #define ROW_HIGH(id,p,n) (ROW_LOW((id)+1,p,n)-1) #define ROW_SIZE(id,p,n) (ROW_HIGH(id,p,n)-ROW_LOW(id,p,n)+1) #define ROW_OWNER(j,p,n) (((p)*((j)+1)-1)/(n)) #define THRESHOLD 65535 static double *A,*B,*C; void MM(int L, int M, int N, double *A, double *B, double *C, int crow, int ccol , /*corner of C block*/ int arow, int acol , /* corner of A block*/ int brow, int bcol , /* corner of B block*/ int l, int m, /* block B is m x n*/ int n) /* block C is l x n*/ { int lhalf[3], mhalf[3], nhalf[3]; int i,j,k; double *aptr,*bptr,*cptr; if (m*n > THRESHOLD) { lhalf[0] = 0; lhalf[1] = l/2; lhalf[2] = l - l/2; mhalf[0] = 0; mhalf[1] = m/2; mhalf[2] = m - m/2; nhalf[0] = 0; nhalf[1] = n/2; nhalf[2] = n - n/2; for (i=0; i<2; i++) for (j=0;j<2;j++) for (k=0;k<2;k++) MM(L,M,N, A, B, C, crow + lhalf[i], ccol + mhalf[j], arow + lhalf[i], acol + mhalf[k], brow + mhalf[k], bcol + nhalf[j], lhalf[i+1], mhalf[k+1], nhalf[j+1] ); }else { for (i=0; i %s \n",s); printf("\t : number of processes\n"); printf("\t Matrix size: A=lxm, B=mxn, C=lxn\n"); } void print_to_file(double *mt, int row, int col, char *name) { FILE *f; f= fopen(name,"w"); if (f == NULL){ printf("Cannot write to file %s\n",name); exit(1); } int i,j; for (i=0;i