Changeset 623 for trunk/user
- Timestamp:
- Mar 6, 2019, 4:37:15 PM (6 years ago)
- Location:
- trunk/user
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/init/init.c
r588 r623 26 26 // and avoid the hard_config include [AG] 27 27 28 // TODO introduce a communication channel between INIT and KSH29 // to allow KSH to signal INIT the exec completion.30 31 28 //////////////// 32 29 int main( void ) … … 40 37 41 38 #if DEBUG_PROCESS_INIT 42 display_string("[ INIT] process enters");39 display_string("[init] process enters"); 43 40 #endif 44 41 … … 59 56 { 60 57 // INIT display error message 61 snprintf( string , 64 , "[ INITERROR] cannot fork child[%d] => suicide" , i );58 snprintf( string , 64 , "[init ERROR] cannot fork child[%d] => suicide" , i ); 62 59 display_string( string ); 63 60 … … 74 71 // CHILD[i] display error message 75 72 snprintf( string , 64 , 76 "[ INITERROR] CHILD[%d] cannot exec KSH / ret_exec = %d" , i , ret_exec );73 "[init ERROR] CHILD[%d] cannot exec KSH / ret_exec = %d" , i , ret_exec ); 77 74 display_string( string ); 78 75 } … … 81 78 { 82 79 // INIT display CHILD[i] process PID 83 snprintf( string , 64 , "[ INIT] created KSH[%d] / pid = %x", i , ret_fork );80 snprintf( string , 64 , "[init] created KSH[%d] / pid = %x", i , ret_fork ); 84 81 display_string( string ); 85 82 … … 128 125 { 129 126 // display string to report unexpected KSH process block 130 snprintf( string , 64 , "[ INIT] KSH process %x stopped => unblock it" , rcv_pid );127 snprintf( string , 64 , "[init] KSH process %x stopped => unblock it" , rcv_pid ); 131 128 display_string( string ); 132 129 … … 138 135 { 139 136 // display string to report KSH process termination 140 snprintf( string , 64 , "[ INIT] KSH process %x terminated => recreate", rcv_pid );137 snprintf( string , 64 , "[init] KSH process %x terminated => recreate", rcv_pid ); 141 138 display_string( string ); 142 139 … … 147 144 { 148 145 // INIT display error message 149 snprintf( string , 64 , "[ INITERROR] cannot fork child => suicide");146 snprintf( string , 64 , "[init ERROR] cannot fork child => suicide"); 150 147 display_string( string ); 151 148 … … 161 158 { 162 159 // CHILD display error message on TXT0 terminal 163 snprintf( string , 64 , "[ INITERROR] CHILD cannot exec KSH" );160 snprintf( string , 64 , "[init ERROR] CHILD cannot exec KSH" ); 164 161 display_string( string ); 165 162 } … … 168 165 { 169 166 // INIT display new KSH process PID 170 snprintf( string , 64 , "[ INIT] re-created KSH / pid = %x", ret_fork );167 snprintf( string , 64 , "[init] re-created KSH / pid = %x", ret_fork ); 171 168 display_string( string ); 172 169 } -
trunk/user/ksh/ksh.c
r619 r623 58 58 #define DEBUG_INTER 0 59 59 #define DEBUG_PARSE 0 60 #define DEBUG_CMD_CAT 060 #define DEBUG_CMD_CAT 1 61 61 #define DEBUG_CMD_CP 0 62 62 #define DEBUG_CMD_LOAD 0 … … 122 122 if (argc != 2) 123 123 { 124 fd = -1;125 buf = NULL;126 size = 0;127 124 printf(" usage: cat pathname\n"); 128 goto cmd_cat_exit; 125 126 sem_post( &semaphore ); 127 return; 129 128 } 130 129 … … 135 134 if (fd < 0) 136 135 { 137 buf = NULL;138 size = 0;139 136 printf(" error: cannot open file <%s>\n", path); 140 goto cmd_cat_exit; 137 138 sem_post( &semaphore ); 139 return; 141 140 } 142 141 143 142 #if DEBUG_CMD_CAT 144 snprintf( string , 64 , "[ KSH] %s : file %s open", __FUNCTION__, path );143 snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, path ); 145 144 display_string( string ); 146 145 #endif … … 149 148 if ( stat( path , &st ) == -1) 150 149 { 151 buf = NULL;152 size = 0;153 150 printf(" error: cannot stat <%s>\n", path); 154 goto cmd_cat_exit; 151 152 close(fd); 153 sem_post( &semaphore ); 154 return; 155 155 } 156 156 157 157 if ( S_ISDIR(st.st_mode) ) 158 158 { 159 buf = NULL;160 size = 0;161 159 printf(" error: <%s> is a directory\n", path); 162 goto cmd_cat_exit; 160 161 close(fd); 162 sem_post( &semaphore ); 163 return; 163 164 } 164 165 … … 167 168 168 169 #if DEBUG_CMD_CAT 169 snprintf( string , 64 , "[KSH] %s : get size = %d", __FUNCTION__, size ); 170 display_string( string ); 171 #endif 172 173 // MAP_FILE is default type when MAP_ANON and MAP_REMOTE are not specified 170 snprintf( string , 64 , "[ksh] %s : size = %d", __FUNCTION__, size ); 171 display_string( string ); 172 #endif 173 174 if( size == 0 ) 175 { 176 printf(" error: size = 0 for <%s>\n", path); 177 178 close(fd); 179 sem_post( &semaphore ); 180 return; 181 } 182 183 // mapping type is MAP_FILE when MAP_ANON and MAP_REMOTE are not specified 174 184 buf = mmap( NULL , size , PROT_READ|PROT_WRITE , MAP_PRIVATE , fd , 0 ); 175 185 … … 177 187 { 178 188 printf(" error: cannot map file <%s>\n", path ); 179 goto cmd_cat_exit; 189 190 close(fd); 191 sem_post( &semaphore ); 192 return; 180 193 } 181 194 182 195 #if DEBUG_CMD_CAT 183 snprintf( string , 64 , "[KSH] %s : map file %d to buffer %x", __FUNCTION__, fd , buf ); 184 display_string( string ); 185 display_vmm( 0 , getpid() ); 196 snprintf( string , 64 , "[ksh] %s : maped file %d to buffer %x", __FUNCTION__, fd , buf ); 197 display_string( string ); 198 // unsigned int pid = getpid(); 199 // unsigned int cxy = pid >> 16; 200 // display_vmm( cxy , pid ); 186 201 #endif 187 202 … … 189 204 write( 1 , buf , size ); 190 205 191 // release semaphore to get next command 192 sem_post( &semaphore ); 193 194 return; 195 196 cmd_cat_exit: 197 198 if (buf != NULL) munmap(buf, size); 199 if (fd >= 0) close(fd); 206 // unmap te file 207 if( munmap( buf , size ) ) 208 { 209 printf(" error: cannot unmap file <%s>\n", path ); 210 } 211 212 #if DEBUG_CMD_CAT 213 snprintf( string , 64 , "[ksh] %s : unmaped file %d from buffer %x", __FUNCTION__, fd , buf ); 214 display_string( string ); 215 // display_vmm( cxy , pid ); 216 #endif 217 218 // close the file 219 if( close( fd ) ) 220 { 221 printf(" error: cannot close file <%s>\n", path ); 222 } 200 223 201 224 // release semaphore to get next command … … 267 290 268 291 #if DEBUG_CMD_CP 269 snprintf( string , 64 , "[ KSH] %s : file %s open", __FUNCTION__, srcpath );292 snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, srcpath ); 270 293 display_string( string ); 271 294 #endif … … 280 303 281 304 #if DEBUG_CMD_CP 282 snprintf( string , 64 , "[ KSH] %s : got stats for %s", __FUNCTION__, srcpath );305 snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, srcpath ); 283 306 display_string( string ); 284 307 #endif … … 304 327 305 328 #if DEBUG_CMD_CP 306 snprintf( string , 64 , "[ KSH] %s : file %s open", __FUNCTION__, dstpath );329 snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, dstpath ); 307 330 display_string( string ); 308 331 #endif … … 315 338 316 339 #if DEBUG_CMD_CP 317 snprintf( string , 64 , "[ KSH] %s : got stats for %s", __FUNCTION__, dstpath );340 snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, dstpath ); 318 341 display_string( string ); 319 342 #endif … … 339 362 340 363 #if DEBUG_CMD_CP 341 snprintf( string , 64 , "[ KSH] %s : read %d bytes from %s", __FUNCTION__, len, srcpath );364 snprintf( string , 64 , "[ksh] %s : read %d bytes from %s", __FUNCTION__, len, srcpath ); 342 365 display_string( string ); 343 366 #endif … … 351 374 352 375 #if DEBUG_CMD_CP 353 snprintf( string , 64 , "[ KSH] %s : write %d bytes to %s", __FUNCTION__, len, dstpath );376 snprintf( string , 64 , "[ksh] %s : write %d bytes to %s", __FUNCTION__, len, dstpath ); 354 377 display_string( string ); 355 378 #endif … … 381 404 " display dqdt\n" 382 405 " display locks pid trdid\n" 406 " display barrier pid\n" 383 407 " display mapper path page_id nbytes\n"); 384 408 } … … 504 528 { 505 529 printf(" error: illegal arguments pid = %x / trdid = %x\n", pid, trdid ); 530 } 531 } 532 } 533 ///////////////////////////////////////////////// 534 else if( strcmp( argv[1] , "barrier" ) == 0 ) 535 { 536 if( argc != 3 ) 537 { 538 printf(" usage: display barrier pid\n"); 539 } 540 else 541 { 542 unsigned int pid = atoi(argv[2]); 543 544 if( display_barrier( pid ) ) 545 { 546 printf(" error: illegal arguments pid = %x\n", pid ); 506 547 } 507 548 } … … 678 719 679 720 #if DEBUG_CMD_LOAD 680 snprintf( string , 64 , "[ KSH] %s : ksh_pid %x / path %s / bg %d / place %d (%x)\n",721 snprintf( string , 64 , "[ksh] %s : ksh_pid %x / path %s / bg %d / place %d (%x)\n", 681 722 __FUNCTION__, ksh_pid, argv[1], background, placement, cxy ); 682 723 display_string( string ); … … 697 738 698 739 #if DEBUG_CMD_LOAD 699 snprintf( string , 64 , "[ KSH] %s : child_pid %x after fork, before exec\n",740 snprintf( string , 64 , "[ksh] %s : child_pid %x after fork, before exec\n", 700 741 __FUNCTION__ , getpid() ); 701 742 display_string( string ); … … 706 747 707 748 #if DEBUG_CMD_LOAD 708 snprintf( string , 64 , "[ KSH] %s : child_pid %x after exec / ret_exec %x\n",749 snprintf( string , 64 , "[ksh] %s : child_pid %x after exec / ret_exec %x\n", 709 750 __FUNCTION__ , getpid(), ret_exec ); 710 751 display_string( string ); … … 722 763 723 764 #if DEBUG_CMD_LOAD 724 snprintf( string , 64 , "[ KSH] %s : ksh_pid %x after fork / ret_fork %x\n",765 snprintf( string , 64 , "[ksh] %s : ksh_pid %x after fork / ret_fork %x\n", 725 766 __FUNCTION__, getpid(), ret_fork ); 726 767 display_string( string ); … … 795 836 796 837 #if DEBUG_CMD_LS 797 snprintf( string , 64 , "[ KSH] %s : directory <%s> open / DIR %x\n",838 snprintf( string , 64 , "[ksh] %s : directory <%s> open / DIR %x\n", 798 839 __FUNCTION__, pathname , dir ); 799 840 display_string( string ); … … 803 844 { 804 845 printf(" error : directory <%s> not found\n", pathname ); 805 goto cmd_ls_exit; 846 847 sem_post( &semaphore ); 848 return; 806 849 } 807 850 … … 816 859 817 860 #if DEBUG_CMD_LS 818 snprintf( string , 64 , "[ KSH] %s : directory <%s> closed\n",861 snprintf( string , 64 , "[ksh] %s : directory <%s> closed\n", 819 862 __FUNCTION__, pathname ); 820 863 display_string( string ); … … 822 865 823 866 } 824 825 cmd_ls_exit:826 867 827 868 // release semaphore to get next command … … 908 949 909 950 #if DEBUG_CMD_PS 910 snprintf( string , 64 , "\n[ KSH] %s : call display_cluster_process()", __FUNCTION__ );951 snprintf( string , 64 , "\n[ksh] %s : call display_cluster_process()", __FUNCTION__ ); 911 952 display_string( string ); 912 953 #endif … … 1071 1112 #if DEBUG_PARSE 1072 1113 char string[64]; 1073 snprintf( string , 64 , "\n[ KSH] %s : <%s>", __FUNCTION__ , buf );1114 snprintf( string , 64 , "\n[ksh] %s : <%s>", __FUNCTION__ , buf ); 1074 1115 display_string( string ); 1075 1116 #endif … … 1094 1135 1095 1136 #if DEBUG_PARSE 1096 snprintf( string , 64 , "\n[ KSH] %s : argc = %d for <%s>", __FUNCTION__ , argc , argv[0] );1137 snprintf( string , 64 , "\n[ksh] %s : argc = %d for <%s>", __FUNCTION__ , argc , argv[0] ); 1097 1138 display_string( string ); 1098 1139 #endif … … 1193 1234 #if DEBUG_INTER 1194 1235 unsigned int pid = getpid(); 1195 snprintf( string , 64 , "\n[ KSH] %s : request a new command", __FUNCTION__ );1236 snprintf( string , 64 , "\n[ksh] %s : request a new command", __FUNCTION__ ); 1196 1237 display_string( string ); 1197 1238 #endif … … 1230 1271 1231 1272 #if DEBUG_INTER 1232 snprintf( string , 64 , "[ KSH] %s : parse and execute <%s>", __FUNCTION__, cmd );1273 snprintf( string , 64 , "[ksh] %s : parse and execute <%s>", __FUNCTION__, cmd ); 1233 1274 display_string( string ); 1234 1275 #endif … … 1350 1391 1351 1392 #if DEBUG_INTER 1352 snprintf( string , 64 , "\n[ KSH] %s : complete <%s> command", __FUNCTION__, cmd );1393 snprintf( string , 64 , "\n[ksh] %s : complete <%s> command", __FUNCTION__, cmd ); 1353 1394 display_string( string ); 1354 1395 #endif -
trunk/user/sort/sort.c
r619 r623 29 29 #include <hal_macros.h> 30 30 31 #define ARRAY_LENGTH 256 // number of values31 #define ARRAY_LENGTH 1024 // number of items 32 32 #define MAX_THREADS 1024 // 16 * 16 * 4 33 #define USE_DQT_BARRIER 1 34 #define DISPLAY_ARRAY 0 35 #define INTERACTIVE_MODE 0 33 34 #define USE_DQT_BARRIER 1 // use DQT barrier if non zero 35 #define DISPLAY_ARRAY 0 // display items values before and after 36 #define VERBOSE 0 // for debug 37 #define INTERACTIVE_MODE 0 // for debug 38 #define CHECK_RESULT 0 // for debug 39 #define INSTRUMENTATION 1 // register computation times on file 36 40 37 41 ///////////////////////////////////////////////////////////// … … 84 88 85 89 /////////////////////////////////// 86 static void merge( const int * src, 87 int * dst, 88 int length, 89 int init_pos_src_a, 90 int init_pos_src_b, 91 int init_pos_dst ) 90 static void merge( const int * src, // source array 91 int * dst, // destination array 92 int length, // number of items in a subset 93 int init_pos_src_a, // index first item in src subset A 94 int init_pos_src_b, // index first item in src subset B 95 int init_pos_dst ) // index first item in destination 92 96 { 93 97 int i; … … 135 139 unsigned int lid; 136 140 137 int * src_array = NULL;138 int * dst_array = NULL;141 int * src_array = NULL; 142 int * dst_array = NULL; 139 143 140 144 // get core coordinates an date … … 146 150 unsigned int main_uid = ptr->main_uid; 147 151 152 #if DISPLAY_ARRAY 153 unsigned int n; 154 if( thread_uid == main_uid ) 155 { 156 printf("\n*** array before sort\n"); 157 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , array0[n] ); 158 } 159 #endif 160 161 ///////////////////////////////// 162 pthread_barrier_wait( &barrier ); 163 164 #if VERBOSE 165 printf("\n[sort] thread[%d] exit barrier 0\n", thread_uid ); 166 #endif 167 148 168 unsigned int items = ARRAY_LENGTH / threads; 149 169 unsigned int stages = __builtin_ctz( threads ) + 1; 150 170 151 printf("\n[SORT] thread[%d] : start\n", thread_uid ); 171 #if VERBOSE 172 printf("\n[sort] thread[%d] : start\n", thread_uid ); 173 #endif 152 174 153 175 bubbleSort( array0, items, items * thread_uid ); 154 176 155 printf("\n[SORT] thread[%d] : stage 0 completed\n", thread_uid ); 177 #if VERBOSE 178 printf("\n[sort] thread[%d] : stage 0 completed\n", thread_uid ); 179 #endif 156 180 157 181 ///////////////////////////////// 158 182 pthread_barrier_wait( &barrier ); 159 printf("\n[SORT] thread[%d] exit barrier 0\n", thread_uid ); 160 161 // the number of threads contributing to sort 162 // is divided by 2 at each next stage 183 184 #if VERBOSE 185 printf("\n[sort] thread[%d] exit barrier 0\n", thread_uid ); 186 #endif 187 188 #if DISPLAY_ARRAY 189 if( thread_uid == main_uid ) 190 { 191 printf("\n*** array after bubble sort\n"); 192 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , array0[n] ); 193 } 194 #endif 195 196 // the number of threads contributing to sort is divided by 2 197 // and the number of items is multiplied by 2 at each next stage 163 198 for ( i = 1 ; i < stages ; i++ ) 164 199 { 165 pthread_barrier_wait( &barrier ); 200 if((i % 2) == 1) // odd stage 201 { 202 src_array = array0; 203 dst_array = array1; 204 } 205 else // even stage 206 { 207 src_array = array1; 208 dst_array = array0; 209 } 166 210 167 211 if( (thread_uid & ((1<<i)-1)) == 0 ) 168 212 { 169 printf("\n[SORT] thread[%d] : stage %d start\n", thread_uid , i ); 170 171 if((i % 2) == 1) // odd stage 172 { 173 src_array = array0; 174 dst_array = array1; 175 } 176 else // even stage 177 { 178 src_array = array1; 179 dst_array = array0; 180 } 181 213 214 #if VERBOSE 215 printf("\n[sort] thread[%d] : stage %d start\n", thread_uid , i ); 216 #endif 182 217 merge( src_array, 183 218 dst_array, 184 items << i,219 items << (i-1), 185 220 items * thread_uid, 186 221 items * (thread_uid + (1 << (i-1))), 187 222 items * thread_uid ); 188 223 189 printf("\n[SORT] thread[%d] : stage %d completed\n", thread_uid , i ); 224 #if VERBOSE 225 printf("\n[sort] thread[%d] : stage %d completed\n", thread_uid , i ); 226 #endif 190 227 } 191 228 192 229 ///////////////////////////////// 193 230 pthread_barrier_wait( &barrier ); 194 printf("\n[SORT] thread[%d] exit barrier %d\n", thread_uid , i ); 195 196 } 231 232 #if VERBOSE 233 printf("\n[sort] thread[%d] exit barrier %d\n", thread_uid , i ); 234 #endif 235 236 #if DISPLAY_ARRAY 237 if( thread_uid == main_uid ) 238 { 239 printf("\n*** array after merge %d\n", i ); 240 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , dst_array[n] ); 241 } 242 #endif 243 244 } // en for stages 197 245 198 246 // all threads but the main thread exit … … 220 268 unsigned int lid; // core local index for a thread 221 269 unsigned int n; // index in array to sort 222 unsigned long long cycle; // current date for log223 270 pthread_t trdid; // kernel allocated thread index (unused) 224 271 pthread_barrierattr_t barrier_attr; // barrier attributes 225 272 273 unsigned long long start_cycle; 274 unsigned long long seq_end_cycle; 275 unsigned long long para_end_cycle; 276 277 ///////////////////////// 278 get_cycle( &start_cycle ); 279 226 280 // compute number of threads (one thread per core) 227 281 get_config( &x_size , &y_size , &ncores ); … … 240 294 (total_threads != 512) && (total_threads != 1024) ) 241 295 { 242 printf("\n[ SORT ERROR] number of cores must be power of 2\n");296 printf("\n[sort error] number of cores must be power of 2\n"); 243 297 exit( 0 ); 244 298 } … … 247 301 if ( ARRAY_LENGTH % total_threads) 248 302 { 249 printf("\n[ SORT ERROR] array size must be multiple of number of threads\n");303 printf("\n[sort error] array size must be multiple of number of threads\n"); 250 304 exit( 0 ); 251 305 } 252 306 253 printf("\n\n[ SORT] main starts on core[%x,%d] / %d threads / %d values / PID %x\n",254 main_cxy, main_lid, total_threads, ARRAY_LENGTH, getpid());307 printf("\n\n[sort] main starts / %d threads / %d items / pid %x / cycle %d\n", 308 total_threads, ARRAY_LENGTH, getpid(), (unsigned int)start_cycle ); 255 309 256 310 // initialize barrier … … 269 323 if( error ) 270 324 { 271 printf("\n[ SORT ERROR] cannot initialise barrier\n" );325 printf("\n[sort error] cannot initialise barrier\n" ); 272 326 exit( 0 ); 273 327 } 274 328 275 printf("\n[SORT] main completes barrier init\n"); 329 #if VERBOSE 330 printf("\n[sort] main completes barrier init\n"); 331 #endif 276 332 277 333 // Array to sort initialization … … 281 337 } 282 338 283 #if DISPLAY_ARRAY 284 printf("\n*** array before sort\n"); 285 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , array0[n] ); 286 #endif 287 288 printf("\n[SORT] main completes array init\n"); 339 #if VERBOSE 340 printf("\n[sort] main completes array init\n"); 341 #endif 289 342 290 343 // launch other threads to execute sort() function … … 317 370 &arg[thread_uid] ) ) // sort arguments 318 371 { 319 printf("\n[ SORT ERROR] main cannot create thread %x \n", thread_uid );372 printf("\n[sort error] main cannot create thread %x \n", thread_uid ); 320 373 exit( 0 ); 321 374 } 322 375 else 323 376 { 324 printf("\n[SORT] main created thread %x \n", thread_uid ); 377 #if VERBOSE 378 printf("\n[sort] main created thread %x \n", thread_uid ); 379 #endif 325 380 } 326 381 } … … 329 384 } 330 385 331 get_cycle( &cycle ); 332 printf("\n[SORT] main completes threads create at cycle %d\n", (unsigned int)cycle ); 386 /////////////////////////// 387 get_cycle( &seq_end_cycle ); 388 389 #if VERBOSE 390 printf("\n[sort] main completes sequencial init at cycle %d\n", 391 (unsigned int)seq_end_cycle ); 392 #endif 333 393 334 394 #if INTERACTIVE_MODE … … 339 399 sort( &arg[main_uid] ); 340 400 401 //////////////////////////// 402 get_cycle( ¶_end_cycle ); 403 404 printf("\n[sort] main completes parallel sort at cycle %d\n", 405 (unsigned int)para_end_cycle ); 406 407 // destroy barrier 408 pthread_barrier_destroy( &barrier ); 409 341 410 #if INTERACTIVE_MODE 342 411 idbg(); 343 412 #endif 344 413 345 // destroy barrier 346 pthread_barrier_destroy( &barrier ); 347 348 #if INTERACTIVE_MODE 349 idbg(); 350 #endif 351 352 // Check result 353 int success = 1; 354 int* res_array = ( (total_threads == 2) || 355 (total_threads == 8) || 356 (total_threads == 32) || 357 (total_threads == 128) || 358 (total_threads == 512) ) ? array1 : array0; 359 360 for( n=0 ; n<(ARRAY_LENGTH-2) ; n++ ) 361 { 362 if ( res_array[n] > res_array[n+1] ) 363 { 364 printf("\n[SORT] array[%d] = %d > array[%d] = %d\n", 365 n , res_array[n] , n+1 , res_array[n+1] ); 366 success = 0; 367 break; 368 } 369 } 370 371 #if DISPLAY_ARRAY 372 printf("\n*** array after sort\n"); 373 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , res_array[n] ); 374 #endif 375 376 get_cycle( &cycle ); 377 378 if ( success ) 379 { 380 printf("\n[SORT] success at cycle %d\n", (unsigned int)cycle ); 381 } 382 else 383 { 384 printf("\n[SORT] failure at cycle %d\n", (unsigned int)cycle ); 385 } 386 387 #if INTERACTIVE_MODE 388 idbg(); 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"); 435 #endif 436 437 #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 fprintf( stream , "\n----- %s -----\n" 470 " - sequencial : %d cycles\n" 471 " - parallel : %d cycles\n", 472 name, sequencial, parallel ); 473 474 // close instrumentation file 475 if( fclose( stream ) ) 476 { 477 printf("\n[sort error] cannot close instrumentation file <%s>\n", name ); 478 exit(0); 479 } 389 480 #endif 390 481 … … 392 483 393 484 } // end main() 394 395 485 396 486 /*
Note: See TracChangeset
for help on using the changeset viewer.