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
#include "DistributeVecLib.h"
#include "Sort.h"
int main(int argc, char **argv) {
long P, n, i, j, s, nz, nztot, *procstart, *Ns, *Nr, *Nv, *Nv1, *J;
int *procindex;
long int *owner;
printf("Test AssignRemainingNonemptyColumns: ");
P = 17 ; /* P is the number of processors, must be odd, >= 3 */
n = P ; /* P by P communication matrix C with processors
in positions 0,1,...,P-1-j in column j for 0 <= j <= (P-1)/2 . */
Ns = (long *)malloc(P*sizeof(long));
Nr = (long *)malloc(P*sizeof(long));
Nv = (long *)malloc(P*sizeof(long));
Nv1 = (long *)malloc(P*sizeof(long));
nz = ((P+1)*(3*P+1) ) / 8 ;
procstart = (long *)malloc((n+1)*sizeof(long));
procindex = (int *)malloc(nz*sizeof(int));
owner = (long int *)malloc(n*sizeof(long int));
if ( Ns == NULL || Nr == NULL || Nv == NULL || Nv1 == NULL ||
procstart == NULL || procindex == NULL || owner == NULL){
printf("Error\n") ;
exit(1);
}
/* Initialise Ns, Nr, Nv, Nv1 */
for (i=0; i<P; i++){
Ns[i] = 0;
Nr[i] = 0;
Nv[i] = 0;
Nv1[i] = 0;
}
/* Initialise owner, procstart */
nztot = 0;
for (j=0; j <= (P-1)/2; j++){
owner[j] = -1;
procstart[j] = nztot ;
nztot += P-j ;
}
for (j= (P+1)/2; j <n; j++){
owner[j] = -1;
procstart[j] = nztot ;
}
procstart[n] = nztot ;
if ( nztot != nz) {
printf("Error\n") ;
exit(1);
}
/* Fill procindex. Only first (P+1)/2 columns. */
for (j=0; j<= (P-1)/2 ; j++)
for (s=procstart[j]; s<procstart[j+1]; s++)
procindex[s] = s- procstart[j] ;
AssignRemainingNonemptyColumns(n, P, owner, procstart, procindex, Ns, Nr, Nv) ;
/* Check owners */
/* First half should be owned */
for (j=0; j <= (P-1)/2; j++){
if (owner[j] < 0 || owner[j] >= P) {
printf("Error\n") ;
exit(1);
}
}
/* Second half should be unowned */
for (j= (P+1)/2; j<n; j++){
if (owner[j] != -1) {
printf("Error\n") ;
exit(1);
}
}
/* Don't trust Nv. Count again. */
for (j=0; j <= (P-1)/2; j++)
Nv1[owner[j]]++ ;
/* Check maximum number of sends, receives, components.
No processor should own more than 1 component */
for (i=0; i<P; i++){
if (Ns[i] >= P || Nr[i] > (P+1)/2 || Nv[i] > 1 || Nv[i] != Nv1[i] ){
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
printf("Error\n") ;
exit(1);
}
}
/* Sort the Ns values in increasing order */
J = (long *) malloc(n * sizeof(long)) ;
if (J == NULL){
printf("Error\n") ;
exit(1);
}
for (j=0; j < P ; j++)
J[j] = j ;
CSort(J, Ns, P-1, 0, P-1) ;
/* The Ns values must be 0,0,...,0, (P-1)/2,...,P-1 */
for (i=0; i<(P-1)/2; i++){
if (Ns[J[i]] != 0 ){
printf("Error\n") ;
exit(1);
}
}
for (i=(P-1)/2; i < P; i++){
if (Ns[J[i]] != i ){
printf("Error\n") ;
exit(1);
}
}
printf("OK\n") ;
exit(0);
} /* end main */