Added support for committing the messages that were selected as "conditionally delivered"
authorFilippo Gioachin <gioachin@uiuc.edu>
Tue, 6 Jul 2010 03:47:25 +0000 (22:47 -0500)
committerFilippo Gioachin <gioachin@uiuc.edu>
Tue, 6 Jul 2010 03:47:25 +0000 (22:47 -0500)
This means that a new variable in the shared memory segment tells the resuming parent how many messages should be fully delivered.

src/ck-core/debug-charm.C

index 21c38d5f6ed9f91e81656719f8eafd01851c0da0..3ff8fde7eca2852dce4a5d8a6b6934104a18c4e9 100644 (file)
@@ -428,6 +428,7 @@ void CpdPupMessage(PUP::er &p, void *msg)
 
 struct ConditionalList {
   int count;
+  int deliver;
   int msgs[1];
 };
 CkpvStaticDeclare(void *, lastBreakPointMsg);
@@ -592,6 +593,7 @@ static pid_t CpdConditional_SetupComm() {
     int shmemid = shmget(IPC_PRIVATE, 1024*1024, IPC_CREAT | 0666);
     conditionalShm = (ConditionalList*)shmat(shmemid, NULL, 0);
     conditionalShm->count = 0;
+    conditionalShm->deliver = 0;
     shmctl(shmemid, IPC_RMID, &dummy);
   }
   
@@ -642,10 +644,29 @@ extern "C" void CpdEndConditionalDeliver_master() {
   close(conditionalPipe[1]);
   conditionalPipe[1] = 0;
   wait(NULL);
+  int i;
+  // Check if we have to deliver unconditionally some messages
+  if (conditionalShm->deliver > 0) {
+    // Deliver the requested number of messages
+    for (i=0; i < conditionalShm->deliver; ++i) {
+      int msgNum = conditionalShm->msgs[i];
+      if (msgNum == -1) CpdDeliverSingleMessage();
+      else CpdDeliverMessageInt(msgNum);
+    }
+    // Move back the remaining messages accordingly
+    for (i=conditionalShm->deliver; i < conditionalShm->count; ++i) {
+      conditionalShm->msgs[i-conditionalShm->deliver] = conditionalShm->msgs[i];
+    }
+    conditionalShm->count -= conditionalShm->deliver;
+    conditionalShm->deliver = 0;
+    CmiMachineProgressImpl();
+  }
+  CkAssert(conditionalShm->count >= 0);
   if (conditionalShm->count == 0) {
     CcsSendReply(0,NULL);
     shmdt((char*)conditionalShm);
     conditionalShm = NULL;
+    CkPrintf("Conditional delivery on %d concluded; normal mode resumed\n",CkMyPe());
   } else {
     if (CpdConditional_SetupComm()==0) {
       // We are in the child, deliver again the messages
@@ -674,6 +695,14 @@ void CpdDeliverMessageConditionally(char * msg) {
   }
 }
 
+void CpdCommitConditionalDelivery(char * msg) {
+  int msgNum;
+  sscanf(msg+CmiMsgHeaderSizeBytes, "%d", &msgNum);\
+  conditionalShm->deliver = msgNum;
+  shmdt((char*)conditionalShm);
+  _exit(0);
+}
+
 class CpdList_msgStack : public CpdListAccessor {
   virtual const char * getPath(void) const {return "charm/messageStack";}
   virtual size_t getLength(void) const {
@@ -1017,6 +1046,7 @@ void CpdCharmInit()
   CcsRegisterHandler("deliverMessage",(CmiHandler)CpdDeliverMessage);
   CcsRegisterHandler("deliverConditional",(CmiHandler)CpdDeliverMessageConditionally);
   CcsRegisterHandler("endConditional",(CmiHandler)CpdEndConditionalDelivery);
+  CcsRegisterHandler("commitConditional",(CmiHandler)CpdCommitConditionalDelivery);
   CpdListRegister(new CpdList_arrayElementNames());
   CpdListRegister(new CpdList_arrayElements());
   CpdListRegister(new CpdList_objectNames());