Changeset 652 for trunk/user/sort
- Timestamp:
- Nov 14, 2019, 3:56:51 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/sort/sort.c
r637 r652 69 69 #define INSTRUMENTATION 1 // register computation times on file 70 70 71 ///////////////////////////////////////////////////////////////////////////////////72 // Arguments for the sort() function73 ///////////////////////////////////////////////////////////////////////////////////74 75 typedef struct76 {77 unsigned int tid; // continuous thread index78 unsigned int threads; // total number of threads79 pthread_barrier_t * parent_barrier; // pointer on termination barrier80 }81 sort_args_t;82 83 71 //////////////////////////////////////////////////////////////////////////////////// 84 72 // Sort specific global variables … … 88 76 int array1[ARRAY_LENGTH]; 89 77 78 unsigned int threads; // total number of working threads 79 90 80 pthread_barrier_t barrier; // synchronisation variables 91 81 … … 93 83 // Global variables required by parallel_pthread_create() 94 84 ///////////////////////////////////////////////////////////////////////////////////// 95 96 // 2D arrays of input arguments for the <sort> threads97 // These arrays are initialised by the application main thread98 99 sort_args_t sort_args[CLUSTERS_MAX][CORES_MAX]; // sort function arguments100 sort_args_t * sort_ptrs[CLUSTERS_MAX][CORES_MAX]; // pointers on arguments101 102 // 1D array of barriers to allow the <sort> threads to signal termination103 // this array is initialised by the pthread_parallel_create() function104 105 pthread_barrier_t parent_barriers[CLUSTERS_MAX]; // termination barrier106 85 107 86 … … 174 153 } // end merge() 175 154 176 ////////////////////////////// 177 void sort( sort_args_t * ptr )155 /////////////////////////////////////////////// 156 void sort( pthread_parallel_work_args_t * ptr ) 178 157 { 179 158 unsigned int i; … … 183 162 // get arguments 184 163 unsigned int tid = ptr->tid; 185 unsigned int threads = ptr->threads; 186 pthread_barrier_t * parent_barrier = ptr->parent_barrier; 164 pthread_barrier_t * parent_barrier = ptr->barrier; 187 165 188 166 unsigned int items = ARRAY_LENGTH / threads; … … 190 168 191 169 #if DEBUG_SORT 192 printf("\n[sort] start : ptr %x / tid %d / threads %d / barrier %x\n",170 printf("\n[sort] start : ptr %x / tid %d / threads %d / parent_barrier %x\n", 193 171 ptr, tid, threads, parent_barrier ); 194 172 #endif … … 249 227 } // en for stages 250 228 251 // sort thread signal completion to main thread229 // sort thread signal completion to pthtread_parallel_create() 252 230 pthread_barrier_wait( parent_barrier ); 253 231 … … 269 247 unsigned int y_size; // number of columns 270 248 unsigned int ncores; // number of cores per cluster 271 unsigned int total_threads; // total number of threads272 unsigned int x; // X coordinate for a sort thread273 unsigned int y; // Y coordinate for a sort thread274 unsigned int cxy; // cluster identifier for a sort thead275 unsigned int lid; // core local index for a thread276 unsigned int tid; // sort thread continuous index277 249 pthread_barrierattr_t barrier_attr; // barrier attributes (used for DQT) 278 250 unsigned int n; // index in array to sort … … 285 257 get_cycle( &start_cycle ); 286 258 287 // compute number of threads (one thread per core)259 // compute number of working threads (one thread per core) 288 260 get_config( &x_size , &y_size , &ncores ); 289 t otal_threads = x_size * y_size * ncores;261 threads = x_size * y_size * ncores; 290 262 291 263 // compute covering DQT size an level … … 294 266 295 267 // checks number of threads 296 if ( (t otal_threads != 1) && (total_threads != 2) && (total_threads != 4) &&297 (t otal_threads != 8) && (total_threads != 16 ) && (total_threads != 32) &&298 (t otal_threads != 64) && (total_threads != 128) && (total_threads != 256) &&299 (t otal_threads != 512) && (total_threads != 1024) )268 if ( (threads != 1) && (threads != 2) && (threads != 4) && 269 (threads != 8) && (threads != 16 ) && (threads != 32) && 270 (threads != 64) && (threads != 128) && (threads != 256) && 271 (threads != 512) && (threads != 1024) ) 300 272 { 301 273 printf("\n[sort] ERROR : number of cores must be power of 2\n"); … … 304 276 305 277 // check array size 306 if ( ARRAY_LENGTH % t otal_threads)278 if ( ARRAY_LENGTH % threads) 307 279 { 308 280 printf("\n[sort] ERROR : array size must be multiple of number of threads\n"); … … 311 283 312 284 printf("\n[sort] main starts / %d threads / %d items / pid %x / cycle %d\n", 313 t otal_threads, ARRAY_LENGTH, getpid(), (unsigned int)start_cycle );285 threads, ARRAY_LENGTH, getpid(), (unsigned int)start_cycle ); 314 286 315 287 // initialize barrier … … 319 291 barrier_attr.y_size = y_size; 320 292 barrier_attr.nthreads = ncores; 321 error = pthread_barrier_init( &barrier, &barrier_attr , t otal_threads );293 error = pthread_barrier_init( &barrier, &barrier_attr , threads ); 322 294 } 323 295 else // use SIMPLE_BARRIER 324 296 { 325 error = pthread_barrier_init( &barrier, NULL , t otal_threads );297 error = pthread_barrier_init( &barrier, NULL , threads ); 326 298 } 327 299 … … 352 324 #endif 353 325 354 // build array of arguments for the <sort> threads355 for (x = 0 ; x < x_size ; x++)356 {357 for (y = 0 ; y < y_size ; y++)358 {359 // compute cluster identifier360 cxy = HAL_CXY_FROM_XY( x , y );361 362 for ( lid = 0 ; lid < ncores ; lid++ )363 {364 // compute thread continuous index365 tid = (((x * y_size) + y) * ncores) + lid;366 367 // initialize 2D array of arguments368 sort_args[cxy][lid].tid = tid;369 sort_args[cxy][lid].threads = total_threads;370 sort_args[cxy][lid].parent_barrier = &parent_barriers[cxy];371 372 // initialize 2D array of pointers373 sort_ptrs[cxy][lid] = &sort_args[cxy][lid];374 }375 }376 }377 378 326 /////////////////////////// 379 327 get_cycle( &seq_end_cycle ); … … 386 334 // create and execute the working threads 387 335 if( pthread_parallel_create( root_level, 388 &sort, 389 &sort_ptrs[0][0], 390 &parent_barriers[0] ) ) 336 &sort ) ) 391 337 { 392 338 printf("\n[sort] ERROR : cannot create threads\n"); … … 412 358 #if CHECK_RESULT 413 359 int success = 1; 414 int * res_array = ( (t otal_threads == 2) ||415 (t otal_threads == 8) ||416 (t otal_threads == 32) ||417 (t otal_threads == 128) ||418 (t otal_threads == 512) ) ? array1 : array0;360 int * res_array = ( (threads == 2) || 361 (threads == 8) || 362 (threads == 32) || 363 (threads == 128) || 364 (threads == 512) ) ? array1 : array0; 419 365 420 366 for( n=0 ; n<(ARRAY_LENGTH-2) ; n++ )
Note: See TracChangeset
for help on using the changeset viewer.