updated version for bluegene.
authorGengbin Zheng <gzheng@illinois.edu>
Thu, 8 May 2003 02:59:27 +0000 (02:59 +0000)
committerGengbin Zheng <gzheng@illinois.edu>
Thu, 8 May 2003 02:59:27 +0000 (02:59 +0000)
src/ck-perf/trace-bluegene.C [new file with mode: 0644]
src/ck-perf/trace-bluegene.h [new file with mode: 0644]
src/ck-perf/trace-converse.c
src/ck-perf/trace-projections.C
src/ck-perf/trace.h

diff --git a/src/ck-perf/trace-bluegene.C b/src/ck-perf/trace-bluegene.C
new file mode 100644 (file)
index 0000000..1dcacd7
--- /dev/null
@@ -0,0 +1,191 @@
+/*****************************************************************************
+ * $Source$
+ * $Author$
+ * $Date$
+ * $Revision$
+ *****************************************************************************/
+
+
+/**
+ * \addtogroup CkPerf
+*/
+/*@{*/
+
+
+#include "charm++.h"
+#include "trace-common.h"
+#include "trace-bluegene.h"
+
+CkpvStaticDeclare(Trace*, _tracebg);
+
+extern int traceBluegeneLinked;
+
+void _createTracebluegene(char** argv)
+{
+  //DEBUGF(("%d createTraceBluegene\n", CkMyPe()));
+  CkpvInitialize(Trace*, _tracebg);
+  CkpvAccess(_tracebg) = new  TraceBluegene(argv);
+  CkpvAccess(_traces)->addTrace(CkpvAccess(_tracebg));
+  traceBluegeneLinked = 1;
+}
+
+
+// this PE must be trace-enabled(in trace-common.C) to be able to do bgPrint()
+static void writeData(void *data, double t, double recvT, void *ptr)
+{
+  FILE *fp = (FILE *)ptr;
+#if 0
+  if(fp !=0)
+    fprintf(fp,(char*)data,t);
+#endif
+  TraceBluegene *traceBluegene = (TraceBluegene *)ptr;
+  traceBluegene->writePrint((char*)data, t);
+}
+
+void TraceBluegene::writePrint(char* str, double t){
+  if (pfp == NULL)
+    creatFiles();
+  fprintf(pfp,str,t);
+}
+
+TraceBluegene::TraceBluegene(char** argv)
+{
+  if(CkMyPe() == 0){
+    stsfp = fopen("bgTraceFile", "w");
+    if(stsfp==0)
+      CmiAbort("Cannot open Bluegene sts file for writing.\n");
+  }
+  
+  pfp = NULL;
+}
+
+void TraceBluegene::traceClose() {
+CmiPrintf("TraceBluegene::traceClose pn %d\n", CkMyPe());
+  bgUpdateProj(2);
+  if(pfp != 0)
+    fclose(pfp);
+  if((CkMyPe() == 0)&&(stsfp !=0))
+    fclose(stsfp);
+}
+
+TraceBluegene::~TraceBluegene(){
+/*
+  bgUpdateProj();
+  if(pfp != 0)
+    fclose(pfp);
+  if((CkMyPe() == 0)&&(stsfp !=0))
+    fclose(stsfp);
+*/
+}
+
+void TraceBluegene::creatFiles()
+{
+  char* fname = new char[15];
+  sprintf(fname,"bgPrintFile%d",CkMyPe());
+  pfp = fopen(fname,"w");     
+  if(pfp==NULL)
+    CmiAbort("Cannot open Bluegene print file for writing.\n");
+}
+
+void TraceBluegene::tlineEnd(void** parentLogPtr){
+  if(genTimeLog)
+    *parentLogPtr = (void*)tTIMELINE[tTIMELINE.length()-1];
+  else
+    *parentLogPtr = NULL;
+}
+
+
+void TraceBluegene::bgBeginExec(char* name,void** parentLogPtr){
+
+
+  if (!genTimeLog) return;
+
+  bgTimeLog* newLog = new bgTimeLog(_threadEP,name,BgGetCurTime());
+  if(*parentLogPtr)
+    newLog->addBackwardDep(*(bgTimeLog**)parentLogPtr);
+  currLog = newLog;
+  BgInsertLog((void*)newLog);
+  *parentLogPtr = newLog;
+}
+
+
+void TraceBluegene::bgEndExec(){
+
+  if (!genTimeLog) return;
+  currLog->closeLog();
+}
+
+
+void TraceBluegene::getForwardDep(void* log, void** fDepPtr){
+
+  bgTimeLog* cLog = (bgTimeLog*) log;
+  
+  if(cLog->forwardDeps.length() !=1) {
+    cLog->write(stdout);
+    CkAbort("Quitting\n");
+  }
+  *fDepPtr = (void*)(cLog->forwardDeps[0]);
+}
+
+void TraceBluegene::getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr){
+  if(!genTimeLog) return;
+
+  bgTimeLog* cLog = (bgTimeLog*)fDepPtr;
+
+  int i=0;
+
+  // find the valid sdag overlap pointer
+  for(i=0;i< logsize+1;i++)
+    if(logs2[i])
+      break;    
+  
+  if (i<logsize+1) {
+    cLog->addBackwardDep((bgTimeLog*)logs2[i]);
+  }
+  // CmiAssert(i<logsize+1);
+  
+  for(int j=0;j<logsize;j++)   
+      cLog->addBackwardDep((bgTimeLog*)(logs1[j]));
+}
+
+void TraceBluegene::userBracketEvent(char* name, double bt, double et, void** parentLogPtr){
+
+  if (!genTimeLog) return;
+
+  bgTimeLog* newLog = new bgTimeLog(_threadEP,name,bt,et);
+  if(*parentLogPtr)
+    newLog->addBackwardDep(*(bgTimeLog**)parentLogPtr);
+  *parentLogPtr = newLog;
+  currLog = newLog;
+  BgInsertLog((void*)newLog);
+}
+
+
+void TraceBluegene::userBracketEvent(char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList){
+   
+  if (!genTimeLog) return;
+
+  bgTimeLog* newLog = new bgTimeLog(_threadEP,name,bt,et);
+  newLog->addBackwardDeps(bgLogList);
+  *parentLogPtr = newLog;
+  currLog = newLog;
+  BgInsertLog((void*)newLog);
+}
+
+
+void TraceBluegene::traceWriteSts(){
+  if (!genTimeLog) return;
+  //  CmiPrintf("\n\n\n[%d]In the traceWriteSts before printing logs\n\n\n\n",CkMyPe());
+  //if(CkMyPe() == 0)
+  // currLog->write(stsfp);
+  return;
+}
+
+void TraceBluegene::bgPrint(char* str){
+  if (!genTimeLog) return;
+  bgAddProjEvent(strdup(str), BgGetTime(), writeData, this, 2);
+
+}
+
+/*@}*/
+
diff --git a/src/ck-perf/trace-bluegene.h b/src/ck-perf/trace-bluegene.h
new file mode 100644 (file)
index 0000000..b1ef3d5
--- /dev/null
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * $Source$
+ * $Author$
+ * $Date$
+ * $Revision$
+ *****************************************************************************/
+
+/**
+ * \addtogroup CkPerf
+*/
+/*@{*/
+
+
+#ifndef _TRACE_BLUEGENE_H
+#define _TRACE_BLUEGENE_H
+
+#include "trace.h"
+#include "blue.h"
+#include "blue_timing.h"
+#include "blue_impl.h"
+
+class TraceBluegene : public Trace {
+
+ private:
+    bgTimeLog* currLog;
+    FILE* stsfp;
+    FILE* pfp;
+ public:
+    TraceBluegene(char** argv);
+    ~TraceBluegene();
+    int traceOnPE() { return 1; }
+    //   void* userBracketEvent(int e, double bt, double et);
+    //    void userBracketEvent(char* name,double bt, double et,char* msg,void** parentLogPtr);
+    void getForwardDep(void* log, void** fDepPtr);
+    void getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr);
+    void tlineEnd(void** parentLogPtr);
+    void bgBeginExec(char* name,void** parentLogPtr);
+    void bgEndExec();
+    void userBracketEvent(char* name, double bt, double et, void** parentLogPtr);
+    void userBracketEvent(char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList);
+    void bgPrint(char* str);
+    void traceWriteSts();
+    void creatFiles();
+    void writePrint(char *, double t);
+    void traceClose();
+};
+
+
+#endif
+
+/*@}*/
index f87d798246543a69f691b168f307dcf2bc0d85be..fa8616e3270ea200d11d551884d5a1a295989c88 100644 (file)
@@ -31,6 +31,7 @@ void traceUserEvent(int i) {}
 void traceUserBracketEvent(int a, double b, double c) {}
 int traceRegisterUserEvent(const char* e, int f) { return -1; }
 void traceClose(void) {}
