git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@9433 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2013-02-09 19:55:40 +00:00
parent ceffdd4a6b
commit c2c3ef3b22
2 changed files with 22 additions and 9 deletions

View File

@ -1505,15 +1505,26 @@ void Comm::forward_comm_array(int n, double **array)
}
/* ----------------------------------------------------------------------
reverse communication invoked by a Dump
communicate inbuf around full ring of processors with messtag
nbytes = size of inbuf = n datums, each of size nper bytes
use callback() to allow caller to process each proc's inbuf
------------------------------------------------------------------------- */
void Comm::ring(int n, int nmax, char *buf, char *bufcopy, int messtag,
void Comm::ring(int n, int nper, void *inbuf, int messtag,
void (*callback)(int, char *))
{
MPI_Request request;
MPI_Status status;
int nbytes = n*nper;
int maxbytes;
MPI_Allreduce(&nbytes,&maxbytes,1,MPI_INT,MPI_MAX,world);
char *buf,*bufcopy;
memory->create(buf,maxbytes,"comm:buf");
memory->create(bufcopy,maxbytes,"comm:bufcopy");
memcpy(buf,inbuf,nbytes);
int next = me + 1;
int prev = me - 1;
if (next == nprocs) next = 0;
@ -1521,14 +1532,17 @@ void Comm::ring(int n, int nmax, char *buf, char *bufcopy, int messtag,
for (int loop = 0; loop < nprocs; loop++) {
if (me != next) {
MPI_Irecv(bufcopy,nmax,MPI_CHAR,prev,messtag,world,&request);
MPI_Send(buf,n,MPI_CHAR,next,messtag,world);
MPI_Irecv(bufcopy,maxbytes,MPI_CHAR,prev,messtag,world,&request);
MPI_Send(buf,nbytes,MPI_CHAR,next,messtag,world);
MPI_Wait(&request,&status);
MPI_Get_count(&status,MPI_CHAR,&n);
memcpy(buf,bufcopy,n);
callback(n,buf);
MPI_Get_count(&status,MPI_CHAR,&nbytes);
memcpy(buf,bufcopy,nbytes);
callback(nbytes/nper,buf);
}
}
memory->destroy(buf);
memory->destroy(bufcopy);
}
/* ----------------------------------------------------------------------