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