@@ -28,18 +28,11 @@ static int sortSegments(Mesh mesh, struct comm *c, int dim, buffer *bfr) {
28
28
break ;
29
29
}
30
30
31
- s = e ;
31
+ points [s ].ifSegment = 1 ;
32
+ for (s = s + 1 ; s < e ; s ++ )
33
+ points [s ].ifSegment = 0 ;
32
34
}
33
35
34
- // Set globalId
35
- slong out [2 ][1 ], buf [2 ][1 ], in [1 ];
36
- in [0 ] = nPoints ;
37
- comm_scan (out , c , gs_long , gs_add , in , 1 , buf );
38
- slong start = out [0 ][0 ];
39
-
40
- for (e = 0 ; e < nPoints ; e ++ )
41
- points [e ].globalId = start + e ;
42
-
43
36
return 0 ;
44
37
}
45
38
@@ -48,21 +41,25 @@ static int findLocalSegments(Mesh mesh, int i, GenmapScalar tolSquared) {
48
41
sint npts = mesh -> elements .n ;
49
42
int nDim = mesh -> nDim ;
50
43
44
+ //if (npts > 0)
45
+ // printf("%d %d %0.12lf %0.12lf %0.12lf %llu\n", 0, pts[0].ifSegment, pts[0].x[0], pts[0].x[1], pts[0].x[2], pts[0].globalId);
46
+
51
47
sint j ;
52
- for (j = 0 ; j < npts - 1 ; j ++ ) {
53
- GenmapScalar d = sqrDiff (pts [j ].x [i ], pts [j + 1 ].x [i ]);
48
+ for (j = 1 ; j < npts ; j ++ ) {
49
+ GenmapScalar d = sqrDiff (pts [j ].x [i ], pts [j - 1 ].x [i ]);
54
50
55
- GenmapScalar dx = min (pts [j ].dx , pts [j + 1 ].dx )* tolSquared ;
51
+ GenmapScalar dx = min (pts [j ].dx , pts [j - 1 ].dx )* tolSquared ;
56
52
57
53
if (d > dx )
58
- pts [j + 1 ].ifSegment = 1 ;
54
+ pts [j ].ifSegment = 1 ;
55
+
56
+ //printf("%d %d %0.12lf %0.12lf %0.12lf %llu\n", j, pts[j].ifSegment, pts[j].x[0], pts[j].x[1], pts[j].x[2], pts[j].globalId);
59
57
}
60
58
}
61
59
62
60
static int mergeSegments (Mesh mesh , struct comm * c , int i , GenmapScalar tolSquared , buffer * bfr ) {
63
61
uint nPoints = mesh -> elements .n ;
64
62
Point points = mesh -> elements .ptr ;
65
- int nDim = mesh -> nDim ;
66
63
67
64
sint rank = c -> id ;
68
65
sint size = c -> np ;
@@ -95,10 +92,8 @@ static int mergeSegments(Mesh mesh, struct comm *c, int i, GenmapScalar tolSquar
95
92
96
93
// If rank > 0, send i = 0,... n-1 where points[i].ifSegment == 0 to rank - 1
97
94
n = 0 ;
98
- if (rank > 0 ) {
99
- for (; n < nPoints && points [n ].ifSegment == 0 ; n ++ )
100
- points [n ].proc = rank - 1 ;
101
- }
95
+ for (; n < nPoints && points [n ].ifSegment == 0 ; n ++ )
96
+ points [n ].proc = rank - 1 ;
102
97
for (; n < nPoints ; n ++ )
103
98
points [n ].proc = rank ;
104
99
@@ -127,37 +122,34 @@ int findSegments(Mesh mesh, struct comm *c, GenmapScalar tol, int verbose, buffe
127
122
128
123
//TODO: load balance
129
124
130
- // Initialize
125
+ // Initialize globalId and ifSegment
126
+ slong out [2 ][1 ], buf [2 ][1 ], in [1 ];
127
+ in [0 ] = nPoints ;
128
+ comm_scan (out , c , gs_long , gs_add , in , 1 , buf );
129
+ slong start = out [0 ][0 ];
131
130
uint i ;
132
- for (i = 0 ; i < nPoints ; i ++ )
131
+ for (i = 0 ; i < nPoints ; i ++ ) {
133
132
points [i ].ifSegment = 0 ;
133
+ points [i ].globalId = start + i ;
134
+ }
134
135
135
- slong out [2 ][1 ], buf [2 ][1 ], in [1 ];
136
- // in[0] = nPoints;
137
- // comm_scan(out, &nonZeroRanks, gs_long, gs_add, in, 1, buf);
138
- // slong start = out[0][0];
139
-
140
- // if (verbose > 1 && rank == 0) {
141
- // printf("\tsegments: rank=%d npts=%u start=%lld\n", rank, nPoints, start);
142
- // fflush(stdout);
143
- // }
144
- // comm_barrier(&nonZeroRanks);
136
+ //FIXME: first rank with nPoints>0 should do this
137
+ if (c -> id == 0 && nPoints > 0 )
138
+ points [0 ].ifSegment = 1 ;
145
139
146
140
comm_ext orig ;
147
141
#ifdef MPI
148
142
MPI_Comm_dup (c -> c , & orig );
149
143
#endif
150
144
struct comm nonZeroRanks ;
151
-
152
- int dim , bin , rank , t ;
145
+ int rank = c -> id ;
146
+
147
+ int dim , bin , t , merged = 0 ;
153
148
for (t = 0 ; t < nDim ; t ++ ) {
154
149
for (dim = 0 ; dim < nDim ; dim ++ ) {
155
150
nPoints = mesh -> elements .n ;
156
151
157
- bin = 1 ;
158
- if (nPoints == 0 )
159
- bin = 0 ;
160
-
152
+ bin = (nPoints > 0 );
161
153
#ifdef MPI
162
154
MPI_Comm new ;
163
155
MPI_Comm_split (orig , bin , rank , & new );
@@ -168,28 +160,27 @@ int findSegments(Mesh mesh, struct comm *c, GenmapScalar tol, int verbose, buffe
168
160
#endif
169
161
170
162
rank = nonZeroRanks .id ;
171
- for (i = 0 ; i < nPoints ; i ++ )
172
- points [i ].proc = rank ;
173
163
174
- if (bin == 1 ) {
175
- sortSegments (mesh , & nonZeroRanks , dim , bfr );
164
+ if (bin > 0 && verbose > 0 ) {
165
+ nPoints = mesh -> elements .n ;
166
+ points = mesh -> elements .ptr ;
167
+ sint count = 0 ;
168
+ for (i = 0 ; i < nPoints ; i ++ )
169
+ if (points [i ].ifSegment > 0 )
170
+ count ++ ;
171
+
172
+ in [0 ] = count ;
173
+ comm_allreduce (& nonZeroRanks , gs_long , gs_add , in , 1 , buf );
174
+ if (rank == 0 )
175
+ printf ("\tlocglob: %d %d %lld\n" , t + 1 , dim + 1 , in [0 ]);
176
+ }
176
177
178
+ if (bin > 0 ) {
179
+ sortSegments (mesh , & nonZeroRanks , dim , bfr );
177
180
findLocalSegments (mesh , dim , tolSquared );
178
-
179
- mergeSegments (mesh , & nonZeroRanks , dim , tolSquared , bfr );
180
-
181
- if (verbose > 0 ) {
182
- nPoints = mesh -> elements .n ;
183
- points = mesh -> elements .ptr ;
184
- sint count = 0 ;
185
- for (i = 0 ; i < nPoints ; i ++ )
186
- if (points [i ].ifSegment > 0 )
187
- count ++ ;
188
-
189
- in [0 ] = count ;
190
- comm_allreduce (& nonZeroRanks , gs_long , gs_add , in , 1 , buf );
191
- if (rank == 0 )
192
- printf ("\tlocglob: %d %d %lld\n" , t + 1 , dim + 1 , in [0 ] + 1 );
181
+ if (merged == 0 ) {
182
+ mergeSegments (mesh , & nonZeroRanks , dim , tolSquared , bfr );
183
+ merged = 1 ;
193
184
}
194
185
}
195
186
0 commit comments