void PrintRolls( int rolls[] ) { int i; for ( i=kMinRoll; i<=kMaxRoll; i++ ) { printf( "%2d (%3d): ", i, rolls[ i ] ); PrintX( rolls[ i ] / 10 ); printf( "\n" ); } }
void PrintRolls( int rolls[] ) { int i; for ( i = 2; i <= 12; i++ ) { printf( "%2d (%3d): ", i, rolls[ i ] ); PrintX( rolls[ i ] / 10 ); putchar( '\n' ); } }
// MAIN routine main(int argc, char **argv) { clock_t clkStart,clkStop; //Elapsed times using <times()> struct tms tStart,tStop; //CPU times for the threads int k, i, j, temp; double max; vFlag = 0; GetParam(argc, argv); int row ;int col; pivoting(0); CurrentRow = Norm +1; Count = NumThreads -1; printf("Starting timing ... computing ...\n"); clkStart = times(&tStart); create_threads(); wait_for_threads(); //printf("before back substitution:\n"); //printAB(); //PrintX(); // Back substitution in sequential for (i=N-1; i>=0; i--) { X[idx[i]] = B[idx[i]]; for (j=N-1; j>i; j--) //X[idx[i]]-=colA[j][idx[i]]*X[idx[j]]; X[idx[i]]-=rowA[idx[i]][j]*X[idx[j]]; X[idx[i]] /= rowA[idx[i]][i]; } clkStop = times(&tStop); printf("Stopped timing.\n"); if (N<MAXN4print) PrintX(); if (vFlag) for (i=0;i<N;i++) if (fabs(X[idx[i]]-(double)(i+1))>0.01) printf("Incorrect results, i=%d, X[i]=%f\n",i,X[idx[i]]); printf("Elapsed time = %g ms.\n", (float)(clkStop-clkStart) /(float)sysconf(_SC_CLK_TCK)*1000); printf("The total CPU time comsumed = %g ms.\n", (float)((tStop.tms_utime-tStart.tms_utime) + (tStop.tms_stime-tStart.tms_stime)) / (float)sysconf(_SC_CLK_TCK)*1000); }
void PrintPoly(int poly[], int degree, bool deriv){ bool firstTurm = false; // loop though each turn in the polynomial for (int i = 0; i < degree; i++){ // Output the first turm slightly different if ((poly[i] != 0) && (!firstTurm) && ( (deriv ? (degree - i -2) :(degree - i -1)) >= 0) ){ firstTurm = true; PrintSign(poly[i], true); PrintPreX(deriv ? poly[i] * (degree - i -1) : poly[i], deriv ? (degree - i ) :(i == degree -1), firstTurm, deriv); PrintX(deriv ? (degree - i -2) :(degree - i -1)); }else if ((poly[i] != 0) && ((deriv ? (degree - i -2) :(degree - i -1)) >= 0 )){ // output the rest of the turms PrintSign(poly[i], false); PrintPreX(deriv ? poly[i] * (degree - i -1) : poly[i], deriv ? (degree - i ) :(i == degree -1), firstTurm, deriv); PrintX(deriv ? (degree - i -2) :(degree - i -1)); }else if (poly[i] == -1 && ((degree - i ) == 1) && deriv && ((degree - i ) > 0)){ // Output the last turm in the diferential, if the lenght is 1 PrintPreX(deriv ? poly[i] * (degree - i -1) : poly[i], deriv ? (degree - i ) :(i == degree -1), !firstTurm, deriv); } } // Output a newline after the polynomial if fully outputed printf("\n"); }
// MAIN routine main( int argc, char **argv ) { // Elapsed times using <times()> clock_t clkStart; clock_t clkStop; // CPU times for the threads struct tms tStart; struct tms tStop; int k; int i; int j; int temp; double max; vFlag = 0; GetParam( argc, argv ); printf( "Starting timing ... computing ...\n" ); clkStart = times( &tStart ); long threadCounter; for( threadCounter = 0; threadCounter < M; threadCounter++ ) { thread_data_arry[ threadCounter ].i = 0; thread_data_arry[ threadCounter ].b = N; thread_data_arry[ threadCounter ].thread_id = threadCounter; printf( "\tmain: creating thread %ld\n", threadCounter ); int threadReturnCode = pthread_create( &idThreads[ threadCounter ], NULL, rowMcol, (void *) &thread_data_arry[ threadCounter ]); if( threadReturnCode ) { printf( "ERROR; return code from pthread_create() is %d\n", threadReturnCode ); exit( -1 ); } } printf( "\tcompleted thread creation ... going to try to join all threads!\n" ); // for loop processes until all threads terminate for( threadCounter = 0; threadCounter < M; threadCounter++ ) { pthread_join( idThreads[ threadCounter ], NULL ); } printf( "\tall threads have terminated!\n" ); clkStop = times( &tStop ); printf( "Stopped timing.\n" ); if( N < MAXN4print ) { PrintX(); } if( vFlag == 1 ) { CheckX(); } printf( "Elapsed time = %g ms.\n", (float)( clkStop - clkStart ) / (float) sysconf( _SC_CLK_TCK ) * 1000 ); printf( "The total CPU time comsumed = %g ms.\n", (float)(( tStop.tms_utime - tStart.tms_utime ) + ( tStop.tms_stime - tStart.tms_stime )) / (float)sysconf( _SC_CLK_TCK ) * 1000 ); // Last thing that main() should do pthread_exit( NULL ); return 0; }