From 01498cb3b2e958ea44b4eeb49f31bb1e1263e482 Mon Sep 17 00:00:00 2001 From: jjenista Date: Thu, 13 Aug 2009 23:38:58 +0000 Subject: [PATCH] sese's wait for children to exit before exiting --- Robust/src/IR/Flat/BuildCode.java | 38 +++++++++++++++++++++---- Robust/src/Runtime/mlp_runtime.c | 24 ---------------- Robust/src/Runtime/mlp_runtime.h | 26 ++++++----------- Robust/src/Tests/mlp/tinyTest/test.java | 19 +++++++------ 4 files changed, 52 insertions(+), 55 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index fa42b1f0..3b633ba2 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -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 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 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 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, diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c index a01e220b..26551d0b 100644 --- a/Robust/src/Runtime/mlp_runtime.c +++ b/Robust/src/Runtime/mlp_runtime.c @@ -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 ) { - -} -*/ diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index b4b2d05e..f2f291d3 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -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__ */ diff --git a/Robust/src/Tests/mlp/tinyTest/test.java b/Robust/src/Tests/mlp/tinyTest/test.java index 4dd35d99..6f38215b 100644 --- a/Robust/src/Tests/mlp/tinyTest/test.java +++ b/Robust/src/Tests/mlp/tinyTest/test.java @@ -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 -- 2.34.1