Skip to content

Commit 984e9d5

Browse files
authored
Import latest changes (#26)
* Add a check to find disconnected components * Add face-check consistency * Refactor metrics, build system and implement Grammian * Fix io and example/partition * Fix MG preconditioner and add Grammian
1 parent 4e8af7b commit 984e9d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2226
-1575
lines changed

Makefile

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
## General build parameters ##
12
DEBUG ?= 0
2-
PAUL ?= 1
3+
MPI ?= 1
34
CC ?= mpicc
4-
CFLAGS ?= -O2
5-
## ALGO=0 (Lanczos),1 (RQI),2 (FMG)
5+
CFLAGS ?= -g -O0
6+
BLAS ?= 0
7+
UNDERSCORE ?= 0
8+
9+
## Genmap algorithmic parameters ##
10+
# ALGO = 0 (Lanczos),1 (RQI),2 (FMG)
611
ALGO ?= 0
7-
MPI ?= 1
12+
RCB_PRE_STEP ?= 1
13+
PAUL ?= 1
14+
GRAMMIAN ?= 0
815

16+
## Don't touch what follows ##
917
MKFILEPATH =$(abspath $(lastword $(MAKEFILE_LIST)))
1018
SRCROOT_ ?=$(patsubst %/,%,$(dir $(MKFILEPATH)))
1119
SRCROOT =$(realpath $(SRCROOT_))
1220

13-
GSLIBDIR=$(GSLIBPATH)
14-
1521
SRCDIR =$(SRCROOT)/src
1622
SORTDIR =$(SRCROOT)/src/sort
1723
PRECONDDIR=$(SRCROOT)/src/precond
@@ -23,8 +29,9 @@ TESTDIR =$(SRCROOT)/tests
2329
TARGET=parRSB
2430
LIB=$(BUILDDIR)/lib/lib$(TARGET).a
2531

26-
INCFLAGS=-I$(SRCDIR) -I$(SORTDIR) -I$(PRECONDDIR) -I$(GENCONDIR) -I$(GSLIBDIR)/include
27-
LDFLAGS:=-L$(BUILDDIR)/lib -l$(TARGET) -L $(GSLIBDIR)/lib -lgs -lm
32+
INCFLAGS=-I$(SRCDIR) -I$(SORTDIR) -I$(PRECONDDIR) -I$(GENCONDIR) \
33+
-I$(GSLIBPATH)/include
34+
LDFLAGS:=-L$(BUILDDIR)/lib -l$(TARGET) -L$(GSLIBPATH)/lib -lgs -lm
2835

2936
SRCS =$(wildcard $(SRCDIR)/*.c)
3037
SORTSRCS =$(wildcard $(SORTDIR)/*.c)
@@ -52,10 +59,27 @@ else ifeq ($(ALGO),1)
5259
PP += -DGENMAP_RQI
5360
endif
5461

62+
ifneq ($(RCB_PRE_STEP),0)
63+
PP += -DGENMAP_RCB_PRE_STEP
64+
endif
65+
5566
ifneq ($(PAUL),0)
5667
PP += -DGENMAP_PAUL
5768
endif
5869

70+
ifneq ($(GRAMMIAN),0)
71+
PP += -DGENMAP_GRAMMIAN
72+
endif
73+
74+
ifneq ($(UNDERSCORE),0)
75+
PP += -DGENMAP_UNDERSCORE
76+
endif
77+
78+
ifneq ($(BLAS),0)
79+
PP += -DGENMAP_BLAS
80+
LDFLAGS += -L$(BLASLIBPATH) -lblasLapack
81+
endif
82+
5983
ifneq ($(MPI),0)
6084
PP += -DMPI
6185
endif
@@ -77,7 +101,8 @@ ifneq ($(INSTALLDIR),)
77101
@mkdir -p $(INSTALLDIR)/lib 2>/dev/null
78102
@cp -v $(LIB) $(INSTALLDIR)/lib 2>/dev/null
79103
@mkdir -p $(INSTALLDIR)/include 2>/dev/null
80-
@cp $(SRCDIR)/*.h $(SORTDIR)/*.h $(PRECONDDIR)/*.h $(INSTALLDIR)/include 2>/dev/null
104+
@cp $(SRCDIR)/*.h $(SORTDIR)/*.h $(PRECONDDIR)/*.h \
105+
$(INSTALLDIR)/include 2>/dev/null
81106
endif
82107

83108
.PHONY: lib

examples/gencon.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ int main(int argc,char *argv[]){
1515
}
1616

1717
Mesh mesh;
18-
read_re2_mesh(&mesh,argv[1],&comm);
18+
read_geometry(&mesh,argv[1],&comm);
1919

2020
findMinNeighborDistance(mesh);
2121

2222
double tol=(argc>2)?atof(argv[2]):0.2;
2323

24-
findSegments(mesh,&comm,tol);
24+
findSegments(mesh,&comm,tol,0);
2525
setGlobalID(mesh,&comm);
2626
sendBack(mesh,&comm);
2727
matchPeriodicFaces(mesh,&comm);
@@ -30,9 +30,9 @@ int main(int argc,char *argv[]){
3030
int len=strlen(co2FileName); assert(len>4 && len<BUFSIZ);
3131
co2FileName[len-2]='o',co2FileName[len-3]='c';
3232

33-
write_co2_file(mesh,co2FileName,&comm);
33+
write_connectivity(mesh,co2FileName,&comm);
3434

35-
MeshFree(mesh);
35+
mesh_free(mesh);
3636
comm_free(&comm);
3737
MPI_Finalize();
3838

examples/partition.c

+85-61
Original file line numberDiff line numberDiff line change
@@ -6,97 +6,121 @@ Parition mesh using Nek5000's vertex connectivity (con) file.
66
#include <stdlib.h>
77
#include <mpi.h>
88

9-
#include "conReader.h"
9+
#include <gencon.h>
10+
#include <genmap.h>
11+
#include <parRSB.h>
1012

11-
#include "gslib.h"
12-
#include "parRSB.h"
1313
#include "quality.h"
1414

1515
#define MAXNV 8 /* maximum number of vertices per element */
1616
typedef struct {
1717
int proc;
18-
long long id;
1918
long long vtx[MAXNV];
2019
} elm_data;
2120

21+
#define EXIT_ERROR() do{\
22+
MPI_Finalize();\
23+
return EXIT_FAILURE;\
24+
} while(0)
25+
2226
int main(int argc, char *argv[]) {
23-
struct comm comm;
24-
struct crystal cr;
25-
struct array eList;
26-
elm_data *data;
27+
MPI_Init(&argc, &argv);
28+
int rank,size;
29+
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
30+
MPI_Comm_size(MPI_COMM_WORLD,&size);
31+
32+
if(argc!=3){
33+
if(rank==0)
34+
printf("Usage: %s <#nread> <mesh file>\n",argv[0]);
35+
EXIT_ERROR();
36+
}
2737

28-
int ierr;
29-
int e, n, nel, nv;
30-
int options[3];
38+
int n_read = atoi(argv[1]);
39+
char* mesh_name = argv[2];
3140

32-
MPI_Init(&argc, &argv);
33-
comm_init(&comm, MPI_COMM_WORLD);
41+
char geom_name[BUFSIZ];
42+
strncpy(geom_name,mesh_name,BUFSIZ);
43+
strncat(geom_name,".re2",BUFSIZ);
44+
45+
char conn_name[BUFSIZ];
46+
strncpy(conn_name,mesh_name,BUFSIZ);
47+
strncat(conn_name,".co2",BUFSIZ);
3448

3549
int color = MPI_UNDEFINED;
50+
if(rank<n_read) color=1;
51+
MPI_Comm comm_read;
52+
MPI_Comm_split(MPI_COMM_WORLD, color, 0, &comm_read);
3653

37-
if (argc != 3) {
38-
if(comm.id) printf("usage: ./example <#nread> <co2 file>\n");
39-
return EXIT_FAILURE;
40-
}
54+
long long *vl=NULL;
55+
double *coord=NULL;
56+
int nelt=0,ndim,nv;
4157

42-
int nRead = atoi(argv[1]);
43-
char* conFile = argv[2];
58+
/* Read mesh data */
59+
if(color==1){
60+
struct comm comm; comm_init(&comm, comm_read);
4461

45-
if (comm.id < nRead) color = 1;
46-
MPI_Comm comm_read;
47-
MPI_Comm_split(comm.c, color, 0, &comm_read);
62+
Mesh mesh;
63+
read_geometry(&mesh,geom_name,&comm);
64+
read_connectivity(mesh,conn_name,&comm);
65+
get_vertex_ids(&vl,mesh);
66+
get_vertex_coordinates(&coord,mesh);
4867

49-
ierr = 0;
50-
struct con con = {};
51-
if (color != MPI_UNDEFINED) ierr = conRead(conFile, &con, comm_read);
52-
if(ierr) goto quit;
68+
ndim = get_mesh_dim(mesh);
69+
nelt = get_mesh_nel(mesh);
5370

54-
comm_bcast(&comm, &con.nv, sizeof(int), 0);
55-
nv = con.nv;
56-
nel = con.nel;
57-
int *part = (int*) malloc(nel * sizeof(int));
71+
mesh_free(mesh);
72+
comm_free(&comm);
73+
}
74+
75+
MPI_Bcast(&ndim,1,MPI_INT,0,MPI_COMM_WORLD);
76+
nv=(ndim==3)?8:4;
5877

78+
/* Partition the mesh */
79+
int options[3];
5980
options[0] = 1; /* use custom options */
60-
options[1] = 3; /* debug level */
81+
options[1] = 2; /* debug level */
6182
options[2] = 0; /* not used */
6283

63-
ierr = parRSB_partMesh(part, con.vl, nel, nv, options, comm.c);
64-
if(ierr) goto quit;
84+
int *part=(int*)calloc(nelt,sizeof(int));
85+
int ierr=parRSB_partMesh(part,vl,coord,nelt,nv,options,MPI_COMM_WORLD);
86+
if(ierr){
87+
if(vl) free(vl);
88+
if(coord) free(coord);
89+
if(part) free(part);
90+
EXIT_ERROR();
91+
}
6592

66-
/* redistribute data */
67-
array_init(elm_data, &eList, nel), eList.n = nel;
68-
for(data = eList.ptr, e = 0; e < nel; ++e) {
69-
data[e].proc = part[e];
70-
data[e].id = con.el[e];
71-
for(n = 0; n < nv; ++n) {
72-
data[e].vtx[n] = con.vl[e * nv + n];
93+
/* Redistribute data */
94+
struct array elements;
95+
array_init(elm_data,&elements,nelt);
96+
elm_data *data;
97+
int e,n;
98+
for(data=elements.ptr,e=0; e<nelt; ++e) {
99+
data[e].proc=part[e];
100+
for(n=0; n<nv; ++n) {
101+
data[e].vtx[n] = vl[e*nv+n];
73102
}
74103
}
75-
free(part);
76-
conFree(&con);
104+
elements.n=nelt;
77105

78-
crystal_init(&cr, &comm);
79-
sarray_transfer(elm_data, &eList, proc, 0, &cr);
106+
struct comm comm; comm_init(&comm,MPI_COMM_WORLD);
107+
struct crystal cr; crystal_init(&cr, &comm);
108+
sarray_transfer(elm_data,&elements,proc,0,&cr);
80109
crystal_free(&cr);
81-
nel = eList.n;
82-
83-
long long *el = (long long*) malloc(nel * sizeof(long long));
84-
long long *vl = (long long*) malloc(nv * nel * sizeof(long long));
85-
for(data = eList.ptr, e = 0; e < nel; ++e) {
86-
el[e] = data[e].id;
87-
for(n = 0; n < nv; ++n) {
88-
vl[e * nv + n] = data[e].vtx[n];
110+
comm_free(&comm);
111+
112+
nelt=elements.n;
113+
vl=(long long*) malloc(nv*nelt*sizeof(long long));
114+
for(data=elements.ptr, e=0; e<nelt; ++e) {
115+
for(n=0; n<nv; ++n){
116+
vl[e*nv+n]=data[e].vtx[n];
89117
}
90118
}
119+
array_free(&elements);
91120

92-
printPartStat(vl, nel, nv, comm.c);
93-
94-
free(el);
95-
free(vl);
96-
array_free(&eList);
97-
comm_free(&comm);
121+
printPartStat(vl, nelt, nv, MPI_COMM_WORLD);
98122

99-
quit:
100-
MPI_Finalize();
101-
return ierr;
123+
if(part) free(part);
124+
if(vl) free(vl);
125+
if(coord) free(coord);
102126
}

0 commit comments

Comments
 (0)