[3] | 1 | #include "system.h" |
---|
| 2 | #include "stdio.h" |
---|
| 3 | #include "stdlib.h" |
---|
[85] | 4 | //#include "matrice.h" |
---|
[3] | 5 | |
---|
| 6 | #include "../segmentation.h" |
---|
| 7 | |
---|
[85] | 8 | #define NPROCS 1 |
---|
| 9 | #define SIZE 50 |
---|
[3] | 10 | #define SORT_TYPE 0 // shellSort |
---|
| 11 | |
---|
| 12 | volatile int nprocs=NPROCS; |
---|
| 13 | |
---|
[85] | 14 | |
---|
[3] | 15 | unsigned int gQSortNum0[200] = { |
---|
| 16 | 251, 24, 113, 170, 215, 60, 83, 30, 115, 48, 169, 210, 49, 92, 101, 58, 21, 184, 225, 6, |
---|
| 17 | 199, 244, 227, 146, 99, 96, 25, 222, 65, 140, 213, 22, 219, 136, 175, 182, 73, 36, 141, 190, |
---|
| 18 | 83, 112, 137, 114, 175, 188, 187, 102, 53, 168, 193, 154, 167, 172, 3, 242, 67, 64, 144, 137, |
---|
| 19 | 142, 175, 188, 69, 102, 53, 168, 193, 102, 89, 172, 253, 242, 67, 192, 7, 62, 159, 20, 181, |
---|
| 20 | 182, 187, 216, 207, 22, 105, 132, 109, 162, 205, 16, 151, 18, 113, 228, 37, 6, 85, 8, 161, |
---|
| 21 | 58, 135, 76, 35, 174, 35, 224, 39, 158, 127, 180, 149, 86, 155, 200, 239, 118, 119, 28, 77, |
---|
| 22 | 254, 19, 176, 183, 78, 145, 132, 5, 90, 117, 152, 127, 218, 153, 20, 67, 178, 3, 128, 185, |
---|
| 23 | 254, 95, 172, 139, 246, 123, 104, 15, 42, 169, 68, 211, 98, 243, 80, 41, 174, 79, 36, 27, |
---|
| 24 | 186, 149, 86, 155, 200, 239, 118, 119, 28, 77, 254, 19, 176, 183, 78, 145, 132, 5, 90, 117, |
---|
| 25 | 152, 127, 218, 153, 20, 67, 178, 3, 128, 185, 254, 95, 172, 139, 246, 123, 104, 15, 42, 169 }; |
---|
| 26 | |
---|
| 27 | |
---|
[85] | 28 | unsigned int SortArr0[NPROCS*(SIZE+50)]; |
---|
| 29 | |
---|
[3] | 30 | void shellSortPhase(unsigned int a[],unsigned int length, int gap); |
---|
| 31 | void shellSort(unsigned int *base, unsigned int n); // type 0 |
---|
| 32 | |
---|
| 33 | int main() |
---|
| 34 | { |
---|
| 35 | register int p; |
---|
| 36 | |
---|
| 37 | int beg_cycle, end_cycle; |
---|
| 38 | |
---|
| 39 | beg_cycle = cpu_cycles(); |
---|
| 40 | |
---|
| 41 | p=procnum(); |
---|
| 42 | |
---|
| 43 | puts("Hello from processor "); |
---|
| 44 | putchar(p+'0'); |
---|
| 45 | putchar('\n'); |
---|
| 46 | |
---|
| 47 | int i; |
---|
| 48 | int j; |
---|
| 49 | unsigned int* SortArray; |
---|
| 50 | |
---|
| 51 | if(p+1 <= nprocs) |
---|
| 52 | { |
---|
| 53 | i=1; |
---|
| 54 | puts("Memory copy \n"); |
---|
[85] | 55 | SortArray = SortArr0 + p*(SIZE+50); |
---|
[3] | 56 | memcpy(SortArray, gQSortNum0 + p*SIZE,SIZE*4); |
---|
| 57 | |
---|
| 58 | puts("Sort... \n"); |
---|
[85] | 59 | shellSort((unsigned int *) (SortArray), (unsigned int) SIZE); |
---|
[3] | 60 | |
---|
| 61 | for (j = 1; j < SIZE; j++) |
---|
| 62 | { |
---|
| 63 | if (SortArray[j] < SortArray[j-1]) |
---|
| 64 | { |
---|
| 65 | puts("ucbqsort: failed\n"); |
---|
| 66 | while(1); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | puts("ucbqsort: success\n"); |
---|
| 72 | end_cycle = cpu_cycles(); |
---|
| 73 | // printf( "nombre cycles cpu : %i\n", end_cycle-beg_cycle); |
---|
| 74 | printf( "begin time : %i\n", beg_cycle); |
---|
| 75 | printf( "end time : %i\n", end_cycle); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | while(1); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | //------------------------------------------------------ |
---|
| 83 | /* |
---|
| 84 | * Exécute un tri par insertion avec la séparation donnée |
---|
| 85 | * If gap == 1, on fait un tri ordinaire. |
---|
| 86 | * If gap >= length, on ne fait rien. |
---|
| 87 | */ |
---|
| 88 | void shellSortPhase(unsigned int a[],unsigned int length, int gap) { |
---|
| 89 | int i; |
---|
| 90 | |
---|
| 91 | puti(gap); |
---|
| 92 | for (i = gap; i < length; ++i) { |
---|
| 93 | unsigned int value = a[i]; |
---|
| 94 | int j; |
---|
| 95 | for (j = i - gap; j >= 0 && a[j] > value; j -= gap) { |
---|
| 96 | putchar('+'); |
---|
| 97 | a[j + gap] = a[j]; |
---|
| 98 | putchar('-'); |
---|
| 99 | } |
---|
| 100 | a[j + gap] = value; |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | void shellSort(unsigned int *base, unsigned int n) { |
---|
| 105 | /* |
---|
| 106 | * gaps[] doit approximer une Série géométrique. |
---|
| 107 | * La sequence suivante est la meilleure connue en terme |
---|
| 108 | * de nombre moyen de comparaisons. voir: |
---|
| 109 | * http://www.research.att.com/~njas/sequences/A102549 |
---|
| 110 | */ |
---|
| 111 | static const int gaps[] = { |
---|
| 112 | 1, 4, 10, 23, 57, 132, 301, 701 |
---|
| 113 | }; |
---|
| 114 | int sizeIndex; |
---|
| 115 | |
---|
| 116 | puts("Shell Sort\n"); |
---|
| 117 | for (sizeIndex = sizeof(gaps)/sizeof(gaps[0]) - 1; |
---|
| 118 | sizeIndex >= 0; |
---|
| 119 | --sizeIndex) |
---|
| 120 | shellSortPhase(base, n, gaps[sizeIndex]); |
---|
| 121 | } |
---|
| 122 | |
---|