static void TimeRoutine2(Routine2 r, const char* what) { // First call is used to choose how many iterations to time. static int TrialCount; bool firstCall = TrialCount==0; static double tBase; double t; T x[nMax]; T y[nMax]; T z[2*nMax]; GLT_ult *ults; glt_args * args; FillRandom(x,nMax); FillRandom(y,nMax); if (firstCall) TrialCount=1; for(;;) { printf("En Starttime2 %d numero de counts %d\n", glt_get_thread_num(),TrialCount); unsigned long long t0 = cilk_getticks(); ults = glt_ult_malloc(TrialCount); args = (glt_args *)malloc(sizeof(glt_args)*TrialCount); for (int i=0; i<TrialCount; ++i){ //(*r)(z,x,y,nMax); args[i].z=z; args[i].x=x; args[i].y=y; args[i].nMax=nMax; glt_ult_creation_to(r,(void*)&args[i],&ults[i],0); } glt_yield(); for (int i=0; i<TrialCount; ++i){ glt_ult_join(&ults[i]); } unsigned long long t1 = cilk_getticks(); free(ults); free (args); t = cilk_ticks_to_seconds(t1-t0); if (!firstCall || (t>=MinTime)) break; // Double the number of iterations TrialCount*=2; } if (firstCall) { // Print table caption and heading printf("Timing %d multiplications of %lu-degree polynomials\n\n",TrialCount,(unsigned long)nMax); printf("%20s %s %s\n","Version","Time", "Speedup"); tBase = t; } std::printf("%20s %6.3f %5.2f x\n",what,t,tBase/t); }
int main(int argc, char** argv) { // Create random input matrices. Override the default size with argv[1] // Warning: Matrix indexing is 0 based. int nn = DEFAULT_MATRIX_SIZE; if (argc > 1) { nn = std::atoi(argv[1]); } std::cout << "Simple algorithm: Multiply two " << nn << " by " << nn << " matrices, computing A = B*C" << std::endl; double* A = (double*) calloc(nn* nn, sizeof(double)); double* B = (double*) calloc(nn* nn, sizeof(double)); double* C = (double*) calloc(nn* nn, sizeof(double)); if (NULL == A || NULL == B || NULL == C) { std::cout << "Fatal Error. Cannot allocate matrices A, B, and C." << std::endl; return 1; } // Populate B and C pseudo-randomly - // The matrices are populated with random numbers in the range (-1.0, +1.0) cilk_for(int i = 0; i < nn * nn; ++i) { B[i] = (float) ((i * i) % 1024 - 512) / 512; } cilk_for(int i = 0; i < nn * nn; ++i) { C[i] = (float) (((i + 1) * i) % 1024 - 512) / 512; } // Multiply to get A = B*C unsigned long long start_tick, end_tick; long elapsed_milliseconds; start_tick = cilk_getticks(); matrix_multiply(A, B, C, (unsigned int)nn); end_tick = cilk_getticks(); float par_time = cilk_ticks_to_seconds(end_tick - start_tick); // (end_tick - start_tick) / 1000.0F; std::cout << " Matrix Multiply took " << par_time << " seconds." << std::endl; // If n is small, print the results if (nn <= 8) { std::cout << "Matrix A:" << std::endl; print_matrix(B, nn); std::cout << std::endl << "Matrix B:" << std::endl; print_matrix(C, nn); std::cout << std::endl << "Matrix C = A * B:" << std::endl; print_matrix(A, nn); } free(A); free(B); free(C); return 0; }