.


:




:

































 

 

 

 


. .




. Send/Recv, MPI_Bcast. , , MPI- .

MPI_Bcast. root comm.

int MPI_Bcast(void* buffer, int count, MPI_Datatype datatype, int root,MPI_Comm comm)

buffer - ; count - ; datatype- ; root - -; comm-.

comm, , - root. . 4.1 Bcast. MPI_Bcast.

...

IF (MYID.EQ. 0) THEN

PRINT *, ' N: '

READ *, N

END IF

CALL MPI_BCAST(N, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, IERR)

, , . , , - , . , , , () .

MPI : 1) (MPI_Reduce). 2) (MPI_Allreduce). 3) , . i- i (MPI_Scan). 4) Reduce/Scatter (MPI_Reduce_scatter).

- MPI_Reduce, . , op, , root. ..

int MPI_Reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)

sendbuf - ; recvbuf - ( - root); count- ; datatype- ; op-, ; root- - ; comm -.

 

 

.

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();}

 





:


: 2016-07-29; !; : 999 |


:

:

, , .
==> ...

2028 - | 1671 -


© 2015-2024 lektsii.org - -

: 0.009 .