int main (void) { #ifdef INIT init_weights(); #endif tbb::tick_count t0 = tbb::tick_count::now(); for (int c=0; c<TIMES; c++) { solution_weight = MAX_INT; solve_tsp(weights); } tbb::tick_count t1 = tbb::tick_count::now(); printf("Ticks = %f\n", (t1-t0).seconds()); printf("Solution Weight = %d\n", solution_weight); // Dump result hexdump_var("result.hex", &solution_weight, 1); #ifdef PRINT_RESULT printf("Solution weight = %d\n", solution_weight); int i; for(i=0;i<SIZE;i++) { printf("solution[%d] = %d\n", i, solution[i]); } #endif return 0; }
int main(void){ int i,j,k; tbb::tick_count t0 = tbb::tick_count::now(); for(i=0;i<SIZE_X;i++) { for(j=0; j<SIZE_Y; j++) { int sum=0; for(k=0;k<SIZE_Z;k++){ sum += (X[i][k]-5)*(Y[k][j]-5); } Z[i][j] = sum; } } tbb::tick_count t1 = tbb::tick_count::now(); printf("Ticks = %f\n", (t1-t0).seconds()); // Dump result hexdump_var("result.hex", (int*)Z, SIZE_X*SIZE_Z); #ifdef PRINT_RESULT //printf("Done!\n"); for(j=0;j<N;j++) { for(k=0;k<N;k++) { printf("%d,",Z[j][k]); } printf("\n"); } #endif return 0; }
int main(int argc, char* argv[]) { int nth=-1; // number of (hardware) threads (-1 means undefined) if (argc > 1) { //command line with parameters if (argc > 2) { printf("ERROR: wrong use of command line arguments. Usage %s <#threads>\n", argv[0]); return 1; } else { nth = atoi( argv[1] ); } } int defth = tbb::task_scheduler_init::default_num_threads(); if (nth<0) nth=defth; printf("Default #Threads=%d. Using %d threads\n", defth, nth); tbb::task_scheduler_init init(nth); int bound = IMAGESIDE - FILTERSIDE; PARTITIONER partitioner; tbb::tick_count t0 = tbb::tick_count::now(); for (int i=0; i<TIMES; i++) { tbb::parallel_for (tbb::blocked_range2d<int>(0,bound,OUTER_GRAINSIZE,0,bound,INNER_GRAINSIZE), convBody2D(), partitioner); } tbb::tick_count t1 = tbb::tick_count::now(); printf("Ticks = %f\n", (t1-t0).seconds()); // Dump result hexdump_var("result.hex", (int*)image3, IMAGESIDE*IMAGESIDE); #ifdef PRINT_RESULT int x,y; for(x=0; x<IMAGESIDE; x++) { for(y=0; y<IMAGESIDE; y++) { printf("%d,", image3[x][y]); } printf("\n"); } #endif return 0; }
int cilk_main(void) { int i; //solution = NULL; #ifdef DEBUG_VERBOSE threadCount = 0; printf ("addok_error : %d\n", addok_error); printf ("addok_error amount : %d\n", addok_error_amount); printf ("initial global_sp = %d\n", __xmt_global_sp); #endif tbb::tick_count t0 = tbb::tick_count::now(); #ifdef SENS_TIMES for (int st=0; st<SENS_TIMES; st++) { #endif for (int c=0; c<TIMES; c++) nqueens(); #ifdef SENS_TIMES } #endif tbb::tick_count t1 = tbb::tick_count::now(); printf("Ticks = %f\n", (t1-t0).seconds() ); int count = 0; // solution_count.get_value(); printf("NrSolutions = %d\n", count); // Dump result hexdump_var("result.hex", &count, 1); #ifdef DEBUG if (out_of_memory || addok_error) solution_count = -1; #endif #ifdef DEBUG_VERBOSE printf ("final global_sp = %d\n", __xmt_global_sp); //printf ("grLO: %d, grHI: %d\n"); printf ("addok_error : %d\n", addok_error); printf ("addok_error amount : %d\n", addok_error_amount); #endif #ifdef MEM_FOOTPRINT printf("Gl_SP=%d\n", __xmt_global_sp); #endif #ifdef PRINT_RESULT list_node *tmp = solution; if (tmp == NULL) printf ("No solution found\n"); else if (tmp == -2) printf ("solution not updated\n"); else if (tmp == -1) printf ("Ran out of memory to allocate\n"); else while (tmp!=NULL) { for(i=0;i<N;i++) { if (i==tmp->row) printf ("*"); else printf(" "); } printf("\n"); tmp = tmp->next; } #endif //PRINT_RESULT #ifdef CHECK_RESULT list_node *tmpP = solution; for(i=0;i<N && tmpP!=NULL;i++, tmpP=tmpP->next) { int row, column, diag1, diag2; row = tmpP->row; column = i; diag1 = row+column; diag2 = N + row - column - 1; //printf("Setting rowAr[%d] to %d\n", row, rowAr[row]+1); rowAr[row]++; columnAr[column]++; diagonal1Ar[diag1]++; diagonal2Ar[diag2]++; } printf("i=%d\n", i ); printf("Rows with incorrect number of queens:"); for(i=0; i<N; i++) { if (rowAr[i]!=1) printf("%d=%d,", i,rowAr[i]); } printf("\n"); printf("Columns with incorrect number of queens:"); for(i=0; i<N; i++) { if (columnAr[i]!=1) printf("%d,", i); } printf("\n"); printf("Diagonal1 with more than 1 queens:"); for(i=0;i<2*N-1; i++) { if(diagonal1Ar[i] > 1) printf("%d,", i); } printf("\n"); printf("Diagonal2 with more than 1 queens:"); for(i=0;i<2*N-1; i++) { if(diagonal2Ar[i] > 1) printf("%d,", i); } printf("\n"); #endif // CHECK_RESULT return 0; }
int main(int argc, char* argv[]) { int nth=-1; // number of (hardware) threads (-1 means undefined) if (argc > 1) { //command line with parameters if (argc > 2) { printf("ERROR: wrong use of command line arguments. Usage %s <#threads>\n", argv[0]); return 1; } else { nth = atoi( argv[1] ); } } int defth = tbb::task_scheduler_init::default_num_threads(); if (nth<0) nth=defth; printf("Default #Threads=%d. Using %d threads\n", defth, nth); tbb::task_scheduler_init init(nth); int i; //solution = NULL; #ifdef DEBUG_VERBOSE threadCount = 0; printf ("addok_error : %d\n", addok_error); printf ("addok_error amount : %d\n", addok_error_amount); printf ("initial global_sp = %d\n", __xmt_global_sp); #endif tbb::tick_count t0 = tbb::tick_count::now(); #ifdef SENS_TIMES for (int st=0; st<SENS_TIMES; st++) { #endif for (int c=0; c<TIMES; c++) nqueens(); #ifdef SENS_TIMES } #endif tbb::tick_count t1 = tbb::tick_count::now(); int count = solution_count; printf("Ticks = %f\n", (t1-t0).seconds() ); printf("NrSolutions = %d\n", count); // Dump result hexdump_var("result.hex", &count, 1); #ifdef DEBUG if (out_of_memory || addok_error) solution_count = -1; #endif #ifdef DEBUG_VERBOSE printf ("addok_error : %d\n", addok_error); printf ("addok_error amount : %d\n", addok_error_amount); #endif #ifdef PRINT_RESULT /*list_node *tmp = solution; if (tmp == NULL) printf ("No solution found\n"); else if (tmp == -2) printf ("solution not updated\n"); else if (tmp == -1) printf ("Ran out of memory to allocate\n"); else while (tmp!=NULL) { for(i=0;i<SIZE;i++) { if (i==tmp->row) printf ("*"); else printf(" "); } printf("\n"); tmp = tmp->next; }*/ #endif //PRINT_RESULT #ifdef CHECK_RESULT /*list_node *tmpP = solution; for(i=0;i<SIZE && tmpP!=SIZEULL;i++, tmpP=tmpP->next) { int row, column, diag1, diag2; row = tmpP->row; column = i; diag1 = row+column; diag2 = SIZE + row - column - 1; //printf("Setting rowAr[%d] to %d\n", row, rowAr[row]+1); rowAr[row]++; columnAr[column]++; diagonal1Ar[diag1]++; diagonal2Ar[diag2]++; } printf("i=%d\n", i ); printf("Rows with incorrect number of queens:"); for(i=0; i<SIZE; i++) { if (rowAr[i]!=1) printf("%d=%d,", i,rowAr[i]); } printf("\n"); printf("Columns with incorrect number of queens:"); for(i=0; i<SIZE; i++) { if (columnAr[i]!=1) printf("%d,", i); } printf("\n"); printf("Diagonal1 with more than 1 queens:"); for(i=0;i<2*SIZE-1; i++) { if(diagonal1Ar[i] > 1) printf("%d,", i); } printf("\n"); printf("Diagonal2 with more than 1 queens:"); for(i=0;i<2*SIZE-1; i++) { if(diagonal2Ar[i] > 1) printf("%d,", i); } printf("\n"); */ #endif // CHECK_RESULT return 0; }
int main(int argc, char* argv[]) { int nth=-1; // number of (hardware) threads (-1 means undefined) if (argc > 1) { //command line with parameters if (argc > 2) { printf("ERROR: wrong use of command line arguments. Usage %s <#threads>\n", argv[0]); return 1; } else { nth = atoi( argv[1] ); } } int defth = tbb::task_scheduler_init::default_num_threads(); if (nth<0) nth=defth; printf("Default #Threads=%d. Using %d threads\n", defth, nth); readBFSInputs(); tbb::task_scheduler_init init(nth); tbb::tick_count t0 = tbb::tick_count::now(); int ii = 0; for (ii=0; ii<TIMES; ii++) { int nodesLeft = VSIZE; currentLevel = 0; currentLevelSize = 1; currentLevelSet = mytempC; newLevelSet = mytempB; currentLevelSet[0] = START; // store the vertex# this thread will handle level[START] = 0; // the level of the START node is 0 gatekeeper[START] = 1; // set the gatekeeper of the START node PARTITIONER partitioner; while (currentLevelSize>0) { //printf("New level=%d, levelSize=%d, remaining Nodes=%d\n", currentLevel, currentLevelSize, nodesLeft); newLevelIndex = 0; //printf("Lvl:%d, lvlSize=%d\n", currentLevel, currentLevelSize); tbb::parallel_for (tbb::blocked_range<int>(0, currentLevelSize, OUTER_GRAINSIZE), outerLoopBody(), partitioner); // move to next layer currentLevel++; currentLevelSize = newLevelIndex; // from the prefix-sums nodesLeft -= currentLevelSize; // "swap" currentLevelSet with newLevelSet tmpSet = newLevelSet; newLevelSet = currentLevelSet; currentLevelSet = tmpSet; //if (currentLevel >= 5) break; } // end while } // end for ii<TIMES tbb::tick_count t1 = tbb::tick_count::now(); printf("Ticks = %f\n", (t1-t0).seconds()); printf("current level = %d\n", currentLevel); // Dump result hexdump_var("result.hex", level, VSIZE); #ifdef PRINT_RESULT printf("Levels:\n"); for (ii=0;ii<vertices_dim0_size;ii++) { printf("Node %d at level %d \n",ii,level[ii]); } #endif }
int main(int argc, char* argv[]) { int nth=-1; // number of (hardware) threads (-1 means undefined) if (argc > 1) { //command line with parameters if (argc > 2) { printf("ERROR: wrong use of command line arguments. Usage %s <#threads>\n", argv[0]); return 1; } else { nth = atoi( argv[1] ); } } int defth = tbb::task_scheduler_init::default_num_threads(); if (nth<0) nth=defth; printf("Default #Threads=%d. Using %d threads\n", defth, nth); tbb::task_scheduler_init init(nth); // init lock #ifdef DEBUG_VERBOSE printf("test1\n"); #endif #ifdef INIT init_weights(); #endif #ifdef DEBUG_VERBOSE printf("release_failed = %d\n", release_failed); printf("out_of_memory = %d\n", out_of_memory); printf("test2\n"); #endif tbb::tick_count t0 = tbb::tick_count::now(); solution_weight = MAX_INT; solve_tsp(weights); #ifdef NO_LOCKS //FunctorMin<int> my_min; solution_weight = my_weight.combine (min); #endif tbb::tick_count t1 = tbb::tick_count::now(); printf("Ticks = %f\n", (t1-t0).seconds()); printf("Solution Weight = %d\n", solution_weight); // Dump result int solution = solution_weight; hexdump_var("result.hex", &solution, 1); #ifdef DEBUG_VERBOSE printf("release_failed = %d\n", release_failed); printf("out_of_memory = %d\n", out_of_memory); #endif #ifdef DEBUG // if there is an error invalidate solution_weight if (release_failed || out_of_memory) solution_weight = -1; #endif #ifdef PRINT_RESULT printf("Solution weight = %d\n", solution_weight); list_node* tmp_p = solution; int i=SIZE; while(tmp_p != NULL && i!=0) { i--; printf("solution[%d] = %d\n", i, tmp_p->val); tmp_p = tmp_p->next; } #endif return 0; }