Protecting function with #if (and removing debug print)
[charm.git] / src / conv-ccs / middle-ccs.C
index 82521da2bdd963065712c464c9ce23e68a99fa26..262aef92bc63b228601fe7436a450df824ca22b0 100644 (file)
@@ -40,3 +40,79 @@ extern "C" void req_fw_handler(char *msg)
   CcsHandleRequest(hdr, msg+offset);
   CmiFree(msg);
 }
+
+extern "C" void CcsSendReply(int replyLen, const void *replyData);
+/**********************************************
+  "ccs_getinfo"-- takes no data
+    Return the number of parallel nodes, and
+      the number of processors per node as an array
+      of 4-byte big-endian ints.
+*/
+
+void ccs_getinfo(char *msg)
+{
+  int nNode=CmiNumNodes();
+  int len=(1+nNode)*sizeof(ChMessageInt_t);
+  ChMessageInt_t *table=(ChMessageInt_t *)malloc(len);
+  int n;
+  table[0]=ChMessageInt_new(nNode);
+  for (n=0;n<nNode;n++)
+    table[1+n]=ChMessageInt_new(CmiNodeSize(n));
+  CcsSendReply(len,(const char *)table);
+  free(table);
+  CmiFree(msg);
+}
+
+//////////////////////////////////////////////////////////////////// middle-debug.C
+
+extern "C" {
+
+CpvDeclare(void *, debugQueue);
+CpvDeclare(int, freezeModeFlag);
+
+/*
+ Start the freeze-- call will not return until unfrozen
+ via a CCS request.
+ */
+void CpdFreeze(void)
+{
+  CpdNotify(CPD_FREEZE,getpid());
+  if (CpvAccess(freezeModeFlag)) return; /*Already frozen*/
+  CpvAccess(freezeModeFlag) = 1;
+#if ! CMK_BLUEGENE_CHARM
+  CpdFreezeModeScheduler();
+#endif
+}
+
+void CpdUnFreeze(void)
+{
+  CpvAccess(freezeModeFlag) = 0;
+}
+
+int CpdIsFrozen(void) {
+  return CpvAccess(freezeModeFlag);
+}
+
+}
+
+#if CMK_BLUEGENE_CHARM
+#include "blue_impl.h"
+void BgProcessMessageFreezeMode(threadInfo *t, char *msg) {
+//  CmiPrintf("BgProcessMessageFreezeMode\n");
+#if CMK_CCS_AVAILABLE
+  void *debugQ=CpvAccess(debugQueue);
+  CmiAssert(msg!=NULL);
+  int processImmediately = CpdIsDebugMessage(msg);
+  if (processImmediately) BgProcessMessageDefault(t, msg);
+  while (!CpvAccess(freezeModeFlag) && !CdsFifo_Empty(debugQ)) {
+    BgProcessMessageDefault(t, (char*)CdsFifo_Dequeue(debugQ));
+  }
+  if (!processImmediately) {
+    if (!CpvAccess(freezeModeFlag)) BgProcessMessageDefault(t, msg); 
+    else CdsFifo_Enqueue(debugQ, msg);
+  }
+#else
+  BgProcessMessageDefault(t, msg);
+#endif
+}
+#endif