2 PUP -> MPI interface routines
5 Orion Sky Lawlor, olawlor@acm.org, 2004/9/15
7 #ifndef __UIUC_CHARM_PUP_MPI_H
8 #define __UIUC_CHARM_PUP_MPI_H
13 #define pup_checkMPI(err) pup_checkMPIerr(err,__FILE__,__LINE__);
14 inline void pup_checkMPIerr(int mpi_err
,const char *file
,int line
) {
15 if (mpi_err
!=MPI_SUCCESS
) {
16 CmiError("MPI Routine returned error %d at %s:%d\n",
18 CmiAbort("MPI Routine returned error code");
22 /// Return the number of dt's in the next MPI message from/tag/comm.
23 inline int MPI_Incoming_pup(MPI_Datatype dt
,int from
,int tag
,MPI_Comm comm
) {
25 pup_checkMPI(MPI_Probe(from
,tag
,comm
,&sts
));
26 int len
; pup_checkMPI(MPI_Get_count(&sts
,dt
,&len
));
30 /// MPI_Recv, but using an object T with a pup routine.
32 inline void MPI_Recv_pup(T
&t
, int from
,int tag
,MPI_Comm comm
) {
33 int len
=MPI_Incoming_pup(MPI_BYTE
,from
,tag
,comm
);
35 char *buf
=new char[len
];
36 pup_checkMPI(MPI_Recv(buf
,len
,MPI_BYTE
, from
,tag
,comm
,&sts
));
37 PUP::fromMemBuf(t
,buf
,len
);
41 /// MPI_Send, but using an object T with a pup routine.
43 inline void MPI_Send_pup(T
&t
, int to
,int tag
,MPI_Comm comm
) {
44 size_t len
=PUP::size(t
); char *buf
=new char[len
];
45 PUP::toMemBuf(t
,buf
,len
);
46 pup_checkMPI(MPI_Send(buf
,len
,MPI_BYTE
, to
,tag
,comm
));
50 /// MPI_Bcast, but using an object T with a pup routine.
52 inline void MPI_Bcast_pup(T
&t
, int root
,MPI_Comm comm
) {
54 MPI_Comm_rank(comm
,&myRank
);
55 /* Can't do broadcast until everybody knows the size */
57 if(myRank
== root
) len
=PUP::size(t
);
58 pup_checkMPI(MPI_Bcast(&len
,1,MPI_INT
,root
,comm
));
59 /* Now pack object and send off */
60 char *buf
=new char[len
];
61 if(myRank
== root
) PUP::toMemBuf(t
,buf
,len
);
62 pup_checkMPI(MPI_Bcast(buf
,len
,MPI_BYTE
, root
,comm
));
63 PUP::fromMemBuf(t
,buf
,len
);