Changeset 440 for trunk/user/sort
- Timestamp:
- May 3, 2018, 5:51:22 PM (7 years ago)
- Location:
- trunk/user/sort
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/sort/Makefile
r439 r440 4 4 5 5 -include ../../params-soft.mk 6 6 7 ifeq ($(ARCH_NAME),) 7 8 $(error Please define in ARCH_NAME parameter in params-soft.mk!) … … 13 14 14 15 compile: dirs build/sort.elf 16 15 17 build/sort.elf : $(OBJS) sort.ld 16 18 $(LD) -o $@ -T sort.ld $(OBJS) -nostdlib -L$(LIBC) -L$(LIBPTHREAD) -lc -lpthread … … 19 21 build/sort.o : sort.c 20 22 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< 21 $(DU) -D $@ > $@.txt22 23 23 24 dirs: … … 25 26 26 27 clean: 27 rm -rf build/*.o build/*.elf build/*.o.txt28 rm -rf build/*.o build/*.elf build/*.txt 28 29 29 30 .PHONY: dirs clean -
trunk/user/sort/sort.c
r436 r440 27 27 #include <pthread.h> 28 28 29 #define ARRAY_LENGTH 0x100 // 256 values 30 #define VERBOSE 0 29 #define ARRAY_LENGTH 0x100 // 256 values 30 31 #define MAX_THREADS 1024 // 16 * 16 * 4 32 33 #define DISPLAY_ARRAY 0 34 #define DISPLAY_THREADS 1 31 35 32 36 /////////////////////////////////////////////////////// 33 37 // macros for fixed format cxy <=> (x,y) translation 38 // TODO these macros are only for TSAR architecture... 34 39 /////////////////////////////////////////////////////// 35 40 … … 61 66 pthread_barrier_t barrier; // synchronisation variables 62 67 68 pthread_attr_t attr[MAX_THREADS]; // thread attributes (one per thread) 69 args_t arg[MAX_THREADS]; // sort function arguments (one per thread) 63 70 64 71 //////////////////////////////////// … … 135 142 unsigned int i; 136 143 unsigned long long cycle; 144 unsigned int cxy; 145 unsigned int lid; 137 146 138 147 int * src_array = NULL; 139 148 int * dst_array = NULL; 149 150 // get core coordinates an date 151 get_core( &cxy , &lid ); 152 get_cycle( &cycle ); 140 153 141 154 unsigned int thread_uid = ptr->thread_uid; … … 143 156 unsigned int main_uid = ptr->main_uid; 144 157 158 printf("\n### core[%x,%d] enter sort : threads %d / thread_uid %x / main_uid %x / cycle %d\n", 159 cxy, lid, threads, thread_uid, main_uid, (int)cycle ); 160 161 while( 1 ) { asm volatile("nop"); } 162 145 163 unsigned int items = ARRAY_LENGTH / threads; 146 164 unsigned int stages = __builtin_ctz( threads ) + 1; 147 148 get_cycle( &cycle );149 printf("\n[SORT] thread[%d] enter at cycle %d\n", thread_uid , (unsigned int)cycle );150 151 printf("\n[SORT] thread[%d] / stage 0 start\n", thread_uid );152 165 153 166 bubbleSort( array0, items, items * thread_uid ); … … 157 170 ///////////////////////////////// 158 171 pthread_barrier_wait( &barrier ); 172 173 printf("\n[SORT] thread[%d] exit barrier\n", thread_uid ); 159 174 160 175 // the number of threads contributing to sort … … 220 235 pthread_t trdid; // kernel allocated thread index (unused) 221 236 pthread_barrierattr_t barrier_attr; // barrier attributes 222 pthread_attr_t attr[1024]; // thread attributes (one per thread)223 args_t arg[1024]; // sort function arguments (one per thread)224 237 225 238 // compute number of threads (one thread per proc) … … 251 264 252 265 get_cycle( &cycle ); 253 printf("\n [SORT] starts :%d threads / %d values / cycle %d\n",254 threads, ARRAY_LENGTH, (unsigned int)cycle );266 printf("\n\n[SORT] main starts on core[%x,%d] / %d threads / %d values / cycle %d\n", 267 main_cxy, main_lid, threads, ARRAY_LENGTH, (unsigned int)cycle ); 255 268 256 269 // Barrier initialization … … 265 278 266 279 get_cycle( &cycle ); 267 printf("\n[SORT] completes barrier init at cycle %d\n", (unsigned int)cycle );280 printf("\n[SORT] main completes barrier init at cycle %d\n", (unsigned int)cycle ); 268 281 269 282 // Array to sort initialization … … 273 286 } 274 287 275 #if VERBOSE288 #if DISPLAY_ARRAY 276 289 printf("\n*** array before sort\n"); 277 290 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , array0[n] ); … … 279 292 280 293 get_cycle( &cycle ); 281 printf("\n[SORT] completes array init at cycle %d\n", (unsigned int)cycle );294 printf("\n[SORT] main completes array init at cycle %d\n", (unsigned int)cycle ); 282 295 283 296 // launch other threads to execute sort() function … … 303 316 if( thread_uid != main_uid ) 304 317 { 318 319 get_cycle( &cycle ); 320 printf("\n### main creates thread_uid %d / &sort_arg %x / cycle %d\n", 321 thread_uid, &arg[thread_uid], (unsigned int)cycle ); 322 305 323 if ( pthread_create( &trdid, // not used because no join 306 324 &attr[thread_uid], // thread attributes … … 308 326 &arg[thread_uid] ) ) // sort arguments 309 327 { 310 printf("\n[SORT ERROR] creating thread %x\n", thread_uid );328 printf("\n[SORT ERROR] main created thread %x \n", thread_uid ); 311 329 exit( 0 ); 312 330 } 331 } 313 332 314 } 315 } 316 } 317 } 318 319 get_cycle( &cycle ); 320 printf("\n[SORT] completes threads create at cycle %d\n", (unsigned int)cycle ); 321 322 // main run also the sort() function 333 #if DISPLAY_THREADS 334 display_sched( CXY_FROM_XY(x,y) , lid ); 335 #endif 336 } 337 } 338 } 339 340 get_cycle( &cycle ); 341 printf("\n[SORT] main completes threads create at cycle %d\n", (unsigned int)cycle ); 342 343 // main run also the sort() function 323 344 sort( &arg[main_uid] ); 324 345 … … 335 356 if ( res_array[n] > res_array[n+1] ) 336 357 { 358 printf("\n[SORT] array[%d] = %d > array[%d] = %d\n", 359 n , res_array[n] , n+1 , res_array[n+1] ); 337 360 success = 0; 338 361 break; … … 340 363 } 341 364 342 #if VERBOSE365 #if DISPLAY_ARRAY 343 366 printf("\n*** array after sort\n"); 344 367 for( n=0; n<ARRAY_LENGTH; n++) printf("array[%d] = %d\n", n , res_array[n] );
Note: See TracChangeset
for help on using the changeset viewer.