summaryrefslogtreecommitdiffstats
path: root/dis/Matrix/ver2/matrix.c
diff options
context:
space:
mode:
authorJoshua Bakita <jbakita@cs.unc.edu>2020-10-16 16:55:14 -0400
committerJoshua Bakita <jbakita@cs.unc.edu>2020-10-16 16:55:14 -0400
commit6ea9939e0610a809f6f47d13ec68df00d1ca0afc (patch)
treefe4a2eee3ddcf77e2367309dcd75a232b76dcd62 /dis/Matrix/ver2/matrix.c
parente9285d0cdea756a2830f0ace378e4197b36869aa (diff)
Move the DIS benchmarks up a directory and update hardcoded paths
Note that this repo does not attempt to keep a copy of the original DIS benchmark distributions. UNC real-time has another repo for that.
Diffstat (limited to 'dis/Matrix/ver2/matrix.c')
-rwxr-xr-xdis/Matrix/ver2/matrix.c594
1 files changed, 594 insertions, 0 deletions
diff --git a/dis/Matrix/ver2/matrix.c b/dis/Matrix/ver2/matrix.c
new file mode 100755
index 0000000..957d7c5
--- /dev/null
+++ b/dis/Matrix/ver2/matrix.c
@@ -0,0 +1,594 @@
1/* Please note:
2 * This code is the optimized version of the first version of Matrix
3 * Stressmark. It uses less temporary vectors and vsariables, thus reduce
4 * memory allocation/deallocation overhead. the simulation is faster
5 */
6/*
7 * Sample code for the DIS Matrix Stressmark
8 *
9 * This source code is the completely correct source code based on
10 * the example codes provided by Atlantic Aerospace Division, Titan
11 * Systems Corporation, 2000.
12 *
13 * If you just compile and generate the executables from this source
14 * code, this code would be enough. However, if you wish to get a complete
15 * understanding of this stressmark, it is strongly suggested that you
16 * read the Benchmark Analysis and Specifications Document Version 1.0
17 * before going on since the detailed comments are given in this documents.
18 * the comments are not repeated here.
19 */
20
21/*
22 * The Sparse Matrix Storage is implemented by Compact Row Storage Scheme
23 * In the code, the data is first generated by randomNonzeroFloat()
24 * the data is first stored in a full-space matrix with size of dim*dim
25 * then the data is transfered to the Compact Row Matrix,
26 * the data value is kept in *value,
27 * the columns corresponding to the value are stored in *col_ind,
28 * the start element of each row is stored in *row_start.
29 */
30
31/*
32 * Please note:
33 * the total number of data is numberNonzero +dim
34 * among which, NumberNonzero because this is symmetric matrix
35 * dim because the diagonal elements
36 */
37
38#include <stdio.h>
39#include <math.h>
40#include <stdlib.h>
41#include <time.h>
42#include <assert.h>
43#include "DISstressmarkRNG.h"
44#include "extra.h"
45
46#define MIN_SEED -2147483647
47#define MAX_SEED -1
48#define MIN_DIM 1
49#define MAX_DIM 32768
50#define MAX_ITERATIONS 65536
51#define MIN_TOLERANCE 0.000007
52#define MAX_TOLERANCE 0.5
53#define MIN_NUMBER -3.4e10/dim
54#define MAX_NUMBER 3.4e10/dim
55#define EPSI 1.0e-10
56#define MIN_DIG_NUMBER 1.0e-10
57#define MAX_DIG_NUMBER 3.4e10
58
59/*
60 * External variable, dimension
61 */
62
63static int dim;
64int argc;
65char** argv;
66
67/*
68 * matrix * vector
69 */
70
71void matrixMulvector(double *value,
72 int *col_ind,
73 int *row_start,
74 double *vector,
75 double *out)
76{
77 int l, ll;
78 double sum;
79 int tmp_rs, tmp_re;
80
81 for (l=0; l<dim; l++){
82 *(out + l) = 0;
83 tmp_rs = row_start[l];
84
85 if (tmp_rs != -1){
86 tmp_re = row_start[l+1]; /*
87 *get the start and ending elements of
88 * each row
89 */
90 for (ll=tmp_rs; ll<tmp_re; ll++){
91 *(out + l) += value[ll]*vector[col_ind[ll]];
92 }
93 }
94 }
95 return;
96}
97
98
99/*
100 * vector1 - vector2
101 */
102
103void vectorSub(double *vector1, double *vector2, double *vector){
104
105 int l;
106
107 for (l=0; l<dim; l++){
108 *(vector + l) = *(vector1 + l) - *(vector2 + l);
109 }
110 return;
111}
112
113
114/*
115 * vector1 + vector2
116 */
117
118void vectorAdd(double *vector1, double *vector2, double *vector){
119
120 int l;
121
122 for (l=0; l<dim; l++){
123 *(vector + l) = *(vector1 + l) + *(vector2 + l);
124 }
125 return;
126}
127
128/*
129 * vector1 * vector2
130 */
131
132double vectorMul(double *vector1, double *vector2){
133
134 int l;
135 double product;
136
137 product = 0;
138
139 for (l=0; l<dim; l++){
140 product += (*(vector1 + l))*(*(vector2 + l));
141
142 }
143 return product;
144}
145
146/*
147 * /vector/
148 */
149
150double vectorValue(double *vector){
151
152 double value;
153 int l;
154
155 value = 0;
156
157 for (l=0; l<dim; l++){
158 value += (*(vector + l)) * (*(vector + l));
159 }
160
161 return (sqrt(value));
162}
163
164/*
165 * transpose(vector)
166 * In fact, we return the original vector here
167 */
168
169void transpose(double *vector, double *vect){
170
171 int l;
172
173 for (l=0; l<dim; l++){
174 *(vect+l) = *(vector+l);
175 }
176 return;
177}
178
179/*
180 * value * <vector>
181 */
182void valueMulvector(double value, double *vector, double *vect){
183
184 int l;
185 int lll, i;
186 double tmp;
187
188 for (l=0; l<dim; l++){
189 *(vect + l) = *(vector + l) * value;
190 }
191 return;
192}
193
194/*
195 * generate the data distributed sparsely in matrix
196 */
197
198void initMatrix(double *matrix, int dim, int numberNonzero){
199
200 int k, l, ll;
201 int i, j;
202
203 int lll;
204 double sum;
205
206 for (k=0; k< dim*dim; k++){
207 *(matrix + k) = 0;
208 }
209
210 for (l=0; l<numberNonzero/2; l++){
211
212 i = randomUInt(1, dim-1);
213 j = randomUInt(0, i-1);
</