. , . , . , . , . , , . , . .
, , ( ), , , ( ).
, , . , , , () () , . , , , . , : , . , . . , , ( - ). , . ( ) .
//
Semaphore fork[5] = { 1, 1, 1, 1, 1 };
// - ( )
Prilosopher(){
// i
while (1) { P(fork[i]); // P(fork[(i+1)%5]); // <>
//
V(fork[i]); V(fork[(i+1)%5])
<> } }
( (i +1)%5 , % ).
2. ә . .
- , , . , . :
- (MPI_Barrier);
- , : (MPI_Bcast); (gather) (root) (MPI_Gather, MPI_Gatherv); (gather) (MPI_Allgather, MPI_Allgatherv); (scatter) (MPI_Scatter, MPI_Scatterv); Scatter/Gather (All-to-All), , , (MPI_Alltoall, MPI_Alltoallv).
|
|
- (sum, min, max .) , : (MPI_Reduce); (MPI_Allreduce); Reduce/Scatter (MPI_Reduce_scatter); (MPI_Scan);
: 1) -. 2) . , , , . 3) . 4) . 5) .
3. ө ң
int main(int argc,char **argv)
{
int size,rank,i,n=6;
float *a,*b;
a=new float[n];
b=new float[n];
for(i=0;i<n;i++)
{
a[i]=i+1;
b[i]=i+1;
}
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
float f=0,s=0,s1=0;
int nachalo,konec,shag;
shag=n/(size-1);
if(rank!=size-1)
{
nachalo=rank*shag;
konec=rank*shag+shag;
for(i=nachalo;i<konec;i++)
s=s+a[i]*b[i];
MPI_Send(&s,1,MPI_FLOAT,size-1,1,MPI_COMM_WORLD);
}
if(rank==size-1){
for(i=0;i<size-1;i++)
{ MPI_Recv(&s,1,MPI_FLOAT,i,1,MPI_COMM_WORLD,&status);
f=f+s; }
printf("%f\n",f);
}
MPI_Finalize();}
3. 2 ө ң 2-ө ә .
1. Қ . қ ө.
(SMP) (MPP). SMP MPP NUMA-, , . MPP. - , , PVP- . :
1. SISD (Single Instruction Single Data) . . .
|
|
2. SIMD (Single Instruction Multiple Data) . , , .
3. MISD (Multiple Instruction Single Date) . . ,
. - , .
4. MIMD (Multiple Instruction Multiple Date) . .
2. MPI_Cart_create() қ .
() MPI : int MPI_Cart_create(MPI_Comm oldcomm, int ndims, int *dims, int *periods, int reorder, MPI_Comm *cartcomm). 1. oldcomm - . 2. ndims - 3. dims - ndims, . 4. periods - ndims, , . 5.reorder - 6. cartcomm .
int dims[3]={0,0,0}, periods[3]={0,0,0},coords[3], ndims=3, reorder=0;; MPI_Cart_create(MPI_COMM_WORLD,ndims,dims,periods,reorder,&cartcomm);
5 08
3. 3 ө ң 2-ө ә .
1. Қ . қ ө.
(SMP) (MPP). SMP MPP NUMA-, , . MPP. - , , PVP- . :
1. SISD (Single Instruction Single Data) . . .
2. SIMD (Single Instruction Multiple Data) . , , .
3. MISD (Multiple Instruction Single Date) . . ,
. - , .
4. MIMD (Multiple Instruction Multiple Date) . .
2. MPI_Dims_create() қ .
MPI_DIMS_CREATE , . , ( MPI_COMM_WORLD) n- . int MPI_Dims_create(int nnodes, int ndims, int *dims)nnodes (), ndims (), dims - ndims, .
|
|
int dims[2]={0,0},ndims=2;
MPI_Dims_create(size, ndims, dims);
3. ққ ң.
1. Shared & distributed memory .
(DSM - Distributed Shared Memory)
, . ( ). DSM - , () . DSM , . DSM , . , . , , SMP, . , . , , . NUMA (non-uniform memory access).
NUMA (Non-Uniform Memory Access) , . , . , , NUMA- . , , API .
2. ү-ү . MPI_Bsend(), MPI_Brecv қ .
. - : . MPI , . . .
, .. , .
B (buffered) - . , . , . .
MPI_Bsend . -, , . . , , . .
|
|
int MPI_Bsend(void *buf, int count, MPI_Datatype datatype,int dest, int tag, MPI_Comm comm)
buf- ; count ; datatype ; dest - , comm; tag ( nread nwrite PSE nCUBE2); comm .
MPI_Bsend(&buffer, buffsize, MPI_INT, 1, TAG, MPI_COMM_WORLD);