Changeset 257 for soft/giet_vm/sort/main.c
- Timestamp:
- Nov 22, 2013, 5:53:31 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/sort/main.c
r256 r257 1 //================================================================================================= 2 // File : main.c 3 // 4 // Date : 11/2013 5 // 6 // Author : Cesar Fuguet Tortolero 7 // :<cesar.fuguet-tortolero@lip6.fr> 8 // 9 // Description: Sort application using the GIET-VM OS. 10 // This application uses the barrier routines to apply a sort algorithm 11 // in several stages. 12 //================================================================================================= 1 /////////////////////////////////////////////////////////////////////////////// 2 // File : 3 // 4 // main.c 5 // 6 // Date : 7 // 8 // November 2013 9 // 10 // Author : 11 // 12 // Cesar Fuguet Tortolero <cesar.fuguet-tortolero@lip6.fr> 13 // 14 // Description : 15 // 16 // Sort application using the GIET-VM OS. This application uses the 17 // barrier routines to apply a sort algorithm in several stages. 18 // 19 // Considerations : 20 // 21 // - It supports up to 256 processors and the number of processors 22 // must be a power of 2. 23 // 24 // - If there is only one TTY available, this application uses a spin 25 // lock to avoid several threads writting at the same time. 26 // 27 // - This application must be executed on a cache coherent 28 // architecture. Otherwise some modifications must be applied 29 // 30 // - The processors executing this application must have a contiguous 31 // processor id and the first processor must have id 0. 32 // 33 // TODO: Replace processor id based identification mechanism by one based 34 // on thread id 35 // 36 /////////////////////////////////////////////////////////////////////////////// 13 37 14 38 #include "stdio.h" 15 39 #include "hard_config.h" 16 40 #include "barrier.h" 17 18 #define NPROCS 8 19 #define ARRAY_LENGTH (NPROCS * 50) 41 #include "spin_lock.h" 42 43 ////////////////////////////////////////////////////////////////////////// 44 // The NPROCS constant must be modified depending on the desired number of 45 // threads 46 47 #define NPROCS 16 48 #define ARRAY_LENGTH (NPROCS * 128) 20 49 #define IPP (ARRAY_LENGTH / NPROCS) // ITEMS PER PROCESSOR 21 50 22 // Other processors than 0 display algorithm state 51 //////////////////////////////////////////////////////////////////////////////// 52 // Processors other than 0 display algorithm state 53 // The processor 0 always displays some information so this does not affect him 54 23 55 #define VERBOSE 1 24 56 57 /////////////////////////////////////////////////////////////////////// 58 // Define printf according to verbosity option and number of available 59 // TTY 60 25 61 #if (VERBOSE == 1) 26 #define printf(...) giet_tty_printf(__VA_ARGS__) 27 #define puts(...) giet_tty_puts(__VA_ARGS__) 28 #else 29 #define printf(...) 30 #define puts(...) 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 72 #else // VERBOSE == 0 73 # define printf(...) 74 # define puts(...) 31 75 #endif 76 77 #define task0_printf(...) if(procid() == 0) giet_tty_printf(__VA_ARGS__) 32 78 33 79 #define exit giet_exit 34 80 #define procid giet_procid 35 81 #define rand giet_rand 36 37 #define task0_printf(...) if(procid() == 0) giet_tty_printf(__VA_ARGS__)38 82 39 83 int array0[ARRAY_LENGTH]; … … 55 99 int init_pos_result); 56 100 57 // this application support at most 256 processors 58 // number of barriers = log2(NPROCS) 101 /////////////////////////////////////////////////// 102 // This application support at most 256 processors 103 // Number of barriers = log2(NPROCS) 104 59 105 giet_barrier_t barrier[8]; 106 giet_lock_t tty_lock; 60 107 61 108 __attribute__ ((constructor)) void sort() … … 66 113 int i; 67 114 68 /**************************************************************************/69 /* Hello World */70 71 115 task0_printf("Starting SORT application\n"); 72 116 73 / **************************************************************************/74 / * Array Inititialitatin */117 //////////////////////// 118 // Array Initialization 75 119 76 120 for (i = IPP * proc_id; i < IPP * (proc_id + 1); i++) … … 79 123 } 80 124 81 / **************************************************************************/82 / * Barriers Inititialitatin */125 /////////////////////////// 126 // Barriers Initialization 83 127 84 128 while((proc_id != 0) && (init_ok == 0)); … … 88 132 for (i = 0; i < __builtin_ctz(NPROCS); i++) 89 133 { 90 printf("Initializing barrier %d with %d\n", i, NPROCS >> i);134 task0_printf("Initializing barrier %d with %d\n", i, NPROCS >> i); 91 135 barrier_init(&barrier[i], NPROCS >> i); 92 136 } … … 99 143 barrier_wait(&barrier[0]); 100 144 101 /**************************************************************************/ 102 /* Parallel sorting of array pieces */ 103 104 task0_printf("Stage 0: Processor Sorting...\n\r"); 145 /////////////////////////////////// 146 // Parallel sort of array elements 147 148 printf("Proc %d Stage 0: Processor Sorting...\n\r", proc_id); 149 105 150 bubbleSort(array0, IPP, IPP * proc_id); 106 task0_printf("Finishing Stage 0...\n\r"); 151 152 printf("Proc %d Finishing Stage 0...\n\r", proc_id); 107 153 108 154 for (i = 0; i < __builtin_ctz(NPROCS); i++) … … 110 156 asm volatile ("sync"); 111 157 barrier_wait(&barrier[i]); 112 task0_printf("Stage %d: Starting...\n\r", i+1); 158 159 printf("Proc %d Stage %d: Starting...\n\r", proc_id, i+1); 113 160 114 161 if((proc_id % (2 << i)) != 0) exit(); … … 132 179 ); 133 180 134 task0_printf("Finishing Stage %d...\n\r", i + 1);181 printf("Proc %d Finishing Stage %d...\n\r", proc_id, i + 1); 135 182 } 136 183 137 184 int success; 138 185 int failure_index; 186 187 ////////////////////////////// 188 // Verify the resulting array 139 189 140 190 if(proc_id == 0)
Note: See TracChangeset
for help on using the changeset viewer.