Changeset 502 for soft/giet_vm/applications/sort/main.c
- Timestamp:
- Feb 8, 2015, 9:20:45 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/sort/main.c
r432 r502 9 9 // barrier routines to apply a sort algorithm in several stages. 10 10 // 11 // Considerations : 12 // 13 // - It supports up to 256 processors and the number of processors 14 // must be a power of 2. 15 // 16 // - If there is only one TTY available, this application uses a spin 17 // lock to avoid several threads writting at the same time. 18 // 19 // - This application must be executed on a cache coherent 20 // architecture. Otherwise some modifications must be applied 21 // 22 // - The processors executing this application must have a contiguous 23 // processor id and the first processor must have id 0. 11 // Constraints : 12 // 13 // - It supports up to 1024 processors and the number of processors 14 // must be a power of 2. 15 // 16 // _ The array of values to be sorted (ARRAY_LENGTH) must be power of 2 17 // larger than the number of processors. 18 // 19 // - This application must be executed on a cache coherent architecture. 24 20 // 25 21 /////////////////////////////////////////////////////////////////////////////// … … 28 24 #include "mapping_info.h" 29 25 #include "hard_config.h" 30 #include " barrier.h"31 32 #define ARRAY_LENGTH 51233 #define IPT (ARRAY_LENGTH / *nb_thread) // ITEMS PER THREAD26 #include "user_barrier.h" 27 28 #define ARRAY_LENGTH 4096 29 #define IPT (ARRAY_LENGTH / threads) // ITEMS PER THREAD 34 30 35 31 //////////////////////////////////////////////////////////////////////////////// 36 // Processors other than 0 display algorithm state 37 // The processor 0 always displays some information so this does not affect him 32 // Processors other than 0 display algorithm state if VERBOSE non zero 38 33 39 34 #define VERBOSE 1 40 35 41 36 //////////////////////////////////////////////////////////////////////////////// 42 // Define printf according to verbosity option and number of available 43 // TTY 37 // Define printf according to verbosity option and number of available TTY 44 38 45 39 #if (VERBOSE == 1) … … 50 44 51 45 #define task0_printf(...) if(thread_id == 0) giet_shr_printf(__VA_ARGS__) 52 53 #define exit giet_exit54 #define procid giet_procid55 #define rand giet_rand56 46 57 47 int array0[ARRAY_LENGTH]; … … 73 63 int init_pos_result); 74 64 75 /////////////////////////////////////////////////// 76 // This application support at most 256processors77 // Number of barriers = log2( nb_thread)78 79 giet_barrier_t barrier[ 8];65 /////////////////////////////////////////////////////// 66 // This application supports at most 1024 processors 67 // Number of barriers = log2(threads) 68 69 giet_barrier_t barrier[10]; 80 70 81 71 ////////////////////////////////////////// … … 83 73 { 84 74 int thread_id = giet_thread_id(); 85 unsigned int* nb_thread;86 75 int * src_array = NULL; 87 76 int * dst_array = NULL; … … 91 80 unsigned int time_end; 92 81 93 giet_vobj_get_vbase( "sort" , 94 "sort_args", 95 (unsigned int*)&nb_thread ); 96 97 task0_printf("\n[ Thread 0 ] Starting sort application with %u threads " 98 "at cycle %u\n", *nb_thread, time_start); 82 // compute number of threads (one thread per proc) 83 unsigned int x_size; 84 unsigned int y_size; 85 unsigned int nprocs; 86 unsigned int threads; 87 giet_procs_number( &x_size , &y_size , &nprocs ); 88 threads = x_size * y_size * nprocs; 89 90 if ( (threads != 1) && (threads != 2) && (threads != 4) && 91 (threads != 8) && (threads != 16 ) && (threads != 32) && 92 (threads != 64) && (threads != 128) && (threads != 256) && 93 (threads != 512) && (threads != 1024) ) 94 { 95 task0_printf("[SORT ERROR] Number of processors must be power of 2\n" 96 " x_size = %d / y_size = %d / nprocs = %d\n", 97 x_size , y_size , nprocs ); 98 giet_exit("error"); 99 } 100 101 task0_printf("\n[ Thread 0 ] Starting sort application with %d threads " 102 "at cycle %d\n", threads, time_start); 99 103 100 104 /////////////////////////// … … 103 107 if (thread_id == 0) 104 108 { 105 for (i = 0; i < __builtin_ctz( *nb_thread); i++)106 { 107 barrier_init(&barrier[i], *nb_thread>> i);109 for (i = 0; i < __builtin_ctz( threads ); i++) 110 { 111 barrier_init(&barrier[i], threads >> i); 108 112 } 109 113 … … 120 124 for (i = IPT * thread_id; i < IPT * (thread_id + 1); i++) 121 125 { 122 array0[i] = rand();126 array0[i] = giet_rand(); 123 127 } 124 128 … … 132 136 printf("[ Thread %d ] Finishing Stage 0\n\r", thread_id); 133 137 134 for (i = 0; i < __builtin_ctz( *nb_thread); i++)138 for (i = 0; i < __builtin_ctz( threads ); i++) 135 139 { 136 140 barrier_wait(&barrier[i]); … … 139 143 { 140 144 printf("[ Thread %d ] Quit\n\r", thread_id ); 141 exit("Completed");145 giet_exit("Completed"); 142 146 } 143 147 … … 173 177 if(thread_id != 0) 174 178 { 175 exit("error: only thread 0 should get here");179 giet_exit("error: only thread 0 should get here"); 176 180 } 177 181 … … 196 200 if (success) 197 201 { 198 exit("!!! Success !!!");202 giet_exit("!!! Success !!!"); 199 203 } 200 204 else … … 206 210 printf("array[%d] = %d\n", i, dst_array[i]); 207 211 } 208 exit("!!! Failure !!!");209 } 210 211 exit("Completed");212 giet_exit("!!! Failure !!!"); 213 } 214 215 giet_exit("Completed"); 212 216 } 213 217
Note: See TracChangeset
for help on using the changeset viewer.