Skip to content

Commit 63c4445

Browse files
thilinarmtbstgeke
authored andcommitted
[gencon] Fix issues related to ranks with zero elements
1 parent e923047 commit 63c4445

File tree

9 files changed

+177
-173
lines changed

9 files changed

+177
-173
lines changed

src/gencon/gencon-impl.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@
44
#include <gencon.h>
55

66
#define sqrDiff(x,y) (((x)-(y))*((x)-(y)))
7-
#define distance2D(a,b)\
8-
(sqrDiff((a).x[0],(b).x[0])+sqrDiff((a).x[1],(b).x[1]))
7+
#define distance2D(a,b) (sqrDiff((a).x[0],(b).x[0])+sqrDiff((a).x[1],(b).x[1]))
98
#define distance3D(a,b) (distance2D(a,b)+sqrDiff((a).x[2],(b).x[2]))
109

1110
#define min(a,b) ((a)<(b) ? (a) : (b))
1211
#define max(a,b) ((a)>(b) ? (a) : (b))
1312

14-
#define READ_T(coords,buf,T,nVertex) do{\
13+
#define READ_T(coords,buf,T,nVertex) do {\
1514
memcpy((coords),buf,sizeof(T)*nVertex);\
1615
} while(0)
1716

18-
#define WRITE_INT(dest,val) do{\
17+
#define WRITE_INT(dest,val) do {\
1918
memcpy(dest,&(val),sizeof(int));\
2019
} while(0)
2120

