| 1 | #include "system.h" |
|---|
| 2 | #include "stdio.h" |
|---|
| 3 | #include "stdlib.h" |
|---|
| 4 | #include "matrice.h" |
|---|
| 5 | |
|---|
| 6 | #include "../segmentation.h" |
|---|
| 7 | |
|---|
| 8 | #define NPROCS 16 |
|---|
| 9 | #define SIZE 500 //1000 |
|---|
| 10 | #define SORT_TYPE 1 |
|---|
| 11 | |
|---|
| 12 | extern unsigned int __SortArr1; |
|---|
| 13 | extern unsigned int __SortArr2; |
|---|
| 14 | extern unsigned int __SortArr3; |
|---|
| 15 | |
|---|
| 16 | volatile int compteur=NPROCS; |
|---|
| 17 | volatile int nprocs=NPROCS; |
|---|
| 18 | volatile int mmu=0; |
|---|
| 19 | |
|---|
| 20 | unsigned int SortArr0[4*(SIZE+200)]; |
|---|
| 21 | unsigned int *SortArr1 = &__SortArr1; |
|---|
| 22 | unsigned int *SortArr2 = &__SortArr2; |
|---|
| 23 | unsigned int *SortArr3 = &__SortArr3; |
|---|
| 24 | |
|---|
| 25 | void SORT(int *base, int n, int type); |
|---|
| 26 | void insertion_sort(int *base, int n); |
|---|
| 27 | void selection_sort(int *base, int n); |
|---|
| 28 | void bubble_sort(int *base, int n); |
|---|
| 29 | void quick_sort(int *base, int n); |
|---|
| 30 | |
|---|
| 31 | int main() |
|---|
| 32 | { |
|---|
| 33 | |
|---|
| 34 | unsigned int *mappArray[4] = {SortArr0, SortArr1, SortArr2, SortArr3}; |
|---|
| 35 | |
|---|
| 36 | register int p; |
|---|
| 37 | |
|---|
| 38 | p=procnum(); |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | puts("Hello from processor "); |
|---|
| 42 | puti(p); |
|---|
| 43 | putchar('\n'); |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | int i; |
|---|
| 47 | int j; |
|---|
| 48 | |
|---|
| 49 | if(p+1 <= nprocs){ |
|---|
| 50 | i=1; |
|---|
| 51 | puts("Memory copy \n"); |
|---|
| 52 | memcpy(&mappArray[p/4][(p % 4)*(SIZE+200)], gQSortNum0 + ( (4*(p+1)*i) % 32) ,SIZE); |
|---|
| 53 | |
|---|
| 54 | puts("Sort... \n"); |
|---|
| 55 | SORT(&mappArray[(p/4)][(p % 4)*(SIZE+200)], SIZE, SORT_TYPE); |
|---|
| 56 | |
|---|
| 57 | for (j = 1; j < SIZE; j++) |
|---|
| 58 | { |
|---|
| 59 | if (mappArray[p/4][(p % 4)*(SIZE+200)+j] < mappArray[p/4][(p%4)*(SIZE+200) + j - 1]) |
|---|
| 60 | { |
|---|
| 61 | puts("ucbqsort: failed\n"); |
|---|
| 62 | while(1); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | } |
|---|
| 66 | puts("ucbqsort: success\n"); |
|---|
| 67 | |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | while(1); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | //---- insertion sort : non adapté pour tableaux de grande taille (> 100) -- |
|---|
| 74 | void insertion_sort(int *base, int n) |
|---|
| 75 | { |
|---|
| 76 | /* Spécifications externes : Tri du tableau base par insertion séquentielle */ |
|---|
| 77 | int i,p,j; |
|---|
| 78 | int x; |
|---|
| 79 | |
|---|
| 80 | puts("Insertion Sort\n"); |
|---|
| 81 | |
|---|
| 82 | for (i = 1; i < n; i++) |
|---|
| 83 | { |
|---|
| 84 | |
|---|
| 85 | putchar('-'); // added for debug |
|---|
| 86 | |
|---|
| 87 | /* stockage de la valeur en i */ |
|---|
| 88 | x = base[i]; |
|---|
| 89 | |
|---|
| 90 | /* recherche du plus petit indice p inférieur à i tel que base[p] >= base[i] */ |
|---|
| 91 | for(p = 0; base[p] < x; p++); |
|---|
| 92 | /* p pointe une valeur de base supérieure à celle en i */ |
|---|
| 93 | |
|---|
| 94 | /* décalage avant des valeurs de base entre p et i */ |
|---|
| 95 | for (j = i-1; j >= p; j--) { |
|---|
| 96 | base[j+1] = base[j]; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | base[p] = x; /* insertion de la valeur stockée à la place vacante */ |
|---|
| 100 | |
|---|
| 101 | putchar('+'); // added for debug |
|---|
| 102 | |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | //------ simple_sort ------------------------------- |
|---|
| 107 | void selection_sort(int *base, int n) |
|---|
| 108 | { |
|---|
| 109 | int i, min, j , x; |
|---|
| 110 | puts("Selection Sort\n"); |
|---|
| 111 | |
|---|
| 112 | for(i = 0 ; i < n - 1 ; i++) |
|---|
| 113 | { |
|---|
| 114 | |
|---|
| 115 | putchar('-'); // added for debug |
|---|
| 116 | |
|---|
| 117 | min = i; |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | for(j = i+1 ; j < n ; j++) |
|---|
| 121 | { |
|---|
| 122 | |
|---|
| 123 | if(base[j] < base[min]) |
|---|
| 124 | min = j; |
|---|
| 125 | |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | if(min != i) |
|---|
| 129 | { |
|---|
| 130 | x = base[i]; |
|---|
| 131 | base[i] = base[min]; |
|---|
| 132 | base[min] = x; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | putchar('+'); // added for debug |
|---|
| 136 | |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | //------------------------------- |
|---|
| 140 | void bubble_sort(int *base, int n) |
|---|
| 141 | { |
|---|
| 142 | int i = 0; /* Indice de répétition du tri */ |
|---|
| 143 | int j = 0; /* Variable de boucle */ |
|---|
| 144 | int tmp = 0; /* Variable de stockage temporaire */ |
|---|
| 145 | int en_desordre = 1; /* Booléen marquant l'arrêt du tri si le tableau est ordonné */ |
|---|
| 146 | |
|---|
| 147 | puts("Bubble Sort\n"); |
|---|
| 148 | |
|---|
| 149 | /* Boucle de répétition du tri et le test qui arrête le tri dès que le tableau est ordonné */ |
|---|
| 150 | for(i = 0 ; (i < n) && en_desordre; i++) |
|---|
| 151 | { |
|---|
| 152 | putchar('-'); // added for debug |
|---|
| 153 | |
|---|
| 154 | /* Supposons le tableau ordonné */ |
|---|
| 155 | en_desordre = 0; |
|---|
| 156 | /* Vérification des éléments des places j et j-1 */ |
|---|
| 157 | for(j = 1 ; j < n - i ; j++) |
|---|
| 158 | { |
|---|
| 159 | /* Si les 2 éléments sont mal triés */ |
|---|
| 160 | if(base[j] < base[j-1]) |
|---|
| 161 | { |
|---|
| 162 | /* Inversion des 2 éléments */ |
|---|
| 163 | tmp = base[j-1]; |
|---|
| 164 | base[j-1] = base[j]; |
|---|
| 165 | base[j] = tmp; |
|---|
| 166 | |
|---|
| 167 | /* Le tableau n'est toujours pas trié */ |
|---|
| 168 | en_desordre = 1; |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | putchar('+'); // added for debug |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | } |
|---|
| 176 | //------------------------------- |
|---|
| 177 | void quick_sort(int *base, int n) |
|---|
| 178 | {} |
|---|
| 179 | |
|---|
| 180 | //-------------------------------------*/ |
|---|
| 181 | void SORT(int *base, int n, int type) |
|---|
| 182 | { |
|---|
| 183 | switch(type) |
|---|
| 184 | { |
|---|
| 185 | case 0: |
|---|
| 186 | quick_sort(base, n); |
|---|
| 187 | break; |
|---|
| 188 | case 1: |
|---|
| 189 | selection_sort(base, n); |
|---|
| 190 | break; |
|---|
| 191 | case 2: |
|---|
| 192 | insertion_sort(base, n); |
|---|
| 193 | break; |
|---|
| 194 | case 3: |
|---|
| 195 | bubble_sort(base, n); |
|---|
| 196 | break; |
|---|
| 197 | default: |
|---|
| 198 | break; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | |
|---|