Changeset 269 for soft/giet_vm/sort/main.c
- Timestamp:
- Jan 13, 2014, 3:23:38 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/sort/main.c
r258 r269 31 31 // processor id and the first processor must have id 0. 32 32 // 33 // TODO: Replace processor id based identification mechanism by one based34 // on thread id35 //36 33 /////////////////////////////////////////////////////////////////////////////// 37 34 … … 39 36 #include "hard_config.h" 40 37 #include "barrier.h" 41 #include "spin_lock.h"42 38 43 39 ////////////////////////////////////////////////////////////////////////// … … 60 56 61 57 #if (VERBOSE == 1) 62 # if (NB_TTY_CHANNELS > 1) 63 # define printf(...) giet_tty_printf(__VA_ARGS__) 64 # define puts(...) giet_tty_puts(__VA_ARGS__) 65 66 # else // NB_TTY_CHANNELS == 0 67 # define printf(...) \ 68 lock_acquire(&tty_lock); \ 69 giet_tty_printf(__VA_ARGS__); \ 70 lock_release(&tty_lock); 71 # endif 58 # define printf(...) giet_tty_printf(__VA_ARGS__) 59 # define puts(...) giet_tty_puts(__VA_ARGS__) 72 60 #else // VERBOSE == 0 73 61 # define printf(...) … … 75 63 #endif 76 64 77 #define task0_printf(...) if( procid()== 0) giet_tty_printf(__VA_ARGS__)65 #define task0_printf(...) if(thread_id == 0) giet_tty_printf(__VA_ARGS__) 78 66 79 67 #define exit giet_exit … … 104 92 105 93 giet_barrier_t barrier[8]; 106 giet_lock_t tty_lock;107 94 108 95 __attribute__ ((constructor)) void sort() 109 96 { 110 int proc_id = procid(); 97 int thread_id = giet_thread_id(); 98 111 99 int * src_array; 112 100 int * dst_array; 113 101 int i; 114 102 115 task0_printf("Starting SORT application\n"); 103 task0_printf("[ Thread 0 ] Starting SORT application\n"); 104 105 /////////////////////////// 106 // Barriers Initialization 107 108 for (i = 0; i < __builtin_ctz(NPROCS); i++) 109 { 110 barrier_init(&barrier[i], NPROCS >> i); 111 } 116 112 117 113 //////////////////////// 118 114 // Array Initialization 119 115 120 for (i = IPP * proc_id; i < IPP * (proc_id + 1); i++)116 for (i = IPP * thread_id; i < IPP * (thread_id + 1); i++) 121 117 { 122 118 array0[i] = rand(); 123 119 } 124 125 ///////////////////////////126 // Barriers Initialization127 128 while((proc_id != 0) && (init_ok == 0));129 130 if (proc_id == 0)131 {132 for (i = 0; i < __builtin_ctz(NPROCS); i++)133 {134 task0_printf("Initializing barrier %d with %d\n", i, NPROCS >> i);135 barrier_init(&barrier[i], NPROCS >> i);136 }137 138 asm volatile ("sync");139 init_ok = 1;140 }141 142 asm volatile ("sync");143 barrier_wait(&barrier[0]);144 120 145 121 /////////////////////////////////// 146 122 // Parallel sort of array elements 147 123 148 printf(" Proc %d Stage 0: Processor Sorting...\n\r", proc_id);149 150 bubbleSort(array0, IPP, IPP * proc_id);151 152 printf(" Proc %d Finishing Stage 0...\n\r", proc_id);124 printf("[ Thread %d ] Stage 0: Processor Sorting...\n\r", thread_id); 125 126 bubbleSort(array0, IPP, IPP * thread_id); 127 128 printf("[ Thread %d ] Finishing Stage 0\n\r", thread_id); 153 129 154 130 for (i = 0; i < __builtin_ctz(NPROCS); i++) … … 157 133 barrier_wait(&barrier[i]); 158 134 159 printf("Proc %d Stage %d: Starting...\n\r", proc_id, i+1); 160 161 if((proc_id % (2 << i)) != 0) exit(); 135 if((thread_id % (2 << i)) != 0) 136 { 137 printf("[ Thread %d ] Quits\n\r", thread_id); 138 exit(); 139 } 140 141 printf("[ Thread %d ] Stage %d: Starting...\n\r", thread_id, i+1); 162 142 163 143 if((i % 2) == 0) … … 174 154 merge(src_array, dst_array 175 155 , IPP << i 176 , IPP * proc_id177 , IPP * ( proc_id + (1 << i))178 , IPP * proc_id156 , IPP * thread_id 157 , IPP * (thread_id + (1 << i)) 158 , IPP * thread_id 179 159 ); 180 160 181 printf(" Proc %d Finishing Stage %d...\n\r", proc_id, i + 1);161 printf("[ Thread %d ] Finishing Stage %d\n\r", thread_id, i + 1); 182 162 } 183 163 … … 188 168 // Verify the resulting array 189 169 190 if( proc_id == 0)170 if(thread_id == 0) 191 171 { 192 172 success = 1; … … 205 185 if (success) 206 186 { 207 printf(" Success!!\n\r");187 printf("[ Thread 0 ] Success!!\n\r"); 208 188 } 209 189 else 210 190 { 211 printf(" Failure!! Incorrect element: %d\n\r", failure_index);191 printf("[ Thread 0 ] Failure!! Incorrect element: %d\n\r", failure_index); 212 192 213 193
Note: See TracChangeset
for help on using the changeset viewer.