MPI , , , . MPI - , . . , . , MPI, - , , . . . . - - . , . - . . . -: int MPI_Cart_create(MPI_Comm oldcomm, int ndims, int *dims, int *periods, int reorder, MPI_Comm *cartcomm), : oldcomm - . ; ndims - . . , dims - ndims, - . , periods - ndims, , - . ; reorder - . . , cartcomm -. . . . . - , . ; . . . , . . .
MPI.
int size,rank;
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
int i,k,j,s,x=0,p;
int n=10, a[n][n], c[n], b[n], d[p];
p=n/(size-1);
for (i=0;i<n;i++)
{
b[i]=i; for(j=0;j<n;j++) { a[i][j]=x;x++; }
}
if (rank!=size-1)
{ for(k=rank*p;k<p*(rank+1);k++) {
s=0; for(int j=0;j<n;j++)
{ s+=a[k][j]*b[j]; } d[k]=s; }
MPI_Send(&d[rank*p],p,MPI_DOUBLE,size-1,5,MPI_COMM_WORLD);
}
else
{ for (i=0; i<size-1;i++) { MPI_Recv(&c[i*p],p,MPI_DOUBLE,i,5,MPI_COMM_WORLD, &status); } }
. MISD, MIMD.
. . :
SISD (Single Instruction Stream - Single Data Stream) ;
SIMD (Single Instruction Stream Multiple Data Stream) ;
MISD (Multiple Instruction Stream Single Data Stream) ;
MIMD (Multiple Instruction Stream Multiple Data Stream)
MISD
. , , . . ,
MIMD
, . , , .. , , .