+void traceCharmClose(void) {}
 void traceBegin(void) {}
 void traceEnd(void) {}
 void traceWriteSts(void) {}
index c68237a1c2d7861e6142c6a84529a93cac37c720..d3b5bd0ebe45c1c7e2f9a374181baa0cc826ed0f 100644 (file)
@@ -261,8 +261,9 @@ LogPool::~LogPool()
 #if CMK_BLUEGENE_CHARM
   extern int correctTimeLog;
   if (correctTimeLog) {
-    creatFiles("-bg");                 // create *-bg.log and *-bg.sts
-    if (CkMyPe() == 0) writeSts();      // write "*-bg.sts"
+    closeLog();
+    creatFiles("-bg");
+    if (CkMyPe() == 0) writeSts();
     postProcessLog();
   }
 #endif
@@ -337,9 +338,9 @@ void LogPool::writeSts(void)
 static void updateProjLog(void *data, double t, double recvT, void *ptr)
 {
   LogEntry *log = (LogEntry *)data;
-  FILE *fp = (FILE *)ptr;
+  FILE *fp = *(FILE **)ptr;
   log->time = t;
-  log->recvTime = recvT;
+  log->recvTime = recvT<0.0?0:recvT;
   log->write(fp);
 }
 #endif
@@ -372,7 +373,7 @@ void LogPool::add(UChar type,UShort mIdx,UShort eIdx,double time,int event,int p
     case BEGIN_UNPACK:
     case END_UNPACK:
     case USER_EVENT_PAIR:
-      bgAddProjEvent(&pool[numEntries-1], time, updateProjLog);
+      bgAddProjEvent(&pool[numEntries-1], time, updateProjLog, &fp, 1);
   }
 #endif
 }
