00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if USE_MPI_CTRLMSG_SCHEME
00023
00024 #define CTRL_MSG_TAG (TAG-13)
00025 #define USE_NUM_TAGS 1000
00026
00027 static int MPI_CTRL_MSG_CNT=10;
00028 static int tags;
00029
00030 typedef struct MPICtrlMsgEntry{
00031 int src;
00032 int size;
00033 int tag;
00034 }MPICtrlMsgEntry;
00035
00036 typedef struct RecvCtrlMsgEntry{
00037 int bufCnt;
00038 MPI_Request *ctrlReqs;
00039 MPICtrlMsgEntry *bufs;
00040 }RecvCtrlMsgEntry;
00041
00042 static RecvCtrlMsgEntry recvCtrlMsgList;
00043
00044 static void createCtrlMsgIrecvBufs(void){
00045 int i;
00046 MPICtrlMsgEntry *bufPtr = NULL;
00047 MPI_Request *reqPtr = NULL;
00048 int count = MPI_CTRL_MSG_CNT;
00049
00050 tags = 0;
00051
00052 recvCtrlMsgList.bufCnt = count;
00053 recvCtrlMsgList.ctrlReqs = (MPI_Request *)malloc(sizeof(MPI_Request)*count);
00054 recvCtrlMsgList.bufs = (MPICtrlMsgEntry *)malloc(sizeof(MPICtrlMsgEntry)*count);
00055
00056 bufPtr = recvCtrlMsgList.bufs;
00057 reqPtr = recvCtrlMsgList.ctrlReqs;
00058
00059 for(i=0; i<count; i++, bufPtr++, reqPtr++){
00060 if(MPI_SUCCESS != MPI_Irecv(bufPtr, sizeof(MPICtrlMsgEntry),
00061 MPI_BYTE, MPI_ANY_SOURCE, CTRL_MSG_TAG, charmComm, reqPtr)){
00062 CmiAbort("MPI_Irecv failed in creating pre-posted ctrl msg buffers\n");
00063 }
00064 }
00065 }
00066
00067 static void sendViaCtrlMsg(int node, int size, char *msg, SMSG_LIST *smsg){
00068 MPICtrlMsgEntry one;
00069
00070 one.src = CmiMyNode();
00071 one.size = size;
00072 one.tag = TAG + 100 + tags;
00073
00074 tags = (tags+1)%USE_NUM_TAGS;
00075
00076 START_TRACE_SENDCOMM(msg);
00077 if(MPI_SUCCESS != MPI_Send((void *)&one, sizeof(MPICtrlMsgEntry), MPI_BYTE, node, CTRL_MSG_TAG, charmComm)){
00078 CmiAbort("MPI_Send failed in sending ctrl msg\n");
00079 }
00080 if (MPI_SUCCESS != MPI_Isend((void *)msg,size,MPI_BYTE,node,one.tag,charmComm,&(smsg->req)))
00081 CmiAbort("MPISendOneMsg: MPI_Isend failed!\n");
00082 END_TRACE_SENDCOMM(msg);
00083 }
00084
00085
00086 static int recvViaCtrlMsg(void){
00087 int count = recvCtrlMsgList.bufCnt;
00088 MPI_Request *ctrlReqs = recvCtrlMsgList.ctrlReqs;
00089 MPICtrlMsgEntry *ctrlMsgs = recvCtrlMsgList.bufs;
00090
00091 int completed_index = -1;
00092 int flg = 0;
00093 int nbytes = -1;
00094 MPI_Status sts;
00095 if(MPI_SUCCESS != MPI_Testany(count, ctrlReqs, &completed_index, &flg, &sts)){
00096 CmiAbort("MPI_Testany failed for checking if ctrl msg is received\n");
00097 }
00098
00099 if(flg){
00100 int src = ctrlMsgs[completed_index].src;
00101 int msgsize = ctrlMsgs[completed_index].size;
00102 nbytes = msgsize;
00103 char *actualMsg = (char *)CmiAlloc(msgsize);
00104
00105 IRecvList one = irecvListEntryAllocate();
00106
00107
00108 if(MPI_SUCCESS != MPI_Irecv(actualMsg, msgsize, MPI_BYTE, src, ctrlMsgs[completed_index].tag, charmComm, &(one->req))){
00109 CmiAbort("MPI_Irecv failed after a ctrl msg is received\n");
00110 }
00111
00112
00113 if(MPI_SUCCESS != MPI_Irecv(ctrlMsgs+completed_index, sizeof(MPICtrlMsgEntry), MPI_BYTE,
00114 MPI_ANY_SOURCE, CTRL_MSG_TAG, charmComm, ctrlReqs+completed_index)){
00115 CmiAbort("MPI_Irecv failed in re-posting a ctrl msg is received\n");
00116 }
00117
00118 one->msg = actualMsg;
00119 one->size = msgsize;
00120 one->next = NULL;
00121 waitIrecvListTail->next = one;
00122 waitIrecvListTail = one;
00123 }
00124
00125 return nbytes;
00126 }
00127
00128 #endif