legacy_sources/v1/libparallel.c
/*----------------------------------------------------------*/
/* Launch the loop prc on typ1 element depending on typ2	*/
/*----------------------------------------------------------*/
Launch the loop prc on typ1 element depending on typ2
Launch the loop prc on typ1 element depending on typ2
float LaunchParallel(int typ1, int typ2, void *prc, void *arg)
{
	int i, sta;
	if( (typ1 < 1) || (typ1 > MaxTyp) || (typ2 < 0) || (typ2 > MaxTyp) || (typ1 == typ2) )
		return(0.);
	pthread_mutex_lock(par->mtx);
	par->prc = (void (*)(int, int, int, void *))prc;
	par->arg = arg;
	par->typ1 = &par->TypTab[ typ1 ];
	par->WrkCpt = 0;
	par->sta[0] = par->sta[1] = 0.;
	if(typ2)
		par->typ2 = &par->TypTab[ typ2 ];
	else
		par->typ2 = NULL;
	for(i=0;i<par->NmbCpu;i++)
		par->PthTab[i].sta = ParLok;
	for(i=0;i<par->typ1->NmbWrk;i++)
		par->typ1->WrkTab[i].flg = 0;
	pthread_mutex_unlock(par->mtx);
	do
	{
		pthread_mutex_lock(par->mtx);
		sta = ParIdl;
		for(i=0;i<par->NmbCpu;i++)
			if(par->PthTab[i].sta != ParIdl)
				sta = ParRun;
		pthread_mutex_unlock(par->mtx);
		usleep(IdlTim);
	}while(sta == ParRun);
	return(par->sta[1] / par->sta[0]);
}
float LaunchParallel ( int typ1 , int typ2 , void * prc , void * arg ) { int i , sta ; if ( ( typ1 < 1 ) || ( typ1 > MaxTyp ) || ( typ2 < 0 ) || ( typ2 > MaxTyp ) || ( typ1 == typ2 ) ) return ( 0. ) ; pthread_mutex_lock ( par -> mtx ) ; par -> prc = ( void ( * ) ( int , int , int , void * ) ) prc ; par -> arg = arg ; par -> typ1 = & par -> TypTab [ typ1 ] ; par -> WrkCpt = 0 ; par -> sta [ 0 ] = par -> sta [ 1 ] = 0. ; if ( typ2 ) par -> typ2 = & par -> TypTab [ typ2 ] ; else par -> typ2 = NULL ; for ( i = 0 ; i < par -> NmbCpu ; i ++ ) par -> PthTab [ i ] . sta = ParLok ; for ( i = 0 ; i < par -> typ1 -> NmbWrk ; i ++ ) par -> typ1 -> WrkTab [ i ] . flg = 0 ; pthread_mutex_unlock ( par -> mtx ) ; do { pthread_mutex_lock ( par -> mtx ) ; sta = ParIdl ; for ( i = 0 ; i < par -> NmbCpu ; i ++ ) if ( par -> PthTab [ i ] . sta != ParIdl ) sta = ParRun ; pthread_mutex_unlock ( par -> mtx ) ; usleep ( IdlTim ) ; } while ( sta == ParRun ) ; return ( par -> sta [ 1 ] / par -> sta [ 0 ] ) ; }
Launch the loop prc on typ1 element depending on typ2
Launch the loop prc on typ1 element depending on typ2
/* Check bounds */ /* Protect launch command within a mutex */ /* Now wait for every threads to get idle */ /* Return the average speedup */