Added an easy-to-use barrier call, which internally uses a
[charm.git] / src / libs / ck-libs / tcharm / tcharm.C
index eced8bfe9de8086ec284424dab9ef0e71cf5702d..9fdd283703f49d4653ceea24c088a9ad8282ad44 100644 (file)
@@ -258,7 +258,7 @@ FDECL void FTN_NAME(TCHARM_READONLY_GLOBALS,tcharm_readonly_globals)
 
 /************* Startup/Shutdown Coordination Support ************/
 
-enum {TC_READY=23, TC_DONE=42};
+enum {TC_READY=23, TC_BARRIER=87, TC_DONE=42};
 
 //Called when a client is ready to run
 void TCharm::ready(void) {
@@ -269,6 +269,15 @@ void TCharm::ready(void) {
        contribute(sizeof(vals),&vals,CkReduction::sum_int);
 }
 
+//Called when we want to go to a barrier
+void TCharm::barrier(void) {
+       int vals[2]={0,1};
+       if (thisIndex==0) vals[0]=TC_BARRIER;
+       //Contribute to a synchronizing reduction
+       contribute(sizeof(vals),&vals,CkReduction::sum_int);
+       stop();
+}
+
 //Called when the thread is done running
 void TCharm::done(void) {
        DBG("TCharm thread "<<thisIndex<<" done")
@@ -289,6 +298,7 @@ static void coordinatorReduction(void *coord_,int dataLen,void *reductionData)
        DBGX("Finished coordinator reduction: "<<vals[0]<<", "<<vals[1]);
        switch (vals[0]) {
        case TC_READY: coord->clientReady(); break;
+       case TC_BARRIER: coord->clientBarrier(); break;
        case TC_DONE: coord->clientDone(); break;
        default:
                CkAbort("Unexpected value from TCharm array reduction!\n");
@@ -327,6 +337,11 @@ void TCharmCoordinator::clientReady(void)
                threads.run();
        }
 }
+void TCharmCoordinator::clientBarrier(void)
+{
+       DBGX("clients all at barrier");
+       threads.run();
+}
 void TCharmCoordinator::clientDone(void)
 {
        DBGX("clientDone");     
@@ -536,6 +551,15 @@ FDECL void FTN_NAME(TCHARM_MIGRATE,tcharm_migrate)(void)
        TCharm::get()->migrate();
 }
 
+CDECL void TCharmBarrier(void)
+{
+       TCharm::get()->barrier();
+}
+FDECL void FTN_NAME(TCHARM_BARRIER,tcharm_barrier)(void)
+{
+       TCharmBarrier();
+}
+
 CDECL void TCharmDone(void)
 {
        TCharm::get()->done();