2221
// TODO: Use rsb_element here
23-
struct Point_private{
22+
struct Point_private {
2423
GenmapScalar dx;
2524
GenmapScalar x[GC_MAX_DIM];
2625
uint proc;

src/gencon/gencon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int write_connectivity(Mesh mesh,char *fname,struct comm *c);
4747
int read_co2_mesh(Mesh *mesh,char *fname,struct comm *c);
4848

4949
int findMinNeighborDistance(Mesh mesh);
50-
int findSegments(Mesh mesh,struct comm *c,GenmapScalar tol,int verbose);
50+
int findSegments(Mesh mesh,struct comm *c,GenmapScalar tol,int verbose,buffer *bfr);
5151
int faceCheck(Mesh mesh,struct comm *c);
5252
int setGlobalID(Mesh mesh,struct comm *c);
5353
int sendBack(Mesh mesh,struct comm *c);

src/gencon/global-id.c

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
#include "gencon-impl.h"
22

3-
int setGlobalID(Mesh mesh,struct comm *c){
4-
uint nPoints=mesh->elements.n;
5-
Point points=mesh->elements.ptr;
3+
int setGlobalID(Mesh mesh, struct comm *c) {
4+
uint nPoints = mesh->elements.n;
5+
Point points = mesh->elements.ptr;
66

7-
sint bin=1;
8-
if(nPoints==0)
9-
bin=0;
10-
11-
sint rank=c->id,size=c->np; comm_ext old=c->c;
7+
sint bin = 1;
8+
if (nPoints == 0)
9+
bin = 0;
1210

11+
comm_ext old = c->c;
1312
struct comm nonZeroRanks;
1413
#ifdef MPI
15-
MPI_Comm new; MPI_Comm_split(old,bin,rank,&new);
16-
comm_init(&nonZeroRanks,new);
14+
MPI_Comm new;
15+
MPI_Comm_split(old, bin, c->id, &new);
16+
comm_init(&nonZeroRanks, new);
1717
MPI_Comm_free(&new);
1818
#else
19-
comm_init(&nonZeroRanks,1);
19+
comm_init(&nonZeroRanks, 1);
2020
#endif
2121

22-
if(bin==1){
23-
slong count=0;
24-
sint i;
25-
for(i=0;i<nPoints;i++)
26-
if(points[i].ifSegment) count++;
27-
28-
slong out[2][1],buff[2][1],in[1];
29-
in[0]=count+!rank;
30-
comm_scan(out,&nonZeroRanks,gs_long,gs_add,in,1,buff);
31-
slong start=out[0][0];
32-
#if defined(GENMAP_DEBUG)
33-
printf("rank=%d start=%lld size=%lld\n",rank,start,in[0]);
34-
#endif
22+
sint rank = nonZeroRanks.id;
23+
sint size = nonZeroRanks.np;
3524

36-
start-=(rank>0?1:0);
37-
count=0;
38-
for(i=0;i<nPoints;i++){
39-
if(points[i].ifSegment) count++;
25+
if (bin == 1) {
26+
slong count = 0;
27+
sint i;
28+
for (i = 0; i < nPoints; i++)
29+
if (points[i].ifSegment)
30+
count++;
31+
32+
slong out[2][1], buf[2][1], in[1];
33+
in[0] = count + !rank;
34+
comm_scan(out, &nonZeroRanks, gs_long, gs_add, in, 1, buf);
35+
slong start = out[0][0];
36+
37+
start -= (rank > 0 ? 1 : 0);
38+
count = 0;
39+
for (i = 0; i < nPoints; i++) {
40+
if (points[i].ifSegment)
41+
count++;
4042
points[i].globalId=start+count;
4143
}
4244
}
@@ -46,15 +48,16 @@ int setGlobalID(Mesh mesh,struct comm *c){
4648
return 0;
4749
}
4850

49-
int sendBack(Mesh mesh,struct comm *c){
50-
struct crystal cr; crystal_init(&cr,c);
51-
sarray_transfer(struct Point_private,&mesh->elements,origin,0,&cr);
51+
int sendBack(Mesh mesh, struct comm *c) {
52+
struct crystal cr;
53+
crystal_init(&cr, c);
54+
sarray_transfer(struct Point_private, &mesh->elements, origin, 0, &cr);
5255
crystal_free(&cr);
5356

54-
buffer buf; buffer_init(&buf,1024);
55-
sarray_sort(struct Point_private,mesh->elements.ptr,mesh->elements.n,
56-
sequenceId,1,&buf);
57-
buffer_free(&buf);
57+
buffer bfr;
58+
buffer_init(&bfr, 1024);
59+
sarray_sort(struct Point_private, mesh->elements.ptr, mesh->elements.n, sequenceId, 1, &bfr);
60+
buffer_free(&bfr);
5861

5962
return 0;
6063
}

src/gencon/periodic.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include <genmap-impl.h>
77
#include <sort.h>
88

9-
int faces3D[GC_MAX_FACES][GC_MAX_FACE_VERTICES]={
9+
int faces3D[GC_MAX_FACES][GC_MAX_FACE_VERTICES] = {
1010
{1,5,7,3},{2,4,8,6},{1,2,6,5},{3,7,8,4},{1,3,4,2},{5,6,8,7}
1111
};
1212

13-
int faces2D[GC_MAX_FACES][GC_MAX_FACE_VERTICES]={
13+
int faces2D[GC_MAX_FACES][GC_MAX_FACE_VERTICES] = {
1414
{3,1,0,0},{2,4,0,0},{1,2,0,0},{4,3,0,0},{0,0,0,0},{0,0,0,0}
1515
};
1616

@@ -22,8 +22,7 @@ struct minPair_private{
2222
typedef struct minPair_private* minPair;
2323

2424
int compressPeriodicVertices(Mesh mesh,struct comm *c){
25-
parallel_sort(struct Point_private,&mesh->elements,globalId,
26-
gs_long,0,0,c);
25+
parallel_sort(struct Point_private,&mesh->elements,globalId,gs_long,0,0,c);
2726

2827
Point points=mesh->elements.ptr;
2928
uint npoints=mesh->elements.n;
@@ -60,8 +59,7 @@ ulong findMinBelowI(ulong min,uint I,struct array *arr){
6059
return min;
6160
}
6261

63-
int renumberPeriodicVertices(Mesh mesh,struct comm *c,\
64-
struct array *matched)
62+
int renumberPeriodicVertices(Mesh mesh, struct comm *c, struct array *matched)
6563
{
6664
minPair ptr=matched->ptr;
6765
uint size=matched->n;
@@ -136,8 +134,7 @@ int renumberPeriodicVertices(Mesh mesh,struct comm *c,\
136134
buffer_free(&buf);
137135
}
138136

139-
int findConnectedPeriodicPairs(Mesh mesh,BoundaryFace f_,BoundaryFace g_,
140-
struct array *matched)
137+
int findConnectedPeriodicPairs(Mesh mesh, BoundaryFace f_, BoundaryFace g_, struct array *matched)
141138
{
142139
struct Boundary_private f=*f_,g=*g_;
143140

@@ -242,7 +239,7 @@ int gatherMatchingPeriodicFaces(Mesh mesh,struct comm *c){
242239
crystal_free(&cr);
243240
}
244241

245-
int setPeriodicFaceCoordinates(Mesh mesh,struct comm *c){
242+
int setPeriodicFaceCoordinates(Mesh mesh, struct comm *c){
246243
BoundaryFace bPtr=mesh->boundary.ptr;
247244
sint bSize=mesh->boundary.n;
248245
if(bSize==0) return 0;
@@ -287,18 +284,19 @@ int setPeriodicFaceCoordinates(Mesh mesh,struct comm *c){
287284
}
288285
}
289286

290-
int matchPeriodicFaces(Mesh mesh,struct comm *c){
291-
setPeriodicFaceCoordinates(mesh,c);
292-
gatherMatchingPeriodicFaces(mesh,c);
287+
int matchPeriodicFaces(Mesh mesh, struct comm *c){
288+
setPeriodicFaceCoordinates(mesh, c);
289+
gatherMatchingPeriodicFaces(mesh, c);
293290

294291
struct array matched;
295-
array_init(struct minPair_private,&matched,10); matched.n=0;
296-
findConnectedPeriodicFaces(mesh,&matched);
297-
renumberPeriodicVertices(mesh,c,&matched);
292+
array_init(struct minPair_private, &matched, 10);
293+
matched.n = 0;
294+
findConnectedPeriodicFaces(mesh, &matched);
295+
renumberPeriodicVertices(mesh, c, &matched);
298296
array_free(&matched);
299297

300-
compressPeriodicVertices(mesh,c);
301-
sendBack(mesh,c);
298+
compressPeriodicVertices(mesh, c);
299+
sendBack(mesh, c);
302300

303301
return 0;
304302
}

0 commit comments

Comments
 (0)