35 #define MAX_COMM_NUM 1000
38 #define ABC_PRT(a,t) (printf("%s = ", (a)), printf("%7.2f sec\n", (float)(t)/(float)(CLOCKS_PER_SEC)))
44 pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
63 if (
system( (
char *)Command ) )
66 fprintf( stderr,
"The following command has returned non-zero exit status:\n" );
67 fprintf( stderr,
"\"%s\"\n", (
char *)Command );
68 fprintf( stderr,
"Sorry for the inconvenience.\n" );
97 int main(
int argc,
char * argv[] )
99 FILE * pFile, * pOutput = stdout;
102 int i, nCPUs = 0, nLines = 0,
Counter;
103 clock_t clk = clock();
107 { fprintf( stderr,
"Wrong number of command line arguments.\n" );
goto usage; }
110 nCPUs = atoi( argv[1] );
112 { fprintf( pOutput,
"Cannot read an integer represting the number of CPUs.\n" );
goto usage; }
115 pFile = fopen( argv[2],
"r" );
117 { fprintf( pOutput,
"Input file \"%s\" cannot be opened.\n", argv[2] );
goto usage; }
124 if ( Buffer[0] ==
'\n' || Buffer[0] ==
'\r' || Buffer[0] ==
'\t' ||
125 Buffer[0] ==
' ' || Buffer[0] ==
'#')
130 if ( Buffer[
strlen(Buffer)-1] ==
'\n' )
131 Buffer[
strlen(Buffer)-1] = 0;
132 if ( Buffer[
strlen(Buffer)-1] ==
'\r' )
133 Buffer[
strlen(Buffer)-1] = 0;
149 printf(
"Calling: %s\n", (
char *)Buffer );
155 assert(pthread_create( &ThreadIds[nLines], NULL,
Abc_RunThread, (
void *)pBufferCopy ) == 0);
157 { fprintf( pOutput,
"Cannot execute more than %d commands from file \"%s\".\n", nLines, argv[2] );
break; }
174 printf(
"Finished processing commands in file \"%s\". ", argv[2] );
175 ABC_PRT(
"Total time", clock() - clk );
180 for ( i =
strlen(argv[0]) - 1; i > 0; i-- )
181 if ( argv[0][i-1] ==
'\\' || argv[0][i-1] ==
'/' )
184 fprintf( pOutput,
"usage: %s <num> <file>\n", argv[0]+i );
185 fprintf( pOutput,
" executes command listed in <file> in parallel on <num> CPUs\n" );
186 fprintf( pOutput,
"\n" );
static int nThreadsRunning
void * Abc_RunThread(void *Command)
char * Abc_UtilStrsav(char *s)
int main(int argc, char *argv[])
GLOBAL VARIABLES ///.