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