Changeset 619 for trunk/user/sort/sort.c
- Timestamp:
- Feb 12, 2019, 1:15:47 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/sort/sort.c
r596 r619 29 29 #include <hal_macros.h> 30 30 31 #define ARRAY_LENGTH 0x1000 // 4096 values 32 31 #define ARRAY_LENGTH 256 // number of values 33 32 #define MAX_THREADS 1024 // 16 * 16 * 4 34 33 #define USE_DQT_BARRIER 1 35 34 #define DISPLAY_ARRAY 0 36 35 #define INTERACTIVE_MODE 0 … … 42 41 typedef struct 43 42 { 44 unsigned int threads; // total number of threads43 unsigned int threads; // total number of threads 45 44 unsigned int thread_uid; // thread user index (0 to threads -1) 46 45 unsigned int main_uid; // main thread user index … … 206 205 void main( void ) 207 206 { 207 int error; 208 208 unsigned int x_size; // number of rows 209 209 unsigned int y_size; // number of columns 210 210 unsigned int ncores; // number of cores per cluster 211 unsigned int t hreads;// total number of threads211 unsigned int total_threads; // total number of threads 212 212 unsigned int thread_uid; // user defined thread index 213 213 unsigned int main_cxy; // cluster identifier for main … … 226 226 // compute number of threads (one thread per core) 227 227 get_config( &x_size , &y_size , &ncores ); 228 t hreads = x_size * y_size * ncores;228 total_threads = x_size * y_size * ncores; 229 229 230 230 // get core coordinates and user index for the main thread … … 235 235 236 236 // checks number of threads 237 if ( (t hreads != 1) && (threads != 2) && (threads != 4) &&238 (t hreads != 8) && (threads != 16 ) && (threads != 32) &&239 (t hreads != 64) && (threads != 128) && (threads != 256) &&240 (t hreads != 512) && (threads != 1024) )237 if ( (total_threads != 1) && (total_threads != 2) && (total_threads != 4) && 238 (total_threads != 8) && (total_threads != 16 ) && (total_threads != 32) && 239 (total_threads != 64) && (total_threads != 128) && (total_threads != 256) && 240 (total_threads != 512) && (total_threads != 1024) ) 241 241 { 242 242 printf("\n[SORT ERROR] number of cores must be power of 2\n"); … … 245 245 246 246 // check array size 247 if ( ARRAY_LENGTH % t hreads)247 if ( ARRAY_LENGTH % total_threads) 248 248 { 249 249 printf("\n[SORT ERROR] array size must be multiple of number of threads\n"); … … 251 251 } 252 252 253 printf("\n[SORT] main starts on core[%x,%d] / %d thread(s) / %d values / PID %x\n", 254 main_cxy, main_lid, threads, ARRAY_LENGTH, getpid() ); 255 256 // Barrier initialization 257 barrier_attr.x_size = x_size; 258 barrier_attr.y_size = y_size; 259 barrier_attr.nthreads = ncores; 260 if( pthread_barrier_init( &barrier, &barrier_attr , threads ) ) 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() ); 255 256 // initialize barrier 257 if( USE_DQT_BARRIER ) 258 { 259 barrier_attr.x_size = x_size; 260 barrier_attr.y_size = y_size; 261 barrier_attr.nthreads = ncores; 262 error = pthread_barrier_init( &barrier, &barrier_attr , total_threads ); 263 } 264 else // use SIMPLE_BARRIER 265 { 266 error = pthread_barrier_init( &barrier, NULL , total_threads ); 267 } 268 269 if( error ) 261 270 { 262 271 printf("\n[SORT ERROR] cannot initialise barrier\n" ); … … 290 299 291 300 // set sort arguments for all threads 292 arg[thread_uid].threads = t hreads;301 arg[thread_uid].threads = total_threads; 293 302 arg[thread_uid].thread_uid = thread_uid; 294 303 arg[thread_uid].main_uid = main_uid; … … 330 339 sort( &arg[main_uid] ); 331 340 341 #if INTERACTIVE_MODE 342 idbg(); 343 #endif 344 345 // destroy barrier 346 pthread_barrier_destroy( &barrier ); 347 348 #if INTERACTIVE_MODE 349 idbg(); 350 #endif 351 332 352 // Check result 333 353 int success = 1; 334 int* res_array = ( (t hreads==2) ||335 (t hreads==8) ||336 (t hreads==32) ||337 (t hreads==128) ||338 (t hreads==512) ) ? array1 : array0;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; 339 359 340 360 for( n=0 ; n<(ARRAY_LENGTH-2) ; n++ ) … … 359 379 { 360 380 printf("\n[SORT] success at cycle %d\n", (unsigned int)cycle ); 361 exit( 0 );362 381 } 363 382 else 364 383 { 365 384 printf("\n[SORT] failure at cycle %d\n", (unsigned int)cycle ); 366 exit( 1 ); 367 } 385 } 386 387 #if INTERACTIVE_MODE 388 idbg(); 389 #endif 390 391 exit( 0 ); 368 392 369 393 } // end main()
Note: See TracChangeset
for help on using the changeset viewer.