@@ -380,7 +381,7 @@ void LogPool::add(UChar type,UShort mIdx,UShort eIdx,double time,int event,int p
 void LogPool::postProcessLog()
 {
 #if CMK_BLUEGENE_CHARM
-  bgUpdateProj(fp);
+  bgUpdateProj(1);   // event type
 #endif
 }
 
index 782b8fc324743944dfb9e4e470e262dc175a6810..2de35f0f29516cb99b3bac36b8d5aa1fc0bf48eb 100644 (file)
@@ -20,10 +20,21 @@ extern "C" void traceClearEps();
 
 extern double CmiTraceTimer();
 
+// trace_in_charm means only do trace for Charm++ level
+// traceOnPe controls if charm pe will generate trace logs
+#if CMK_TRACE_IN_CHARM
+CkpvExtern(int, traceOnPe);
+#  define TRACE_CHARM_PE()  (CkpvAccess(traceOnPe))
+#else
+          /* skip communication thread */
+#  define TRACE_CHARM_PE()  (CkMyRank() != CkMyNodeSize())
+#endif
+
 // Base class of all tracing strategies.
 // 
 class Trace {
   public:
+    virtual int traceOnPE() { return TRACE_CHARM_PE(); }
     // turn trace on/off, note that charm will automatically call traceBegin()
     // at the beginning of every run unless the command line option "+traceoff"
     // is specified
@@ -77,9 +88,17 @@ class Trace {
     virtual void traceWriteSts() {}
     // do any clean-up necessary for tracing
     virtual void traceClose() {}
+    // only for Blue Gene
+    virtual void tlineEnd(void** parentLogPtr){}
+    virtual void bgBeginExec(char* name,void** pLogPtr){}
+    virtual void bgEndExec(){}
+    virtual void bgPrint(char* str){}
+    virtual void getForwardDepForAll(void** logs1,void** logs2, int size ,void* fDepPtr){}
+    virtual void userBracketEvent(char* name, double bt, double et, void** parentLogPtr){}
+    virtual void userBracketEvent(char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList){}
 };
 
-#define ALLDO(x) for (int i=0; i<length(); i++) traces[i]->x
+#define ALLDO(x) for (int i=0; i<length(); i++) if (traces[i]->traceOnPE()) traces[i]->x
 
 /// Array of Traces modules,  every event raised will go through every Trace module.
 class TraceArray {
@@ -130,6 +149,7 @@ public:
     inline int traceRegisterUserEvent(const char*x, int evt) {
          int eno = 0;
          for (int i=0; i<length(); i++) {
+           if (traces[i]->traceOnPE() == 0) continue;
            int e = traces[i]->traceRegisterUserEvent(x, evt);
            if (e) eno = e;
           }
@@ -140,6 +160,16 @@ public:
     inline void traceClose() {ALLDO(traceClose()); clearTrace();}
     inline void traceBegin() {ALLDO(traceBegin());}
     inline void traceEnd() {ALLDO(traceEnd());}
+    // only for Blue Gene
+    inline void tlineEnd(void** pLogPtr){ALLDO(tlineEnd(pLogPtr));}
+    inline void bgBeginExec(char* name,void** pLogPtr){ALLDO(bgBeginExec(name,pLogPtr));}
+    inline void bgEndExec(){ALLDO(bgEndExec());}
+    inline void bgPrint(char* str){ALLDO(bgPrint(str));}
+    inline void getForwardDepForAll(void** logs1, void**logs2,int size,void* fDepPtr){ALLDO(getForwardDepForAll(logs1, logs2,size,fDepPtr));}
+    inline void userBracketEvent(char* name,double bt, double et, void** pLogPtr) {ALLDO(userBracketEvent(name,bt,et,pLogPtr));}
+    inline void userBracketEvent(char* name,double bt, double et, void** pLogPtr, CkVec<void*> bgLogList) {ALLDO(userBracketEvent(name,bt,et,pLogPtr,bgLogList))
+;}
+
 };
 
 CkpvExtern(TraceArray*, _traces);
@@ -148,15 +178,8 @@ extern "C" {
 #include "conv-trace.h"
 }
 
-// traceOnPe controls if charm pe will generate trace logs
-#if CMK_TRACE_IN_CHARM
-CkpvExtern(int, traceOnPe);
-#  define TRACE_CHARM_PE()  (CkpvAccess(traceOnPe))
-#else
-#  define TRACE_CHARM_PE()  (CkMyRank() != CkMyNodeSize())
-#endif
 #ifndef CMK_OPTIMIZE
-#  define _TRACE_ONLY(code) do{if(CpvAccess(traceOn)&&TRACE_CHARM_PE()){ code; }} while(0)
+#  define _TRACE_ONLY(code) do{if(CpvAccess(traceOn)){ code; }} while(0)
 #else
 #  define _TRACE_ONLY(code) /*empty*/
 #endif
@@ -183,8 +206,17 @@ CkpvExtern(int, traceOnPe);
 #define _TRACE_ENQUEUE(env) _TRACE_ONLY(CkpvAccess(_traces)->enqueue(env))
 #define _TRACE_DEQUEUE(env) _TRACE_ONLY(CkpvAccess(_traces)->dequeue(env))
 
+// for Blue Gene only
+#define BgPrint(x)  _TRACE_ONLY(CkpvAccess(_traces)->bgPrint(x))
+#define _TRACE_BG_BEGIN_EXECUTE(x,pLogPtr)  _TRACE_ONLY(CkpvAccess(_traces)->bgBeginExec(x,pLogPtr))
+#define _TRACE_BG_END_EXECUTE()   _TRACE_ONLY(CkpvAccess(_traces)->bgEndExec())
+#define _TRACE_BG_TLINE_END(pLogPtr) _TRACE_ONLY(CkpvAccess(_traces)->tlineEnd(pLogPtr))
+#define _TRACE_BG_FORWARD_DEPS(logs1,logs2,size,fDep)  _TRACE_ONLY(CkpvAccess(_traces)->getForwardDepForAll(logs1,logs2, size,fDep))
+#define _TRACE_BG_USER_EVENT_BRACKET(x,bt,et,pLogPtr) _TRACE_ONLY(CkpvAccess(_traces)->userBracketEvent(x,bt,et,pLogPtr))
+#define _TRACE_BGLIST_USER_EVENT_BRACKET(x,bt,et,pLogPtr,bgLogList) _TRACE_ONLY(CkpvAccess(_traces)->userBracketEvent(x,bt,et,pLogPtr,bgLogList))
+
+
 #endif
 
 
 /*@}*/
-