Added an easy-to-use barrier call, which internally uses a
authorOrion Lawlor <olawlor@acm.org>
Thu, 10 Jan 2002 19:35:19 +0000 (19:35 +0000)
committerOrion Lawlor <olawlor@acm.org>
Thu, 10 Jan 2002 19:35:19 +0000 (19:35 +0000)
reduction/broadcast cycle.

src/libs/ck-libs/tcharm/tcharm.C
src/libs/ck-libs/tcharm/tcharm.h
src/libs/ck-libs/tcharm/tcharmc.h
src/libs/ck-libs/tcharm/tcharmf.h

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();
index 973db0c2d28bd08bcbb29d058adbf7ff4b609ae8..fc0145f37cd466776e6e222c6cbca0241d9b8de7 100644 (file)
@@ -126,6 +126,9 @@ class TCharm: public ArrayElement1D
        //One client is ready to run
        void ready(void);
 
+       //Sleep till entire array is here
+       void barrier(void);
+
        //Thread finished running
        void done(void);
 
@@ -178,6 +181,7 @@ public:
        ~TCharmCoordinator();
        void addClient(const CkArrayID &client);
        void clientReady(void);
+       void clientBarrier(void);
        void clientDone(void);
        
        static int getTotal(void) {
index b2e0771178af13201061673b52c44939de57931f..8b347a0adcf9f9a2ad0ae19aa58f644e08ce1194 100644 (file)
@@ -49,6 +49,7 @@ int TCharmGetNumChunks(void);
 /**** Routines you can call from the thread (driver) ****/
 int TCharmElement(void);
 int TCharmNumElements(void);
+void TCharmBarrier(void);
 
 typedef void (*TCharmPupFn)(pup_er p,void *data);
 int TCharmRegister(void *data,TCharmPupFn pfn);
index 41b2888241007466686fa3ea1d68cb7843904525..79dae79080ace8a75116b29c99f8d33140d77778 100644 (file)
@@ -6,6 +6,8 @@
        integer, external :: tcharm_element
        integer, external :: tcharm_num_elements
        
+       external tcharm_barrier
+
        external tcharm_register
        external tcharm_migrate
        external tcharm_done