.


:




:

































 

 

 

 


MPI_Gather, MPI_scatter, MPI_allgather, MPI_alltoall, MPI_allreduce. .




: MPI_Gather, MPI_Allgather, MPI_Gatherv, MPI_Allgatherv. .

MPI_Gather , , root. . -.

int MPI_Gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype,int root, MPI_Comm comm)

sendbuf - ; sendcount - ; sendtype - ; recvbuf - ( - root); recvcount - , ( - root); recvtype - ; root - -; comm - .

MPI_Comm comm;

int array[100];

int root, *rbuf;

...

MPI_Comm_size(comm, &gsize);

rbuf = (int *) malloc(gsize * 100 * sizeof(int));

MPI_Gather(array, 100, MPI_INT, rbuf, 100, MPI_INT, root, comm);

MPI_Allgather , MPI_Gather, . , i sendbuf, i- recvbuf . recvbuf .

int MPI_Allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)

MPI_Gatherv , , , recvcounts. -, displs.

int MPI_Gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* rbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, int root, MPI_Comm comm)

MPI_Alltoall Scatter Gather Allgather, . i j- sendbuf j, i- recvbuf. .

int MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)

MPI_Allreduce , root. , , .

int MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm 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; !; : 1582 |


:

:

,
==> ...

1880 - | 1799 -


© 2015-2024 lektsii.org - -

: 0.008 .