diff options
Diffstat (limited to 'dis/Transitive/transitive.c')
| -rw-r--r-- | dis/Transitive/transitive.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/dis/Transitive/transitive.c b/dis/Transitive/transitive.c new file mode 100644 index 0000000..5fa52e8 --- /dev/null +++ b/dis/Transitive/transitive.c | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* | ||
| 2 | * Sample code for the DIS Transitive Stressmark | ||
| 3 | * | ||
| 4 | * This source code is the completely correct source code based on | ||
| 5 | * the example codes provided by Atlantic Aerospace Division, Titan | ||
| 6 | * Systems Corporation, 2000. | ||
| 7 | * | ||
| 8 | * If you just compile and generate the executables from this source | ||
| 9 | * code, this code would be enough. However, if you wish to get a complete | ||
| 10 | * understanding of this stressmark, it is strongly suggested that you | ||
| 11 | * read the Benchmark Analysis and Specifications Document Version 1.0 | ||
| 12 | * before going on since the detailed comments are given in this documents. | ||
| 13 | * the comments are not repeated here. | ||
| 14 | * | ||
| 15 | * CHANGELOG: | ||
| 16 | * Joshua Bakita, 05/30/2020: Fixed out-of-bounds randInt call | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <stdio.h> | ||
| 20 | #include <time.h> | ||
| 21 | #include <assert.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include "DISstressmarkRNG.h" | ||
| 24 | #include "extra.h" | ||
| 25 | |||
| 26 | #define MIN_VERTICES 8 | ||
| 27 | #define MAX_VERTICES 16384 | ||
| 28 | #define MIN_EDGES 0 | ||
| 29 | #define MAX_EDGES 268435456 | ||
| 30 | #define MIN_SEED -2147483647 | ||
| 31 | #define MAX_SEED -1 | ||
| 32 | #define NO_PATH 2147483647 | ||
| 33 | |||
| 34 | #define MIN_EDGS 0 | ||
| 35 | #define MAX_EDGE 255 | ||
| 36 | |||
| 37 | /* | ||
| 38 | * main() | ||
| 39 | */ | ||
| 40 | |||
| 41 | int main(int argc, char** argv){ | ||
| 42 | unsigned int *din, *dout; | ||
| 43 | unsigned int n; | ||
| 44 | unsigned int m; | ||
| 45 | unsigned int i, j, k; | ||
| 46 | int seed; | ||
| 47 | |||
| 48 | time_t startTime; | ||
| 49 | unsigned int sum; | ||
| 50 | |||
| 51 | fscanf(stdin,"%d %d %d", &n, &m, &seed); | ||
| 52 | |||
| 53 | assert((n >= MIN_VERTICES) && (n <= MAX_VERTICES)); | ||
| 54 | assert((m >= MIN_EDGES) && (m <= MAX_EDGES)); | ||
| 55 | assert (m <= n*n); | ||
| 56 | assert ((seed >= MIN_SEED) && (seed <= MAX_SEED)); | ||
| 57 | |||
| 58 | if ((din = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) | ||
| 59 | return (-1); | ||
| 60 | if ((dout = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) | ||
| 61 | return (-1); | ||
| 62 | |||
| 63 | for (i=0; i<n*n; i++){ | ||
| 64 | *(din + i) = NO_PATH; | ||
| 65 | *(dout + i) = NO_PATH; | ||
| 66 | } | ||
| 67 | |||
| 68 | randInit(seed); | ||
| 69 | for (k=0; k<m; k++){ | ||
| 70 | i = randInt(0, n-1); | ||
| 71 | j = randInt(0, n-1); | ||
| 72 | *(din + j*n + i) = randInt(MIN_EDGES, MAX_EDGES); | ||
| 73 | } | ||
| 74 | |||
| 75 | SET_UP | ||
| 76 | startTime = time(NULL); | ||
| 77 | |||
| 78 | for (k=0; k<n; k++){ | ||
| 79 | unsigned int old; | ||
| 80 | unsigned int new1; | ||
| 81 | unsigned int *dtemp; | ||
| 82 | START_LOOP | ||
| 83 | |||
| 84 | for (i=0; i<n; i++){ | ||
| 85 | for (j=0; j<n; j++){ | ||
| 86 | old = *(din + j*n + i); | ||
| 87 | new1 = *(din + j*n + k) + *(din + k*n + i); | ||
| 88 | *(dout + j*n + i) = (new1 < old ? new1: old); | ||
| 89 | assert (*(dout + j*n + i) <= NO_PATH); | ||
| 90 | assert (*(dout + j*n + i) <= *(din + j*n + i)); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | dtemp = dout; | ||
| 94 | dout = din; | ||
| 95 | din = dtemp; | ||
| 96 | STOP_LOOP | ||
| 97 | } | ||
| 98 | |||
| 99 | startTime = time(NULL) - startTime; | ||
| 100 | |||
| 101 | for (j=0; j<n; j++){ | ||
| 102 | sum = 0; | ||
| 103 | for (i=0; i<n; i++){ | ||
| 104 | if (*(din + j*n + i) != NO_PATH) | ||
| 105 | sum += *(din + j*n + i); | ||
| 106 | } | ||
| 107 | fprintf(stdout, "%u\n", sum); | ||
| 108 | } | ||
| 109 | for (i=0; i<n; i++){ | ||
| 110 | sum = 0; | ||
| 111 | for (j=0; j<n; j++){ | ||
| 112 | if (*(din + j*n + i) != NO_PATH) | ||
| 113 | sum += *(din+j*n+i); | ||
| 114 | } | ||
| 115 | |||
| 116 | fprintf(stdout, "%u\n", sum); | ||
| 117 | } | ||
| 118 | |||
| 119 | fprintf(stdout, " total time = %u seconds. \n", (unsigned int)startTime); | ||
| 120 | free(din); | ||
| 121 | free(dout); | ||
| 122 | WRITE_TO_FILE | ||
| 123 | return(0); | ||
| 124 | } | ||
| 125 | |||
| 126 | |||
| 127 | |||
| 128 | |||
| 129 | |||
| 130 | |||
| 131 | |||
