Newer
Older
Marco van Oort
committed
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
#include "SparseMatrix.h"
int main(int argc, char **argv) {
char filenameI[MAX_WORD_LENGTH], filenameA[MAX_WORD_LENGTH];
struct sparsematrix A, I, M;
long nz, s, t, p, P, *usedI, *usedA, matchI, matchA, found;
FILE *fp;
printf("Test MMReadSparseMatrixFromIndexAndValueMatrixFiles: ");
/* Check sorting in general */
strcpy(filenameA,"test_MMReadSparseMatrixFromIndexAndValueMatrixFilesA.inp");
fp = fopen(filenameA, "r");
MMReadSparseMatrix(fp, &A);
fclose(fp);
strcpy(filenameI,"test_MMReadSparseMatrixFromIndexAndValueMatrixFilesI.inp");
fp = fopen(filenameI, "r");
MMReadSparseMatrix(fp, &I);
fclose(fp);
nz = 12;
P = 2;
/* Use values as processor numbers */
if (!MMReadSparseMatrixFromIndexAndValueMatrixFiles(filenameA, filenameI, &M)) {
printf("Error!\n");
exit(1);
}
usedI = (long *) malloc(nz * sizeof(long));
usedA = (long *) malloc(nz * sizeof(long));
for(s=0; s<nz; s++) {
usedI[s] = 0;
usedA[s] = 0;
}
matchI = matchA = 0;
for(p=1; p<=P; p++) {
for(t=M.Pstart[p-1]; t<M.Pstart[p]; t++) {
found = 0;
for(s=0; s<nz; s++) {
if(usedI[s] == 0 && M.i[t] == I.i[s] && M.j[t] == I.j[s] && (long)I.ReValue[s]+1 == p) {
matchI++;
usedI[s] = 1;
found++;
break;
}
}
for(s=0; s<nz; s++) {
if(usedA[s] == 0 && M.i[t] == A.i[s] && M.j[t] == A.j[s] && M.ReValue[t] == A.ReValue[s]) {
matchA++;
usedA[s] = 1;
found++;
break;
}
}
if(found != 2) {
printf("Error\n");
exit(1);
}
}
}
if(matchI != nz || matchA != nz) {
printf("Error\n");
exit(1);
}
MMDeleteSparseMatrix(&A);
MMDeleteSparseMatrix(&I);
MMDeleteSparseMatrix(&M);
free(usedI);
free(usedA);
printf("OK\n");
exit(0);
} /* end main */