MPI- . mpirun. , mpirun -np 20./first.exe first.exe 20 , .. 5 . ( 2 ). , ($pwd) ./ MPI-1 MPI, mpirun < mpirun><>< >
, . MPI , , . , , , , . ``'' , , mpirun MPI mpiexec.
MPI, (, ), MPI . , MPI mpiexec , , . , mpiexec, , : mpiexec -n <numprocs><>
<> MPI_COMM_WORLD, <numprocs> . mpiexec .
4.1 16 myprog :
mpiexec -n 16 myprog
3. 2*(x+2*x*x/1200.0) [0,1].
double f(double x)
{return 2*(x+2*x*x/1200);} // iskomyi integral
int main(int argc,char **argv)
{
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 n=1000,i,d; // 1000 - uzly
float a=0, b=1, h=(b-a)/n,s=0,r=0; //a i b -nachalo i konec otrezka
d=n/(size-1);
if (rank!=size-1) // schitaut vse processy, krome poslednego
{ for (i=rank*d; i<(rank+1)*d; i++) { s=s+h*f(a+i*h); }
MPI_Send(&s,1,MPI_FLOAT,size-1,1,MPI_COMM_WORLD);}
else
{ for (i=0; i<size-1; i++) // poslednii process vse sobiraet
{ MPI_Recv(&s,1,MPI_FLOAT,i,1,MPI_COMM_WORLD, &status); r+=s; } }
|
|
MPI_Finalize();}
1. Shared & distributed memory .
(DSM - Distributed Shared Memory)
, . ( ). DSM - , () . DSM , . DSM , . , . , , SMP, . , . , , . NUMA (non-uniform memory access).
MPI PVM.
PVM (Parallel Virtual Machine) . UNIX , . MPI (Message Parsing Interface). MPI . , . MPI. MPI . , , , .
MPI PVM : 1. MPI PVM , 2. MPI PVM MPMD ; 3. MPI PVM ; 4. MPI PVM .
MPI PVM : 1. PVM , MPI; 2. PVM ( MPI-2 ); 3. PVM , ( MPI-2 ).