Changeset 85 for trunk/platforms/caba-xxx-ccxcachemulti-mipsel/soft
- Timestamp:
- Sep 3, 2010, 3:57:30 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/platforms/caba-xxx-ccxcachemulti-mipsel/soft/main.c
r3 r85 2 2 #include "stdio.h" 3 3 #include "stdlib.h" 4 #include "matrice.h"4 //#include "matrice.h" 5 5 6 6 #include "../segmentation.h" 7 7 8 #define NPROCS 49 #define SIZE 10008 #define NPROCS 1 9 #define SIZE 50 10 10 #define SORT_TYPE 0 // shellSort 11 11 12 12 volatile int nprocs=NPROCS; 13 13 14 /* 14 15 15 unsigned int gQSortNum0[200] = { 16 16 251, 24, 113, 170, 215, 60, 83, 30, 115, 48, 169, 210, 49, 92, 101, 58, 21, 184, 225, 6, … … 24 24 186, 149, 86, 155, 200, 239, 118, 119, 28, 77, 254, 19, 176, 183, 78, 145, 132, 5, 90, 117, 25 25 152, 127, 218, 153, 20, 67, 178, 3, 128, 185, 254, 95, 172, 139, 246, 123, 104, 15, 42, 169 }; 26 */27 26 28 unsigned int SortArr0[NPROCS*(SIZE+200)];29 27 30 void SORT(unsigned int *base, unsigned int n, int type); 31 void insertion_sort(unsigned int *base, unsigned int n); // type 2 32 void selection_sort(unsigned int *base, unsigned int n); // type 1 33 void bubble_sort(unsigned int *base, unsigned int n); // type 3 28 unsigned int SortArr0[NPROCS*(SIZE+50)]; 29 34 30 void shellSortPhase(unsigned int a[],unsigned int length, int gap); 35 31 void shellSort(unsigned int *base, unsigned int n); // type 0 … … 57 53 i=1; 58 54 puts("Memory copy \n"); 59 SortArray = SortArr0 + p*(SIZE+ 200);55 SortArray = SortArr0 + p*(SIZE+50); 60 56 memcpy(SortArray, gQSortNum0 + p*SIZE,SIZE*4); 61 //memcpy(SortArray, gQSortNum0,SIZE*4);62 57 63 58 puts("Sort... \n"); 64 SORT((unsigned int *) (SortArray), (unsigned int) SIZE, SORT_TYPE);59 shellSort((unsigned int *) (SortArray), (unsigned int) SIZE); 65 60 66 61 for (j = 1; j < SIZE; j++) … … 81 76 } 82 77 83 84 // puts("Display the sorted array : \n");85 // for(j = 0; j < SIZE; j++)86 // {87 // puti(SortArray[j]);88 // putchar('\n');89 // }90 91 // printf( "------------------------------ \n");92 // printf( "nombre cycles cpu : %i\n", end_cycle-beg_cycle);93 // printf( "------------------------------ \n");94 95 78 96 79 while(1); 97 80 } 98 81 99 100 //---- insertion sort : non adapté pour tableaux de grande taille (> 100) --101 void insertion_sort(unsigned int *base, unsigned int n)102 {103 /* Spécifications externes : Tri du tableau base par insertion séquentielle */104 int i,p,j;105 int x;106 107 puts("Insertion Sort\n");108 109 for (i = 1; i < n; i++)110 {111 112 putchar('-'); // added for debug113 114 /* stockage de la valeur en i */115 x = base[i];116 117 /* recherche du plus petit indice p inférieur à i tel que base[p] >= base[i] */118 for(p = 0; base[p] < x; p++);119 /* p pointe une valeur de base supérieure à celle en i */120 121 /* décalage avant des valeurs de base entre p et i */122 for (j = i-1; j >= p; j--) {123 base[j+1] = base[j];124 }125 126 base[p] = x; /* insertion de la valeur stockée à la place vacante */127 128 putchar('+'); // added for debug129 130 }131 }132 133 //------ simple_sort -------------------------------134 void selection_sort(unsigned int *base, unsigned int n)135 {136 int i, min, j , x;137 puts("Selection Sort\n");138 139 for(i = 0 ; i < n - 1 ; i++)140 {141 142 putchar('-'); // added for debug143 144 min = i;145 146 147 for(j = i+1 ; j < n ; j++)148 {149 150 if(base[j] < base[min])151 min = j;152 153 }154 155 if(min != i)156 {157 x = base[i];158 base[i] = base[min];159 base[min] = x;160 }161 162 putchar('+'); // added for debug163 164 }165 }166 //-------------------------------167 void bubble_sort(unsigned int *base, unsigned int n)168 {169 int i = 0; /* Indice de répétition du tri */170 int j = 0; /* Variable de boucle */171 int tmp = 0; /* Variable de stockage temporaire */172 int en_desordre = 1; /* Booléen marquant l'arrêt du tri si le tableau est ordonné */173 174 puts("Bubble Sort\n");175 176 /* Boucle de répétition du tri et le test qui arrête le tri dès que le tableau est ordonné */177 for(i = 0 ; (i < n) && en_desordre; i++)178 {179 putchar('-'); // added for debug180 181 /* Supposons le tableau ordonné */182 en_desordre = 0;183 /* Vérification des éléments des places j et j-1 */184 for(j = 1 ; j < n - i ; j++)185 {186 /* Si les 2 éléments sont mal triés */187 if(base[j] < base[j-1])188 {189 /* Inversion des 2 éléments */190 tmp = base[j-1];191 base[j-1] = base[j];192 base[j] = tmp;193 194 /* Le tableau n'est toujours pas trié */195 en_desordre = 1;196 }197 }198 199 putchar('+'); // added for debug200 }201 202 }203 82 //------------------------------------------------------ 204 83 /* … … 242 121 } 243 122 244 //-------------------------------------*/245 void SORT(unsigned int *base, unsigned int n, int type)246 {247 switch(type)248 {249 case 0:250 shellSort(base, n);251 break;252 case 1:253 selection_sort(base, n);254 break;255 case 2:256 insertion_sort(base, n);257 break;258 case 3:259 bubble_sort(base, n);260 break;261 default:262 break;263 }264 }
Note: See TracChangeset
for help on using the changeset viewer.