Newer
Older
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
90
91
92
93
94
95
96
97
98
#include "DistributeVecOrig.h"
struct opts Options;
int main(int argc, char **argv) {
struct sparsematrix A;
long P, n, i, t, nzp, maxcom,
ComVol, MaxOut, MaxIn, MaxCompnts, TotCompnts;
long int *X;
printf("Test DistributeVecOrig: ");
P = 666; /* number of processors >= 3 */
/* P by 3P matrix A, consisting of three P by P blocks,
A = [B|I|0] where B is a circulant matrix with three nonzero
diagonals. */
A.m = P;
A.n = 3*P;
n = A.n;
A.NrNzElts = 4*P;
A.NrProcs = P;
A.i = (long *) malloc(A.NrNzElts* sizeof(long));
A.j = (long *) malloc(A.NrNzElts* sizeof(long));
A.Pstart = (long *) malloc((P+1)* sizeof(long));
X = (long int *) malloc(n* sizeof(long int));
if ( A.i == NULL || A.j == NULL || A.Pstart == NULL || X == NULL ){
printf("Error\n");
exit(1);
}
/* Fill matrix with nonzeros */
t= 0;
for (i=0; i<P; i++){
/* Insert the 4 nonzeros of a row */
A.i[t] = A.i[t+1] = A.i[t+2] = A.i[t+3] = i;
A.j[t] = i;
A.j[t+1] = (i+P-1) % P;
A.j[t+2] = (i+P-2) % P;
A.j[t+3] = i+P;
t += 4;
}
nzp = 4;
/* Procs 0, 1, ..., P-1 have nzp nonzeros each. */
for (i=0; i<P; i++)
A.Pstart[i] = i*nzp;
A.Pstart[P] = 4*P;
Options.VectorPartition_Step3 = VecRandom;
maxcom = DistributeVecOrig(&A, X, ROW, &Options);
if (!maxcom < 0) {
printf("Error\n");
exit(1);
}
if (!CalcCom(&A, X, ROW, &ComVol, &MaxOut, &MaxIn, &MaxCompnts, &TotCompnts)) {
printf("Error\n");
exit(1);
}
/* Check result values. This is not a very strict check,
because vector assignment and maxcom can vary. */
if (ComVol != 2*P || maxcom != MAX(MaxIn,MaxOut) || TotCompnts != n){
printf("Error\n");
exit(1);
}
/* Check legality of vector distribution */
for (i=0; i<n; i++){
if (X[i] < 0 || X[i] >= P) {
printf("Error\n");
exit(1);
}
}
/* Check first block */
for (i=0; i<P; i++){
if (X[i] != i && X[i] != (i+1)%P && X[i] != (i+2)%P ) {
printf("Error\n");
exit(1);
}
}
/* Check second block */
for (i=P; i<2*P; i++){
if (X[i] != i-P) {
printf("Error\n");
exit(1);
}
}
printf("OK\n");
exit(0);
} /* end main */