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
#include "DistributeVecOpt2.h"
int main(int argc, char **argv) {
struct sparsematrix A;
long P, k, n, q, r, i, t, nzp, maxout,
ComVol, MaxOut, MaxIn, MaxCompnts, TotCompnts;
int success;
long int *X;
printf("Test DistributeVecOpt2: ");
P = 6; /* number of processors >= 2 */
k = 7; /* number of columns each pair of processors share */
n= P*P*k; /* 2 by n matrix A */
A.m = 2;
A.n = n;
A.NrNzElts = P*(P-1)*k;
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 (q=0; q<P; q++){
/* nonzeros of proc q in row 0 */
for (r=q+1; r<P; r++){
for (i=0; i<k; i++){
A.i[t] = 0;
A.j[t] = (q*P + r) * k + i;
t++;
}
}
/* nonzeros of proc q in row 1 */
for (r=0; r<q; r++){
for (i=0; i<k; i++){
A.i[t] = 1;
A.j[t] = (r*P + q) * k + i;
t++;
}
}
}
nzp = (P-1)*k;
/* Procs 0, 1, ..., P-1 have nzp nonzeros each. */
for (i=0; i<P; i++)
A.Pstart[i] = i*nzp;
A.Pstart[P] = P*(P-1)*k;
success = DistributeVecOpt2(&A, X, ROW);
if (!CalcCom(&A, X, ROW, &ComVol, &MaxOut, &MaxIn, &MaxCompnts, &TotCompnts)) {
printf("Error\n");
exit(1);
}
if (((P-1)*k) %2 == 0)
maxout = ((P-1)*k)/ 2; /* ceiling */
else
maxout = ((P-1)*k)/ 2 + 1;
/* Check result values */
if (success != TRUE || ComVol != (P*(P-1)*k)/2 || MaxOut != maxout ||
MaxIn != MaxOut || TotCompnts != n){
printf("Error\n");
exit(1);
}
printf("OK\n");
exit(0);
} /* end main */