Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Communicate.C

Go to the documentation of this file.
00001 
00007 #include <string.h>
00008 #include <stdlib.h>
00009 #include "Communicate.h"
00010 #include "MStream.h"
00011 #include "charm++.h"
00012 
00013 CkpvStaticDeclare(CmmTable, CsmMessages);
00014 
00015 static void CsmHandler(void *msg)
00016 {
00017   if ( CmiMyRank() ) { CmiFree(msg); return; }
00018   // get start of user message
00019   int *m = (int *) ((char *)msg+CmiMsgHeaderSizeBytes);
00020   // sending node  & tag act as tags
00021   CmmPut(CkpvAccess(CsmMessages), 2, m, msg);
00022 }
00023 
00024 Communicate::Communicate(void) 
00025 {
00026   CkpvInitialize(CmmTable, CsmMessages);
00027   CsmHandlerIndex = CmiRegisterHandler((CmiHandler) CsmHandler);
00028   CkpvAccess(CsmMessages) = CmmNew();
00029 }
00030 
00031 
00032 Communicate::~Communicate(void) 
00033 {
00034   // do nothing
00035 }
00036 
00037 MIStream *Communicate::newInputStream(int PE, int tag)
00038 {
00039   MIStream *st = new MIStream(this, PE, tag);
00040   return st;
00041 }
00042 
00043 MOStream *Communicate::newOutputStream(int PE, int tag, unsigned int bufSize)
00044 {
00045   MOStream *st = new MOStream(this, PE, tag, bufSize);
00046   return st;
00047 }
00048 
00049 void *Communicate::getMessage(int PE, int tag)
00050 {
00051   if ( CmiMyRank() ) NAMD_bug("Communicate::getMessage called on non-rank-zero Pe\n");
00052   int itag[2], rtag[2];
00053   void *msg;
00054 
00055   itag[0] = (PE==(-1)) ? (CmmWildCard) : PE;
00056   itag[1] = (tag==(-1)) ? (CmmWildCard) : tag;
00057   while((msg=CmmGet(CkpvAccess(CsmMessages),2,itag,rtag))==0) {
00058     CmiDeliverMsgs(0);
00059   }
00060   return msg;
00061 }
00062 
00063 void Communicate::sendMessage(int PE, void *msg, int size)
00064 {
00065   if ( CmiMyPe() ) NAMD_bug("Communicate::sendMessage not from Pe 0");
00066   CmiSetHandler(msg, CsmHandlerIndex);
00067   switch(PE) {
00068     case ALL:
00069       NAMD_bug("Unexpected Communicate::sendMessage(ALL,...)");
00070       //CmiSyncBroadcastAll(size, (char *)msg);
00071       break;
00072     case ALLBUTME:
00073       CmiSyncBroadcast(size, (char *)msg);
00074       break;
00075     default:
00076       NAMD_bug("Unexpected Communicate::sendMessage(PEL,...)");
00077       //CmiSyncSend(PE, size, (char *)msg);
00078       break;
00079   }
00080 }

Generated on Sat Sep 6 04:07:40 2008 for NAMD by  doxygen 1.3.9.1