summaryrefslogtreecommitdiffstats
path: root/dis/Matrix/ver1/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'dis/Matrix/ver1/matrix.c')
-rwxr-xr-xdis/Matrix/ver1/matrix.c600
1 files changed, 600 insertions, 0 deletions
diff --git a/dis/Matrix/ver1/matrix.c b/dis/Matrix/ver1/matrix.c
new file mode 100755
index 0000000..518a638
--- /dev/null
+++ b/dis/Matrix/ver1/matrix.c
@@ -0,0 +1,600 @@
1/*
2 * Sample code for the DIS Matrix 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/*
17 * The Sparse Matrix Storage is implemented by Compact Row Storage Scheme
18 * In the code, the data is first generated by randomNonzeroFloat()
19 * the data is first stored in a full-space matrix with size of dim*dim
20 * then the data is transfered to the Compact Row Matrix,
21 * the data value is kept in *value,
22 * the columns corresponding to the value are stored in *col_ind,
23 * the start element of each row is stored in *row_start.
24 */
25
26/*
27 * Please note:
28 * the total number of data is numberNonzero +dim
29 * among which, NumberNonzero because this is symmetric matrix
30 * dim because the diagonal elements
31 */
32
33#include <stdio.h>
34#include <math.h>
35#include <stdlib.h>
36#include <time.h>
37#include <assert.h>
38#include "DISstressmarkRNG.h"
39
40#define MIN_SEED -2147483647
41#define MAX_SEED -1
42#define MIN_DIM 1
43#define MAX_DIM 32768
44#define MAX_ITERATIONS 65536
45#define MIN_TOLERANCE 0.000007
46#define MAX_TOLERANCE 0.5
47#define MIN_NUMBER -3.4e10/dim
48#define MAX_NUMBER 3.4e10/dim
49#define EPSI 1.0e-10
50#define MIN_DIG_NUMBER 1.0e-10
51#define MAX_DIG_NUMBER 3.4e10
52
53/*
54 * External variable, dimension
55 */
56
57static int dim;
58
59/*
60 * matrix * vector
61 */
62
63double *matrixMulvector(double *value,
64 int *col_ind,
65 int *row_start,
66 double *vector)
67{
68 int l, ll;
69 double *out;
70 double sum;
71 int tmp_rs, tmp_re;
72
73 out = (double *)malloc(dim*sizeof(double));
74
75 for (l=0; l<dim; l++){
76 *(out + l) = 0;
77 tmp_rs = row_start[l];
78
79 if (tmp_rs != -1){
80 tmp_re = row_start[l+1]; /*
81 *get the start and ending elements of
82 * each row
83 */
84 for (ll=tmp_rs; ll<tmp_re; ll++){
85 *(out + l) += value[ll]*vector[col_ind[ll]];
86 }
87 }
88 }
89 return out;
90}
91
92
93/*
94 * vector1 - vector2
95 */
96
97double *vectorSub(double *vector1, double *vector2){
98
99 int l;
100 double *vector;
101 vector = (double *)malloc(dim*sizeof(double ));
102 for (l=0; l<dim; l++){
103 *(vector + l) = *(vector1 + l) - *(vector2 + l);
104 }
105 return vector;
106}
107
108
109/*
110 * vector1 + vector2
111 */
112
113double *vectorAdd(double *vector1, double *vector2){
114
115 int l;
116 double *vector;
117
118 vector = (double *)malloc(dim*sizeof(double ));
119
120 for (l=0; l<dim; l++){
121 *(vector + l) = *(vector1 + l) + *(vector2 + l);
122 }
123 return vector;
124}
125
126/*
127 * vector1 * vector2
128 */
129
130double vectorMul(double *vector1, double *vector2){
131
132 int l;
133 double product;
134
135 product = 0;
136
137 for (l=0; l<dim; l++){
138 product += (*(vector1 + l))*(*(vector2 + l));
139
140 }
141 return product;
142}
143
144/*
145 * /vector/
146 */
147
148double vectorValue(double *vector){
149
150 double value;
151 int l;
152
153 value = 0;
154
155 for (l=0; l<dim; l++){
156 value += (*(vector + l)) * (*(vector + l));
157 }
158
159 return (sqrt(value));
160}
161
162/*
163 * transpose(vector)
164 * In fact, we return the original vector here
165 */
166
167double *transpose(double *vector){
168
169 double *vect;
170 int l;
171
172 vect = (double *)malloc(dim*sizeof(double ));
173
174 for (l=0; l<dim; l++){
175 *(vect+l) = *(vector+l);
176 }
177 return vect;
178}
179
180/*
181 * value * <vector>
182 */
183double *valueMulvector(double value, double *vector){
184
185 int l;
186 double *vect;
187 int lll;
188 double sum;
189
190 vect = (double *) malloc(dim * sizeof(double ));
191
192 for (l=0; l<dim; l++){
193 *(vect + l) = (*(vector + l)) * value;
194 }
195
196 return vect;
197}
198
199/*
200 * generate the data distributed sparsely in matrix
201 */
202
203void initMatrix(double *matrix, int dim, int numberNonzero){
204
205 int k, l, ll;
206 int i, j;
207
208 int lll;
209 double sum;
210
211 for (k=0; k< dim*dim; k++){
212 *(matrix + k) = 0;
213 }
214
215 for (l=0; l<numberNonzero/2; l++){
216
217 i = randomUInt(1, dim-1);
218 j = randomUInt(0, i-1);
219