sese's wait for children to exit before exiting
authorjjenista <jjenista>
Thu, 13 Aug 2009 23:38:58 +0000 (23:38 +0000)
committerjjenista <jjenista>
Thu, 13 Aug 2009 23:38:58 +0000 (23:38 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/mlp_runtime.c
Robust/src/Runtime/mlp_runtime.h
Robust/src/Tests/mlp/tinyTest/test.java

index fa42b1f0603b3b51369d7874ba81072373bb2dd7..3b633ba2e2973b6d474c5c9d6917c13f2ab1f488 100644 (file)
@@ -2765,6 +2765,13 @@ public class BuildCode {
 
     output.println("   {");
 
+    // before doing anything, lock your own record and increment the running children
+    if( fsen != mlpa.getRootSESE() ) {
+      output.println("     pthread_mutex_lock( &("+paramsprefix+"->common.lock) );");
+      output.println("     ++("+paramsprefix+"->common.numRunningChildren);");
+      output.println("     pthread_mutex_unlock( &("+paramsprefix+"->common.lock) );");
+    }
+
     // just allocate the space for this record
     output.println("     "+fsen.getSESErecordName()+"* seseToIssue = ("+
                           fsen.getSESErecordName()+"*) mlpAllocSESErecord( sizeof( "+
@@ -2782,6 +2789,14 @@ public class BuildCode {
     output.println("     seseToIssue->common.forwardList = createQueue();");
     output.println("     seseToIssue->common.unresolvedDependencies = 0;");
     output.println("     seseToIssue->common.doneExecuting = FALSE;");    
+    output.println("     pthread_cond_init( &(seseToIssue->common.runningChildrenCond), NULL );");
+    output.println("     seseToIssue->common.numRunningChildren = 0;");
+
+    if( fsen != mlpa.getRootSESE() ) {
+      output.println("     seseToIssue->common.parent = (SESEcommon*) "+paramsprefix+";");
+    } else {
+      output.println("     seseToIssue->common.parent = NULL;");
+    }
 
     // all READY in-vars should be copied now and be done with it
     Iterator<TempDescriptor> tempItr = fsen.getReadyInVarSet().iterator();
@@ -2797,22 +2812,18 @@ public class BuildCode {
          fsen.getParent().getInVarSet().contains( temp ) ||
          fsen.getParent().getOutVarSet().contains( temp ) 
        ) {
-       //from = "(void*) &("+paramsprefix+"->"+temp.getSafeSymbol()+")";
        from = paramsprefix+"->"+temp.getSafeSymbol();
       } else {
        from = temp.getSafeSymbol();
       }
    
-      //String to   = "(void*) &(seseToIssue->"+temp.getSafeSymbol()+")";
       String to   = "seseToIssue->"+temp.getSafeSymbol();
       String size = "sizeof( seseToIssue->"+temp.getSafeSymbol()+" )";
-      
-      //output.println("     memcpy( "+to+", "+from+", "+size+" );");
+
       output.println("     "+to+" = "+from+";");
     }
 
     if( fsen != mlpa.getRootSESE() ) {
-
       // count up outstanding dependencies, static first, then dynamic
       Iterator<SESEandAgePair> staticSrcsItr = fsen.getStaticInVarSrcs().iterator();
       while( staticSrcsItr.hasNext() ) {
@@ -2870,6 +2881,15 @@ public class BuildCode {
 
     String com = paramsprefix+"->common";
 
+    // this SESE cannot be done until all of its children are done
+    // so grab your own lock with the condition variable for watching
+    // that the number of your running children is greater than zero
+    output.println("   pthread_mutex_lock( &("+com+".lock) );");
+    output.println("   while( "+com+".numRunningChildren > 0 ) {");
+    output.println("     pthread_cond_wait( &("+com+".runningChildrenCond), &("+com+".lock) );");
+    output.println("   }");
+    output.println("   pthread_mutex_unlock( &("+com+".lock) );");    
+
     // copy out-set from local temps into the sese record
     Iterator<TempDescriptor> itr = fsexn.getFlatEnter().getOutVarSet().iterator();
     while( itr.hasNext() ) {
@@ -2899,6 +2919,14 @@ public class BuildCode {
     if( fsexn.getFlatEnter() != mlpa.getRootSESE() ) {
       output.println("     psem_give( &("+paramsprefix+"->common.stallSem) );");
     }
+
+    // last of all, decrement your parent's number of running children
+    output.println("     if( "+paramsprefix+"->common.parent != NULL ) {");
+    output.println("       pthread_mutex_lock( &("+paramsprefix+"->common.parent->lock) );");
+    output.println("       --("+paramsprefix+"->common.parent->numRunningChildren);");
+    output.println("       pthread_cond_signal( &("+paramsprefix+"->common.parent->runningChildrenCond) );");
+    output.println("       pthread_mutex_lock( &("+paramsprefix+"->common.parent->lock) );");
+    output.println("     }");
   }
 
   public void generateFlatWriteDynamicVarNode( FlatMethod fm,  
index a01e220b64f29365f0e493ed8f13395c87163288..26551d0b00ba41b5fb3eb2fffbfb3bc92e912f41 100644 (file)
@@ -10,7 +10,6 @@
 #include "workschedule.h"
 
 
-
 void* mlpAllocSESErecord( int size ) {
   void* newrec = RUNMALLOC( size );  
   return newrec;
@@ -20,26 +19,3 @@ void* mlpAllocSESErecord( int size ) {
 void mlpFreeSESErecord( void* seseRecord ) {
   RUNFREE( seseRecord );
 }
-
-/*
-void mlpInit( int numProcessors, 
-             void(*workFunc)(void*),
-             int argc, char** argv,
-             int maxSESEage ) {  
-
-  // first initialize the work scheduler
-  //workScheduleInit( numProcessors, workFunc );
-
-  //workScheduleBegin();
-}
-*/
-/*
-void mlpCommonIssueActions( void* seseRecord ) {
-  
-}
-
-
-void mlpStall( void* seseRecord ) {
-  
-}
-*/
index b4b2d05e953a99a54ceba56c35bf629ccf39fa94..f2f291d3e92473bf74c54dffa0b819d7cb61da41 100644 (file)
@@ -15,6 +15,8 @@
 #define TRUE 1
 #endif
 
+// forward declaration of pointer type
+typedef struct SESEcommon_t* SESEcommon_p;
 
 // these fields are common to any SESE, and casting the
 // generated SESE record to this can be used, because
@@ -30,25 +32,20 @@ typedef struct SESEcommon_t {
   // this child, the child gives it at its SESE exit
   psemaphore stallSem;
 
+  
   // the lock guards the following data SESE's
   // use to coordinate with one another
   pthread_mutex_t lock;
+
   struct Queue*   forwardList;
   int             unresolvedDependencies;
   int             doneExecuting;
 
-} SESEcommon;
-
+  pthread_cond_t  runningChildrenCond;
+  int             numRunningChildren;
+  SESEcommon_p    parent;
 
-/*
-// a parent remembers an SESE instance, say class ID=2
-// and age=0, by declaring an SESEvarSrc seseID2_age0
-// and keeping the fields up-to-date
-typedef struct SESEvarSrc_t {
-  void*  sese;
-  INTPTR addr;
-} SESEvarSrc;
-*/
+} SESEcommon;
 
 
 // simple mechanical allocation and 
@@ -57,11 +54,4 @@ void* mlpCreateSESErecord( int size );
 void  mlpDestroySESErecord( void* seseRecord );
 
 
-// main library functions
-/*
-void mlpInit();
-void mlpCommonIssueActions( void* seseRecord );
-void mlpStall( void* seseRecord );
-*/
-
 #endif /* __MLP_RUNTIME__ */
index 4dd35d9941c941c779d813c151eaa53ba3c1049d..6f38215b55337f343b3e9f8ebc313182e9c3ecad 100644 (file)
@@ -4,7 +4,6 @@ public class Foo {
 
 
 // TODO
-// -dynamic variables
 // -objects
 
 
@@ -17,22 +16,26 @@ public class Test {
     System.out.println( "root: x="+x+", y="+y );
 
     if( x > 3 ) {
-      sese fi {
+      sese fee {
        y = y + 10;
       }
     }
-    
+
+    /*
+    sese fie {
+      float xyz = -2.0f;
+    }
+    float jjj = Math.abs( xyz );
+    */
+
     // see that values from sese fi are
     // forwarded to this sibling
-    //sese fo {
+    //sese foe {
     //System.out.println( "fo: x="+x+", y="+y );
+    //System.out.println( "y="+y+" xyz="+xyz );
     System.out.println( "y="+y );
     //}
 
-    /*
-    float xyz = 2.0f;
-    float jjj = Math.abs( xyz );
-    */
 
 
     // just for testing root's ability to