made a few optimizations
authorSameer Paranjpye <paranjpy@uiuc.edu>
Mon, 1 May 2000 05:16:47 +0000 (05:16 +0000)
committerSameer Paranjpye <paranjpy@uiuc.edu>
Mon, 1 May 2000 05:16:47 +0000 (05:16 +0000)
src/conv-core/quiescence.c
src/conv-core/quiescence.h

index 9150fbb51437db6d66b1f1a360d4a8966125d955..03074329bd2bc44468fb96b5a91969634cf2127a 100644 (file)
@@ -55,18 +55,16 @@ int CQdGetProcessed(CQdState state)
 void CQdProcess(CQdState state, int n)
 { state->mProcessed += n; }
 
-
 void CQdPropagate(CQdState state, CQdMsg msg) 
 {   
-       int i;
-       CmiSetHandler(msg, CQdHandlerIdx);
-    for(i=0; i<state->nChildren; i++) {
-               CQdCreate(state, -1);
-               CmiSyncSend(state->children[i], sizeof(struct ConvQdMsg), (char *)msg);
-    }
+  int i;
+  CmiSetHandler(msg, CQdHandlerIdx);
+  for(i=0; i<state->nChildren; i++) {
+    CQdCreate(state, -1);
+    CmiSyncSend(state->children[i], sizeof(struct ConvQdMsg), (char *)msg);
+  }
 }
 
 int  CQdGetParent(CQdState state) 
 { return state->parent; }
     
@@ -95,7 +93,10 @@ int  CQdAllReported(CQdState state)
 { return state->nReported==(state->nChildren+1);}
 
 void CQdReset(CQdState state) 
-{ state->nReported=0; state->cCreated=0; state->cProcessed=0; state->cDirty=0; }
+{ 
+  state->nReported=0; state->cCreated=0; 
+  state->cProcessed=0; state->cDirty=0; 
+}
 
 void CQdMarkProcessed(CQdState state) 
 { state->oProcessed = state->mProcessed; }
