diff options
Diffstat (limited to 'dis/original/Matrix/ver2/matrix.c')
| -rwxr-xr-x | dis/original/Matrix/ver2/matrix.c | 586 |
1 files changed, 586 insertions, 0 deletions
diff --git a/dis/original/Matrix/ver2/matrix.c b/dis/original/Matrix/ver2/matrix.c new file mode 100755 index 0000000..56245a6 --- /dev/null +++ b/dis/original/Matrix/ver2/matrix.c | |||
| @@ -0,0 +1,586 @@ | |||
| 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 | |||
| 45 | #define MIN_SEED -2147483647 | ||
| 46 | #define MAX_SEED -1 | ||
| 47 | #define MIN_DIM 1 | ||
| 48 | #define MAX_DIM 32768 | ||
| 49 | #define MAX_ITERATIONS 65536 | ||
| 50 | #define MIN_TOLERANCE 0.000007 | ||
| 51 | #define MAX_TOLERANCE 0.5 | ||
| 52 | #define MIN_NUMBER -3.4e10/dim | ||
| 53 | #define MAX_NUMBER 3.4e10/dim | ||
| 54 | #define EPSI 1.0e-10 | ||
| 55 | #define MIN_DIG_NUMBER 1.0e-10 | ||
| 56 | #define MAX_DIG_NUMBER 3.4e10 | ||
| 57 | |||
| 58 | /* | ||
| 59 | * External variable, dimension | ||
| 60 | */ | ||
| 61 | |||
| 62 | static int dim; | ||
| 63 | |||
| 64 | /* | ||
| 65 | * matrix * vector | ||
| 66 | */ | ||
| 67 | |||
| 68 | void matrixMulvector(double *value, | ||
| 69 | int *col_ind, | ||
| 70 | int *row_start, | ||
| 71 | double *vector, | ||
| 72 | double *out) | ||
| 73 | { | ||
| 74 | int l, ll; | ||
| 75 | double sum; | ||
| 76 | int tmp_rs, tmp_re; | ||
| 77 | |||
| 78 | for (l=0; l<dim; l++){ | ||
| 79 | *(out + l) = 0; | ||
| 80 | tmp_rs = row_start[l]; | ||
| 81 | |||
| 82 | if (tmp_rs != -1){ | ||
| 83 | tmp_re = row_start[l+1]; /* | ||
| 84 | *get the start and ending elements of | ||
| 85 | * each row | ||
| 86 | */ | ||
| 87 | for (ll=tmp_rs; ll<tmp_re; ll++){ | ||
| 88 | *(out + l) += value[ll]*vector[col_ind[ll]]; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
| 92 | return; | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | /* | ||
| 97 | * vector1 - vector2 | ||
| 98 | */ | ||
| 99 | |||
| 100 | void vectorSub(double *vector1, double *vector2, double *vector){ | ||
| 101 | |||
| 102 | int l; | ||
| 103 | |||
| 104 | for (l=0; l<dim; l++){ | ||
| 105 | *(vector + l) = *(vector1 + l) - *(vector2 + l); | ||
| 106 | } | ||
| 107 | return; | ||
| 108 | } | ||
| 109 | |||
| 110 | |||
| 111 | /* | ||
| 112 | * vector1 + vector2 | ||
| 113 | */ | ||
| 114 | |||
| 115 | void vectorAdd(double *vector1, double *vector2, double *vector){ | ||
| 116 | |||
| 117 | int l; | ||
| 118 | |||
| 119 | for (l=0; l<dim; l++){ | ||
| 120 | *(vector + l) = *(vector1 + l) + *(vector2 + l); | ||
| 121 | } | ||
| 122 | return; | ||
| 123 | } | ||
| 124 | |||
| 125 | /* | ||
| 126 | * vector1 * vector2 | ||
| 127 | */ | ||
| 128 | |||
| 129 | double vectorMul(double *vector1, double *vector2){ | ||
| 130 | |||
| 131 | int l; | ||
| 132 | double product; | ||
| 133 | |||
| 134 | product = 0; | ||
| 135 | |||
| 136 | for (l=0; l<dim; l++){ | ||
| 137 | product += (*(vector1 + l))*(*(vector2 + l)); | ||
| 138 | |||
| 139 | } | ||
| 140 | return product; | ||
| 141 | } | ||
| 142 | |||
| 143 | /* | ||
| 144 | * /vector/ | ||
| 145 | */ | ||
| 146 | |||
| 147 | double vectorValue(double *vector){ | ||
| 148 | |||
| 149 | double value; | ||
| 150 | int l; | ||
| 151 | |||
| 152 | value = 0; | ||
| 153 | |||
| 154 | for (l=0; l<dim; l++){ | ||
| 155 | value += (*(vector + l)) * (*(vector + l)); | ||
| 156 | } | ||
| 157 | |||
| 158 | return (sqrt(value)); | ||
| 159 | } | ||
| 160 | |||
| 161 | /* | ||
| 162 | * transpose(vector) | ||
| 163 | * In fact, we return the original vector here | ||
| 164 | */ | ||
| 165 | |||
| 166 | void transpose(double *vector, double *vect){ | ||
| 167 | |||
| 168 | int l; | ||
| 169 | |||
| 170 | for (l=0; l<dim; l++){ | ||
| 171 | *(vect+l) = *(vector+l); | ||
| 172 | } | ||
| 173 | return; | ||
| 174 | } | ||
| 175 | |||
| 176 | /* | ||
| 177 | * value * <vector> | ||
| 178 | */ | ||
| 179 | void valueMulvector(double value, double *vector, double *vect){ | ||
| 180 | |||
| 181 | int l; | ||
| 182 | int lll, i; | ||
| 183 | double tmp; | ||
| 184 | |||
| 185 | for (l=0; l<dim; l++){ | ||
| 186 | *(vect + l) = *(vector + l) * value; | ||
| 187 | } | ||
| 188 | return; | ||
| 189 | } | ||
| 190 | |||
| 191 | /* | ||
| 192 | * generate the data distributed sparsely in matrix | ||
| 193 | */ | ||
| 194 | |||
| 195 | void initMatrix(double *matrix, int dim, int numberNonzero){ | ||
| 196 | |||
| 197 | int k, l, ll; | ||
| 198 | int i, j; | ||
| 199 | |||
| 200 | int lll; | ||
| 201 | double sum; | ||
| 202 | |||
| 203 | for (k=0; k< dim*dim; k++){ | ||
| 204 | *(matrix + k) = 0; | ||
| 205 | } | ||
| 206 | |||
| 207 | for (l=0; l<numberNonzero/2; l++){ | ||
| 208 | |||
| 209 | i = randomUInt(1, dim-1); | ||
| 210 | j = randomUInt(0, i-1); | ||
