// -------------------------------------------------------------------------------------------------
void fjm_Start
(
    void
)
// -------------------------------------------------------------------------------------------------
{
    LE_TEST_INFO("FJM TESTS START");

    memset(TestResults, 0, sizeof(TestResults));
    Counter = 0;

    // Compute the expected ending counter value.
    ExpectedCounterValue = GetExpectedCounterValue();

    // Create semaphore to trigger
    CounterSemRef = le_sem_Create("CounterSem", 0);

    // Create the mutex.
    MutexRef = le_mutex_CreateNonRecursive("fork-join-mutex-test");

    // Create the Context Pool.
    if (ContextPoolRef == NULL)
    {
        LE_TEST_INFO("Initializing FJM-ContextPool");
        ContextPoolRef = le_mem_CreatePool("FJM-ContextPool", sizeof(Context_t));
        le_mem_ExpandPool(ContextPoolRef, ExpectedCounterValue);
    }

    // Spawn the first child thread.
    SpawnChildren(1);
}
 task* execute () {
     if ( m_depth < 0 )
         return NULL; // I'm just a continuation now
     recycle_as_safe_continuation();
     SpawnChildren(this);
     m_depth = -1;
     return NULL;
 }
 task* execute () {
     tbb::task_group_context ctx; // Use bound context
     tbb::empty_task &r = *new( task::allocate_root(ctx) ) tbb::empty_task;
     SpawnChildren(&r);
     r.wait_for_all();
     task::destroy(r);
     return NULL;
 }
Exemple #4
0
int AddChildsInd(Node *n,int var,int cut)
{
	// Add children to bottom node n
	// use rule for ordinal rule var, with index of rule cut
	// (in global array RuleMat[NumX+1][RuleNum[i]+1]
	// only works for ordinal rules right now

	if(VarType[var]!=ORD)
	{
		printf("AddChilds: error, VarType!=ORD");
		return 0;
	}
	if((n->Bot)!=1)
	{
		printf("AddChilds: error, node not bottom");
		return 0;
	}

	int LeftI,RightI;
	GetSplitInterval(&LeftI,&RightI,n,var);
	if(cut<LeftI) 
	{
		printf("AddChilds: error, cut<LeftI");
		return 0;
	}
	if(cut>RightI)
	{
		printf("AddChilds: error, cut>LeftI");
		return 0;
	}
	
	int LeftEx=0;
	int RightEx=0;

	n->Bot = 0;
	n->Nog = 1;
	if(!(n->Top)) (n->Parent)->Nog=0;

	(n->rule).Var=var;
	(n->rule).OrdRule = cut;

	
	if((n->rule).OrdRule==LeftI) LeftEx=1;
	if((n->rule).OrdRule==RightI) RightEx=1;

	SpawnChildren(n,LeftEx,RightEx);

	return 1;

}
Exemple #5
0
// -------------------------------------------------------------------------------------------------
void fjm_Start
(
    void* completionObjPtr  ///< [in] Pointer to the object whose reference count is used to signal
                            ///       the completion of the test.
)
// -------------------------------------------------------------------------------------------------
{
    // Compute the expected ending counter value.
    ExpectedCounterValue = GetExpectedCounterValue();

    // Create the mutex.
    MutexRef = le_mutex_CreateNonRecursive("fork-join-mutex-test");

    LE_INFO("completionObjPtr = %p.", completionObjPtr);

    // Create the Context Pool.
    ContextPoolRef = le_mem_CreatePool("FJM-ContextPool", sizeof(Context_t));
    le_mem_ExpandPool(ContextPoolRef, ExpectedCounterValue);

    // Spawn the first child thread.
    SpawnChildren(1, completionObjPtr);
}
Exemple #6
0
// -------------------------------------------------------------------------------------------------
static void* ThreadMainFunction
(
    void* objPtr
)
// -------------------------------------------------------------------------------------------------
{
    Context_t* contextPtr = objPtr;

    LE_INFO("Thread '%s' started.", le_thread_GetMyName());

    IncrementCounter();

    if (contextPtr->depth < DEPTH)
    {
        LE_INFO("Thread '%s' spawning children.", le_thread_GetMyName());

        SpawnChildren(contextPtr->depth + 1, contextPtr->completionObjPtr);
    }

    LE_INFO("Thread '%s' terminating.", le_thread_GetMyName());

    return contextPtr->completionObjPtr;
}
 task* execute () {
     SpawnChildren(this);
     wait_for_all();
     return NULL;
 }
Exemple #8
0
double BirthDeath(Node *top,int *BD,int *Done)
//does either a birth or death step
//top: top of tree
//BD: on exit, 1 if birth , 0 if death
//Done: on exit, 1 if step taken , 0 otherwise
{

	double PGn,Pbot,PBx,PGl,PGr,PDy,Pnog;
	double PDx,PBy;
	double temprob;


	int VarI;
	int LeftEx,RightEx;
	double alpha1,alpha2,alpha;


	double Ly,Lx;

	Rule *rule=new Rule;

	Node *n,*tempnode;

	PBx=PBirth(top,&n,&Pbot);

	
	
	
	if(Bern(PBx)) {
	
		*BD=1;

		
		PGn = PGrow(n);	
	
		Lx = LogLT(n,top);

		VarI = DrPriVar(n);//draw variable
		DrPriRule(VarI,n,&LeftEx,&RightEx);//draw rule
		SpawnChildren(n,LeftEx,RightEx); //create children

		// this omitted because we will implement it at the metrop level
		/*if ((((n->LeftC)->DataList).length < 5) || (((n->RightC)->DataList).length < 5)){
			// back out if we have less than 5 obs in either new kid; clean up first
			KillChildren(n);
			return -1;
		}*/

		PGl = PGrow(n->LeftC);
		PGr = PGrow(n->RightC);
		Ly = LogLT(n,top);
		
		Pnog = 1.0/((double)(top->NumNogNodes()));
	
		PDy = 1.0-PBirth(top,&tempnode,&temprob);

		alpha1 = (PGn*(1.0-PGl)*(1.0-PGr)*PDy*Pnog)/((1.0-PGn)*PBx*Pbot);
		alpha2 = alpha1*exp(Ly-Lx);
		alpha = min(1.0,alpha2);
			
		if(Bern(alpha)) {		
			*Done=1;
		} else {
			
			KillChildren(n);
			*Done=0;
		}
	} else {
			
			*BD=0;
			PDx=1-PBx;
			Pnog = DrNogNode(top,&n);
			PGl = PGrow(n->LeftC);
			PGr = PGrow(n->RightC);
			
			Lx = LogLT(n,top);

			CopyRule(&(n->rule),rule);
			LeftEx=1-((n->LeftC)->VarAvail[(n->rule).Var]);
			RightEx=1-((n->RightC)->VarAvail[(n->rule).Var]);

			KillChildren(n);
		
			Ly = LogLT(n,top);
			PBy = PBirth(top,&tempnode,&temprob);
			PGn = PGrow(n);
			Pbot=PrBotNode(top,n);
			alpha1 =((1.0-PGn)*PBy*Pbot)/(PGn*(1.0-PGl)*(1.0-PGr)*PDx*Pnog);
			alpha2 = alpha1*exp(Ly-Lx);
			alpha = min(1,alpha2);
			
			if(Bern(alpha)) {
				
				*Done=1;
			} else {
				//put back rule and children
				
				CopyRule(rule,&(n->rule));
				SpawnChildren(n,LeftEx,RightEx);
				
				*Done=0;

			}
			
	}
	delete rule;

	return alpha;

	
}