/****** program ples ! Parallel Linear Equation solver ! Array A = ( MP*MLA x NP*NLA ) ! Proc. grid is MP x NP ! Local mat. (al) MLA x NLA ! array A(ig,jg) = 0.1*ig + 0.001*jg (ig not= jg) ! = ig (ig = jg) ! Solve Ax=b, b=1 ******/ #include #include #include #include #include #include extern void Cblacs_pinfo( int* mypnum, int* nprocs); extern void Cblacs_get( int context, int request, int* value); extern int Cblacs_gridinit( int* context, char * order, int np_row, int np_col); extern void Cblacs_gridinfo( int context, int* np_row, int* np_col, int* my_row, int* my_col); extern void Cblacs_gridexit( int context); extern void Cblacs_exit( int error_code); extern void Cblacs_gridmap( int* context, int* map, int ld_usermap, int np_row, int np_col); void setarray(float *a, int myrow, int mycol, int lda_x, int lda_y); void descinit_(int *idescal, int *m,int *n,int *mb,int *nb, int *dummy1 , int *dummy2 , int *icon, int *mla, int *info); int icon; int main() { int mp=2; int mla=4; int mb=2; int np=2; int nla=4; int nb=2; int mype,npe; int idescal[11], idescb[11]; float *al, *b; int *ipiv; int nprow=2 , npcol=2; int ib; int info; int mp_ret, np_ret, myrow, mycol; int zero=0; int one=1; int m,n; m=mla*mp; n=nla*np; Cblacs_pinfo( &mype, &npe ); Cblacs_get( -1, 0, &icon ); Cblacs_gridinit( &icon,"c", mp, np ); /* MP & NP = 2**x */ Cblacs_gridinfo( icon, &mp_ret, &np_ret, &myrow, &mycol); info=0; descinit_(idescal, &m, &n , &mb, &nb , &zero, &zero, &icon, &mla, &info); info=0; descinit_(idescb, &m, &one, &nb, &one, &zero, &zero, &icon, &mla, &info); al=(float*)malloc(sizeof(float)*mla*nla); b=(float*)malloc(sizeof(float)*mla); ipiv=(int*)malloc(sizeof(int)*(mla+mb)); setarray(al,myrow,mycol,4,4); printf("%3d%3d vals%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f\n", myrow,mycol,al[ 0],al[ 1],al[ 2],al[ 3] ,al[ 4],al[ 5],al[ 6],al[ 7] ,al[ 8],al[ 9],al[10],al[11] ,al[12],al[13],al[14],al[15]); for(ib=0;ib