@@ -108,193 +109,191 @@ void CQdSubtreeSetDirty(CQdState state, int d)
 
 CQdState CQdStateCreate(void)
 {
-       CQdState state = (CQdState) malloc(sizeof(struct ConvQdState));
-       _MEMCHECK(state);
-       state->mCreated = 0;
-       state->mProcessed = 0;
-       state->stage = 0;
-       state->nReported = 0;
-       state->oProcessed = 0;
-       state->cCreated = 0;
-       state->cProcessed = 0;
-       state->cDirty = 0;
-       state->nChildren = CmiNumSpanTreeChildren(CmiMyPe());
-       state->parent = CmiSpanTreeParent(CmiMyPe());
-    /* fixed bug on SP3, when nChildren is 0, NULL will be returned by malloc */
-       if (state->nChildren) {
-           state->children = (int *) malloc(state->nChildren*sizeof(int));
-           _MEMCHECK(state->children);
-        }
-       else 
-           state->children = NULL;
-       CmiSpanTreeChildren(CmiMyPe(), state->children);
-
-       return state;
+  CQdState state = (CQdState) malloc(sizeof(struct ConvQdState));
+  _MEMCHECK(state);
+  state->mCreated = 0;
+  state->mProcessed = 0;
+  state->stage = 0;
+  state->nReported = 0;
+  state->oProcessed = 0;
+  state->cCreated = 0;
+  state->cProcessed = 0;
+  state->cDirty = 0;
+  state->nChildren = CmiNumSpanTreeChildren(CmiMyPe());
+  state->parent = CmiSpanTreeParent(CmiMyPe());
+  /* fixed bug on SP3, when nChildren is 0, NULL will be returned by malloc */
+  if (state->nChildren) {
+    state->children = (int *) malloc(state->nChildren*sizeof(int));
+    _MEMCHECK(state->children);
+  }
+  else 
+    state->children = NULL;
+  CmiSpanTreeChildren(CmiMyPe(), state->children);
+
+  return state;
 }
 
 
 static void CQdBcastQD1(CQdState state, CQdMsg msg)
 {  
-       CQdMsgSetPhase(msg, 0); 
-       CQdPropagate(state, msg); 
-       CQdMsgSetPhase(msg, 1); 
-       CQdMsgSetCreated(msg, CQdGetCreated(state)); 
-       CQdMsgSetProcessed(msg, CQdGetProcessed(state)); 
-       CQdCreate(state, -1);
-       CmiSyncSendAndFree(CmiMyPe(), sizeof(struct ConvQdMsg), (char *) msg);
-       CQdMarkProcessed(state); 
-       CQdReset(state); 
-       CQdSetStage(state, 1); 
+  CQdMsgSetPhase(msg, 0); 
+  CQdPropagate(state, msg); 
+  CQdMsgSetPhase(msg, 1); 
+  CQdMsgSetCreated(msg, CQdGetCreated(state)); 
+  CQdMsgSetProcessed(msg, CQdGetProcessed(state)); 
+  CQdCreate(state, -1);
+  CmiSyncSendAndFree(CmiMyPe(), sizeof(struct ConvQdMsg), (char *) msg);
+  CQdMarkProcessed(state); 
+  CQdReset(state); 
+  CQdSetStage(state, 1); 
 }
 
 
 static void CQdBcastQD2(CQdState state, CQdMsg msg)
 {
-       CQdMsgSetPhase(msg, 1); 
-       CQdPropagate(state, msg); 
-       CQdMsgSetPhase(msg, 2); 
-       CQdMsgSetDirty(msg, CQdIsDirty(state)); 
-       CQdCreate(state, -1);
-       CmiSyncSendAndFree(CmiMyPe(), sizeof(struct ConvQdMsg), (char *) msg);
-       CQdReset(state); 
-       CQdSetStage(state, 2); 
+  CQdMsgSetPhase(msg, 1); 
+  CQdPropagate(state, msg); 
+  CQdMsgSetPhase(msg, 2); 
+  CQdMsgSetDirty(msg, CQdIsDirty(state)); 
+  CQdCreate(state, -1);
+  CmiSyncSendAndFree(CmiMyPe(), sizeof(struct ConvQdMsg), (char *) msg);
+  CQdReset(state); 
+  CQdSetStage(state, 2); 
 }
 
 
 static void CQdHandlePhase0(CQdState state, CQdMsg msg)
 {
-       assert(CmiMyPe()==0 || CQdGetStage(state)==0);
-       if(CQdGetStage(state)==0)
-               CQdBcastQD1(state, msg);
-       else
-               CmiFree(msg);
+  assert(CmiMyPe()==0 || CQdGetStage(state)==0);
+  if(CQdGetStage(state)==0)
+    CQdBcastQD1(state, msg);
+  else
+    CmiFree(msg);
 }
 
 
 static void CQdHandlePhase1(CQdState state, CQdMsg msg)
 {
-       switch(CQdGetStage(state)) 
-       {               
-       case 0 :
-               assert(CmiMyPe()!=0);
-               CQdBcastQD2(state, msg);
-               break;
-       case 1 :
-               CQdSubtreeCreate(state, CQdMsgGetCreated(msg)); 
-               CQdSubtreeProcess(state, CQdMsgGetProcessed(msg)); 
-               CQdReported(state); 
-               
-               if(CQdAllReported(state)) 
-               {
-                       if(CmiMyPe()==0) 
-                       {
-                               if(CQdGetCCreated(state) == CQdGetCProcessed(state)) 
-                                       CQdBcastQD2(state, msg); 
-                               else 
-                                       CQdBcastQD1(state, msg);
-                       } 
-                       else 
-                       {
-                               CQdMsgSetCreated(msg, CQdGetCCreated(state)); 
-                               CQdMsgSetProcessed(msg, CQdGetCProcessed(state)); 
-                               CQdCreate(state, -1);
-                               CmiSyncSendAndFree(CQdGetParent(state), sizeof(struct ConvQdMsg), (char *) msg);
-                               DEBUGF(("PE = %d, My parent = %d\n", CmiMyPe(), CQdGetParent(state)));
-                               CQdReset(state); 
-                               CQdSetStage(state, 0); 
-                       }
-               } 
-               else
-                       CmiFree(msg);
-               break;
-       default: 
-               CmiAbort("Internal QD Error. Contact Developers.!\n");
-       }
+  switch(CQdGetStage(state)) {                 
+  case 0 :
+    assert(CmiMyPe()!=0);
+    CQdBcastQD2(state, msg);
+    break;
+  case 1 :
+    CQdSubtreeCreate(state, CQdMsgGetCreated(msg)); 
+    CQdSubtreeProcess(state, CQdMsgGetProcessed(msg)); 
+    CQdReported(state); 
+    
+    if(CQdAllReported(state)) {
+      if(CmiMyPe()==0) {
+       if(CQdGetCCreated(state) == CQdGetCProcessed(state)) 
+         CQdBcastQD2(state, msg); 
+       else 
+         CQdBcastQD1(state, msg);
+      } 
+      else {
+       CQdMsgSetCreated(msg, CQdGetCCreated(state)); 
+       CQdMsgSetProcessed(msg, CQdGetCProcessed(state)); 
+       CQdCreate(state, -1);
+       CmiSyncSendAndFree(CQdGetParent(state), 
+                          sizeof(struct ConvQdMsg), (char *) msg);
+       DEBUGF(("PE = %d, My parent = %d\n", CmiMyPe(), CQdGetParent(state)));
+       CQdReset(state); 
+       CQdSetStage(state, 0); 
+      }
+    } 
+    else
+      CmiFree(msg);
+    break;
+  default: 
+    CmiAbort("Internal QD Error. Contact Developers.!\n");
+  }
 }
 
 
 static void CQdHandlePhase2(CQdState state, CQdMsg msg)
 {
-       assert(CQdGetStage(state)==2);
-       CQdSubtreeSetDirty(state, CQdMsgGetDirty(msg));    
-       CQdReported(state);
-       if(CQdAllReported(state)) 
-       { 
-               if(CmiMyPe()==0) 
-               {
-                       if(CQdIsDirty(state)) 
-                               CQdBcastQD1(state, msg);
-                       else 
-                       {
-                               CmiSetHandler(msg, CQdAnnounceHandlerIdx);
-                               CQdCreate(state, 0-CmiNumPes());
-                               CmiSyncBroadcastAllAndFree(sizeof(struct ConvQdMsg), (char *) msg);
-                               CQdReset(state); 
-                               CQdSetStage(state, 0); 
-               }
-               } 
-               else 
-               {
-                       CQdMsgSetDirty(msg, CQdIsDirty(state)); 
-                       CQdCreate(state, -1);
-                       CmiSyncSendAndFree(CQdGetParent(state), sizeof(struct ConvQdMsg), (char *) msg);
-                       CQdReset(state); 
-                       CQdSetStage(state, 0); 
-               }
-       } 
-       else
-               CmiFree(msg);
+  assert(CQdGetStage(state)==2);
+  CQdSubtreeSetDirty(state, CQdMsgGetDirty(msg));    
+  CQdReported(state);
+  if(CQdAllReported(state)) { 
+    if(CmiMyPe()==0) {
+      if(CQdIsDirty(state)) 
+       CQdBcastQD1(state, msg);
+      else {
+       CmiSetHandler(msg, CQdAnnounceHandlerIdx);
+       CQdCreate(state, 0-CmiNumPes());
+       CmiSyncBroadcastAllAndFree(sizeof(struct ConvQdMsg), (char *) msg);
+       CQdReset(state); 
+       CQdSetStage(state, 0); 
+      }
+    } 
+    else {
+      CQdMsgSetDirty(msg, CQdIsDirty(state)); 
+      CQdCreate(state, -1);
+      CmiSyncSendAndFree(CQdGetParent(state), 
+                        sizeof(struct ConvQdMsg), (char *) msg);
+      CQdReset(state); 
+      CQdSetStage(state, 0); 
+    }
+  } 
+  else
+    CmiFree(msg);
 }
 
 
 static void CQdCallWhenIdle(CQdMsg msg)
 {
-       CQdState state = CpvAccess(cQdState);
+  CQdState state = CpvAccess(cQdState);
   
-       switch(CQdMsgGetPhase(msg)) 
-       {
-    case 0 : CQdHandlePhase0(state, msg); break;
-    case 1 : CQdHandlePhase1(state, msg); break;
-    case 2 : CQdHandlePhase2(state, msg); break;
-    default: CmiAbort("Internal QD Error. Contact Developers.!\n");
-       }
+  switch(CQdMsgGetPhase(msg)) {
+  case 0 : CQdHandlePhase0(state, msg); break;
+  case 1 : CQdHandlePhase1(state, msg); break;
+  case 2 : CQdHandlePhase2(state, msg); break;
+  default: CmiAbort("Internal QD Error. Contact Developers.!\n");
+  }
 }
 
 
 void CQdHandler(CQdMsg msg)
 {
-       CmiGrabBuffer((void **)&msg);
-       CQdProcess(CpvAccess(cQdState), -1);
-       CcdCallOnCondition(CcdPROCESSORIDLE, (CcdVoidFn)CQdCallWhenIdle, (void*) msg);  
+  CmiGrabBuffer((void **)&msg);
+  CQdProcess(CpvAccess(cQdState), -1);
+  CcdCallOnCondition(CcdPROCESSORIDLE, 
+                    (CcdVoidFn)CQdCallWhenIdle, (void*) msg);  
 }
 
 
 void CQdRegisterCallback(CQdVoidFn fn, void *arg)
 {
-       CcdCallOnCondition(CcdQUIESCENCE, fn, arg);
+  CcdCallOnCondition(CcdQUIESCENCE, fn, arg);
 }
 
 void CQdAnnounceHandler(CQdMsg msg)
 {
-       CQdProcess(CpvAccess(cQdState), -1);
-       CcdRaiseCondition(CcdQUIESCENCE);
+  CQdProcess(CpvAccess(cQdState), -1);
+  CcdRaiseCondition(CcdQUIESCENCE);
 }
 
 
 void CQdInit(void)
 {
-       CpvInitialize(CQdState, cQdState);
-       CpvAccess(cQdState) = CQdStateCreate();
-       CQdHandlerIdx = CmiRegisterHandler((CmiHandler)CQdHandler);
-       CQdAnnounceHandlerIdx = CmiRegisterHandler((CmiHandler)CQdAnnounceHandler);
+  CpvInitialize(CQdState, cQdState);
+  CpvAccess(cQdState) = CQdStateCreate();
+  CQdHandlerIdx = CmiRegisterHandler((CmiHandler)CQdHandler);
+  CQdAnnounceHandlerIdx = 
+    CmiRegisterHandler((CmiHandler)CQdAnnounceHandler);
 }
 
 void CmiStartQD(CQdVoidFn fn, void *arg)
 {
-       register CQdMsg msg = (CQdMsg) CmiAlloc(sizeof(struct ConvQdMsg)); 
-       CQdRegisterCallback(fn, arg);
-       CQdMsgSetPhase(msg, 0);  
-       CmiSetHandler(msg, CQdHandlerIdx);
-       CQdCreate(CpvAccess(cQdState), -1);
-       CmiSyncSendAndFree(0, sizeof(struct ConvQdMsg), (char *)msg);
+  register CQdMsg msg = (CQdMsg) CmiAlloc(sizeof(struct ConvQdMsg)); 
+  CQdRegisterCallback(fn, arg);
+  CQdMsgSetPhase(msg, 0);  
+  CmiSetHandler(msg, CQdHandlerIdx);
+  CQdCreate(CpvAccess(cQdState), -1);
+  CmiSyncSendAndFree(0, sizeof(struct ConvQdMsg), (char *)msg);
 }
+
+
+
index f2f7c1a02a6c61afca48fda0de72b4e1a56dc914..3c87874926ef033769bb13d8195799945dce2c43 100644 (file)
 
 struct ConvQdMsg 
 {  
-       char core[CmiMsgHeaderSizeBytes];
-       int phase; /* 0..2*/
-       union 
-       {
-               struct { int created; int processed; } p1;
-               struct { int dirty; } p2;
-       } u;
+  char core[CmiMsgHeaderSizeBytes];
+  int phase; /* 0..2*/
+  union 
+  {
+    struct { int created; int processed; } p1;
+    struct { int dirty; } p2;
+  } u;
 };
 
 
 struct ConvQdState 
 {
-    int stage; /* 0..2*/
-    int oProcessed;
-    int mCreated, mProcessed;
-    int cCreated, cProcessed;
-    int cDirty;
-    int nReported;
-    int nChildren;
-    int parent;
-    int *children;
+  int stage; /* 0..2*/
+  int oProcessed;
+  int mCreated, mProcessed;
+  int cCreated, cProcessed;
+  int cDirty;
+  int nReported;
+  int nChildren;
+  int parent;
+  int *children;
 };