summaryrefslogtreecommitdiffstats
path: root/dis/original/Transitive/transitive.c
diff options
context:
space:
mode:
Diffstat (limited to 'dis/original/Transitive/transitive.c')
-rw-r--r--dis/original/Transitive/transitive.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/dis/original/Transitive/transitive.c b/dis/original/Transitive/transitive.c
new file mode 100644
index 0000000..854d57c
--- /dev/null
+++ b/dis/original/Transitive/transitive.c
@@ -0,0 +1,123 @@
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
16#include <stdio.h>
17#include <time.h>
18#include <assert.h>
19#include <stdlib.h>
20#include "DISstressmarkRNG.h"
21
22#define MIN_VERTICES 8
23#define MAX_VERTICES 16384
24#define MIN_EDGES 0
25#define MAX_EDGES 268435456
26#define MIN_SEED -2147483647
27#define MAX_SEED -1
28#define NO_PATH 2147483647
29
30#define MIN_EDGS 0
31#define MAX_EDGE 255
32
33/*
34 * main()
35 */
36
37int main(){
38 unsigned int *din, *dout;
39 unsigned int n;
40 unsigned int m;
41 unsigned int i, j, k;
42 int seed;
43
44 time_t startTime;
45 unsigned int sum;
46
47 fscanf(stdin,"%d %d %d", &n, &m, &seed);
48
49 assert((n >= MIN_VERTICES) && (n <= MAX_VERTICES));
50 assert((m >= MIN_EDGES) && (m <= MAX_EDGES));
51 assert (m <= n*n);
52 assert ((seed >= MIN_SEED) && (seed <= MAX_SEED));
53
54 if ((din = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL)
55 return (-1);
56 if ((dout = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL)
57 return (-1);
58
59 for (i=0; i<n*n; i++){
60 *(din + i) = NO_PATH;
61 *(dout + i) = NO_PATH;
62 }
63
64 randInit(seed);
65 for (k=0; k<m; k++){
66 i = randInt(0, n);
67 j = randInt(0, n);
68 *(din + j*n + i) = randInt(MIN_EDGES, MAX_EDGES);
69 }
70
71 startTime = time(NULL);
72
73 for (k=0; k<n; k++){
74 unsigned int old;
75 unsigned int new1;
76 unsigned int *dtemp;
77
78 for (i=0; i<n; i++){
79 for (j=0; j<n; j++){
80 old = *(din + j*n + i);
81 new1 = *(din + j*n + k) + *(din + k*n + i);
82 *(dout + j*n + i) = (new1 < old ? new1: old);
83 assert (*(dout + j*n + i) <= NO_PATH);
84 assert (*(dout + j*n + i) <= *(din + j*n + i));
85 }
86 }
87 dtemp = dout;
88 dout = din;
89 din = dtemp;
90 }
91
92 startTime = time(NULL) - startTime;
93
94 for (j=0; j<n; j++){
95 sum = 0;
96 for (i=0; i<n; i++){
97 if (*(din + j*n + i) != NO_PATH)
98 sum += *(din + j*n + i);
99 }
100 fprintf(stdout, "%u\n", sum);
101 }
102 for (i=0; i<n; i++){
103 sum = 0;
104 for (j=0; j<n; j++){
105 if (*(din + j*n + i) != NO_PATH)
106 sum += *(din+j*n+i);
107 }
108
109 fprintf(stdout, "%u\n", sum);
110 }
111
112 fprintf(stdout, " total time = %u seconds. \n", (unsigned int)startTime);
113 free(din);
114 free(dout);
115 return(0);
116 }
117
118
119
120
121
122
123