Changeset 625 for trunk/user/sort
- Timestamp:
- Apr 10, 2019, 10:09:39 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/sort/sort.c
r624 r625 29 29 #include <hal_macros.h> 30 30 31 #define ARRAY_LENGTH 1024// number of items31 #define ARRAY_LENGTH 256 // number of items 32 32 #define MAX_THREADS 1024 // 16 * 16 * 4 33 33 … … 412 412 #endif 413 413 414 #if CHECK_RESULT 415 int success = 1; 416 int* res_array = ( (total_threads == 2) || 417 (total_threads == 8) || 418 (total_threads == 32) || 419 (total_threads == 128) || 420 (total_threads == 512) ) ? array1 : array0; 421 422 for( n=0 ; n<(ARRAY_LENGTH-2) ; n++ ) 423 { 424 if ( res_array[n] > res_array[n+1] ) 425 { 426 printf("\n[sort] array[%d] = %d > array[%d] = %d\n", 427 n , res_array[n] , n+1 , res_array[n+1] ); 428 success = 0; 429 break; 430 } 431 } 432 433 if ( success ) printf("\n[sort] success\n"); 434 else printf("\n[sort] failure\n"); 414 #if CHECK_RESULT 415 416 int success = 1; 417 int * res_array = ( (total_threads == 2) || 418 (total_threads == 8) || 419 (total_threads == 32) || 420 (total_threads == 128) || 421 (total_threads == 512) ) ? array1 : array0; 422 423 for( n=0 ; n<(ARRAY_LENGTH-2) ; n++ ) 424 { 425 if ( res_array[n] > res_array[n+1] ) 426 { 427 printf("\n[sort] array[%d] = %d > array[%d] = %d\n", 428 n , res_array[n] , n+1 , res_array[n+1] ); 429 success = 0; 430 break; 431 } 432 } 433 434 if ( success ) printf("\n[sort] success\n"); 435 else printf("\n[sort] failure\n"); 436 435 437 #endif 436 438 437 439 #if INSTRUMENTATION 438 char name[64]; 439 char path[128]; 440 441 // build a file name from n_items / n_clusters / n_cores 442 if( USE_DQT_BARRIER ) snprintf( name , 64 , "sort_dqt_%d_%d_%d", 443 ARRAY_LENGTH, x_size * y_size, ncores ); 444 else snprintf( name , 64 , "sort_smp_%d_%d_%d", 445 ARRAY_LENGTH, x_size * y_size, ncores ); 446 447 // build file pathname 448 snprintf( path , 128 , "home/%s" , name ); 449 450 // compute results 451 unsigned int sequencial = (unsigned int)(seq_end_cycle - start_cycle); 452 unsigned int parallel = (unsigned int)(para_end_cycle - seq_end_cycle); 453 454 // display results on process terminal 455 printf("\n----- %s -----\n" 456 " - sequencial : %d cycles\n" 457 " - parallel : %d cycles\n", 458 name, sequencial, parallel ); 459 460 // open file 461 FILE * stream = fopen( path , NULL ); 462 if( stream == NULL ) 463 { 464 printf("\n[sort error] cannot open instrumentation file <%s>\n", name ); 465 exit(0); 466 } 467 468 // register results to file 469 int ret = fprintf( stream , "\n----- %s -----\n" 470 " - sequencial : %d cycles\n" 471 " - parallel : %d cycles\n", name, sequencial, parallel ); 472 if( ret < 0 ) 473 { 474 printf("\n[sort error] cannot write to instrumentation file <%s>\n", name ); 475 exit(0); 476 } 477 478 // close instrumentation file 479 if( fclose( stream ) ) 480 { 481 printf("\n[sort error] cannot close instrumentation file <%s>\n", name ); 482 exit(0); 483 } 440 441 char name[64]; 442 char path[128]; 443 444 // build a file name from n_items / n_clusters / n_cores 445 if( USE_DQT_BARRIER ) snprintf( name , 64 , "sort_dqt_%d_%d_%d", 446 ARRAY_LENGTH, x_size * y_size, ncores ); 447 else snprintf( name , 64 , "sort_smp_%d_%d_%d", 448 ARRAY_LENGTH, x_size * y_size, ncores ); 449 450 // build file pathname 451 snprintf( path , 128 , "home/%s" , name ); 452 453 // compute results 454 unsigned int sequencial = (unsigned int)(seq_end_cycle - start_cycle); 455 unsigned int parallel = (unsigned int)(para_end_cycle - seq_end_cycle); 456 457 // display results on process terminal 458 printf("\n----- %s -----\n" 459 " - sequencial : %d cycles\n" 460 " - parallel : %d cycles\n", 461 name, sequencial, parallel ); 462 463 // open file 464 FILE * stream = fopen( path , NULL ); 465 if( stream == NULL ) 466 { 467 printf("\n[sort error] cannot open instrumentation file <%s>\n", name ); 468 exit(0); 469 } 470 471 printf("\n[sort] file %s successfully open\n", path); 472 473 // register results to file 474 int ret = fprintf( stream , "\n----- %s -----\n" 475 " - sequencial : %d cycles\n" 476 " - parallel : %d cycles\n", name, sequencial, parallel ); 477 if( ret < 0 ) 478 { 479 printf("\n[sort error] cannot write to instrumentation file <%s>\n", name ); 480 exit(0); 481 } 482 483 printf("\n[sort] file %s successfully written\n", path); 484 485 // close instrumentation file 486 487 if( fclose( stream ) ) 488 { 489 printf("\n[sort error] cannot close the file <%s>\n", name ); 490 exit(0); 491 } 492 493 printf("\n[sort] file %s successfully closed\n", path); 494 484 495 #endif 485 496
Note: See TracChangeset
for help on using the changeset viewer.