28#ifdef ABC_USE_PTHREADS
31#include "../lib/pthread.h"
45#ifndef ABC_USE_PTHREADS
47void Cmd_RunStarter(
char * pFileName,
char * pBinary,
char * pCommand,
int nCores,
int fVerbose ) {}
52static volatile int nThreadsRunning = 0;
55pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
76 if (
system( (
char *)pCommand ) )
78 fprintf( stderr,
"The following command has returned non-zero exit status:\n" );
79 fprintf( stderr,
"\"%s\"\n\n", (
char *)pCommand );
85 status = pthread_mutex_lock(&
mutex);
assert(status == 0);
87 status = pthread_mutex_unlock(&
mutex);
assert(status == 0);
107void Cmd_RunStarter(
char * pFileName,
char * pBinary,
char * pCommand,
int nCores,
int fVerbose )
109 FILE * pFile, * pFileTemp;
110 pthread_t * pThreadIds;
111 char * BufferCopy, * Buffer;
112 int nLines, LineMax, Line,
Len;
113 int i, c, status, Counter;
119 fprintf( stdout,
"The number of cores (%d) should be more than 1.\n", nCores );
124 pFile = fopen( pFileName,
"rb" );
127 fprintf( stdout,
"Input file \"%s\" cannot be opened.\n", pFileName );
132 nLines = LineMax = Line = 0;
133 while ( (c = fgetc(pFile)) != EOF )
139 LineMax = Abc_MaxInt( LineMax, Line );
143 LineMax += LineMax + 100;
144 LineMax += pBinary ?
strlen(pBinary) : 0;
145 LineMax += pCommand ?
strlen(pCommand) : 0;
149 pThreadIds =
ABC_ALLOC( pthread_t, nLines );
152 if ( pCommand != NULL )
156 for ( i = 0; fgets( Buffer, LineMax, pFile ) != NULL; i++ )
160 if ( Buffer[
Len] ==
'\n' || Buffer[
Len] ==
'\r' || Buffer[
Len] ==
'\t' || Buffer[
Len] ==
' ' )
166 if ( Buffer[0] == 0 || Buffer[0] ==
'\n' || Buffer[0] ==
'\r' || Buffer[0] ==
'\t' || Buffer[0] ==
' ' || Buffer[0] ==
'#' )
170 pFileTemp = fopen( Buffer,
"rb" );
171 if ( pFileTemp == NULL )
173 fprintf( stdout,
"Starter cannot open file \"%s\".\n", Buffer );
186 for ( i = 0; fgets( Buffer, LineMax, pFile ) != NULL; i++ )
190 if ( Buffer[
Len] ==
'\n' || Buffer[
Len] ==
'\r' || Buffer[
Len] ==
'\t' || Buffer[
Len] ==
' ' )
196 if ( Buffer[0] == 0 || Buffer[0] ==
'\n' || Buffer[0] ==
'\r' || Buffer[0] ==
'\t' || Buffer[0] ==
' ' || Buffer[0] ==
'#' )
200 if ( pCommand != NULL )
206 BufferCopy = Abc_UtilStrsav( Buffer );
208 fprintf( stdout,
"Calling: %s\n", (
char *)BufferCopy );
215 status = pthread_mutex_lock(&
mutex);
assert(status == 0);
216 Counter = nThreadsRunning;
217 status = pthread_mutex_unlock(&
mutex);
assert(status == 0);
218 if ( Counter < nCores - 1 )
224 status = pthread_mutex_lock(&
mutex);
assert(status == 0);
226 status = pthread_mutex_unlock(&
mutex);
assert(status == 0);
229 status = pthread_create( &pThreadIds[i], NULL,
Abc_RunThread, (
void *)BufferCopy );
assert(status == 0);
239 status = pthread_mutex_lock(&
mutex);
assert(status == 0);
240 Counter = nThreadsRunning;
241 status = pthread_mutex_unlock(&
mutex);
assert(status == 0);
249 fprintf( stdout,
"Finished processing commands in file \"%s\". ", pFileName );
250 Abc_PrintTime( 1,
"Total wall time", Abc_Clock() - clk );
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START void Cmd_RunStarter(char *pFileName, char *pBinary, char *pCommand, int nCores, int fVerbose)
DECLARATIONS ///.
void * Abc_RunThread(void *Command)