/********************
**Rendy Eka Saputra*******29/9/2011***************************/#include<stdio.h>#include<mpi.h>int main(int argc,char *argv[]){int a[2][4],b[4][2],x,y,id,p;int z1=0,z2=0,z3=0,r=0,d=0,e=0,f=0,g=0,h=0,i=0;for(x=0;x<2;x++){for(y=0;y<4;y++){a[x][y]= z1+1;z1++;}}for(x=0;x<4;x++){for(y=0;y<2;y++){b[x][y]=z2+1;z2++;}}MPI_Init(&argc,&argv);MPI_Comm_rank(MPI_COMM_WORLD,&id);MPI_Comm_size(MPI_COMM_WORLD,&p);MPI_Status Status0;MPI_Status Status1;MPI_Status Status2;if(id==0){for(x=0;x<4;x++)r+=a[z3][x]*b[x][z3];MPI_Send(&r,1,MPI_INT,3,1,MPI_COMM_WORLD);}if(id==1){for(x=0;x<4;x++)d+=a[z3][x]*b[x][z3+1];MPI_Send(&d,1,MPI_INT,3,1,MPI_COMM_WORLD);}if(id==2){for(x=0;x<4;x++)e+=a[z3+1][x]*b[x][z3];MPI_Send(&e,1,MPI_INT,3,1,MPI_COMM_WORLD);}if(id==3){for(x=0;x<4;x++)f+=a[z3+1][x]*b[x][z3+1];MPI_Recv(&g,1,MPI_INT,0,1,MPI_COMM_WORLD,&Status0);MPI_Recv(&h,1,MPI_INT,1,1,MPI_COMM_WORLD,&Status1);MPI_Recv(&i,1,MPI_INT,2,1,MPI_COMM_WORLD,&Status2);int c[2][2]={{g,h},{i,f}};for(x=0;x<2;x++){for(y=0;y<2;y++)printf("%6d", c[x][y]);printf("\n");}}MPI_Finalize();return 0;}
Selasa, 04 Oktober 2011
Parallel Programming: Matrix Multiplication
Label:
Source Code
0 komentar:
Posting Komentar