Skip to content

Commit

Permalink
Import latest changes (#26)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thilinarmtb authored Dec 16, 2020
1 parent 4e8af7b commit 984e9d5
Show file tree
Hide file tree
Showing 50 changed files with 2,226 additions and 1,575 deletions.
43 changes: 34 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
## General build parameters ##
DEBUG ?= 0
PAUL ?= 1
MPI ?= 1
CC ?= mpicc
CFLAGS ?= -O2
## ALGO=0 (Lanczos),1 (RQI),2 (FMG)
CFLAGS ?= -g -O0
BLAS ?= 0
UNDERSCORE ?= 0

## Genmap algorithmic parameters ##
# ALGO = 0 (Lanczos),1 (RQI),2 (FMG)
ALGO ?= 0
MPI ?= 1
RCB_PRE_STEP ?= 1
PAUL ?= 1
GRAMMIAN ?= 0

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

GSLIBDIR=$(GSLIBPATH)

SRCDIR =$(SRCROOT)/src
SORTDIR =$(SRCROOT)/src/sort
PRECONDDIR=$(SRCROOT)/src/precond
Expand All @@ -23,8 +29,9 @@ TESTDIR =$(SRCROOT)/tests
TARGET=parRSB
LIB=$(BUILDDIR)/lib/lib$(TARGET).a

INCFLAGS=-I$(SRCDIR) -I$(SORTDIR) -I$(PRECONDDIR) -I$(GENCONDIR) -I$(GSLIBDIR)/include
LDFLAGS:=-L$(BUILDDIR)/lib -l$(TARGET) -L $(GSLIBDIR)/lib -lgs -lm
INCFLAGS=-I$(SRCDIR) -I$(SORTDIR) -I$(PRECONDDIR) -I$(GENCONDIR) \
-I$(GSLIBPATH)/include
LDFLAGS:=-L$(BUILDDIR)/lib -l$(TARGET) -L$(GSLIBPATH)/lib -lgs -lm

SRCS =$(wildcard $(SRCDIR)/*.c)
SORTSRCS =$(wildcard $(SORTDIR)/*.c)
Expand Down Expand Up @@ -52,10 +59,27 @@ else ifeq ($(ALGO),1)
PP += -DGENMAP_RQI
endif

ifneq ($(RCB_PRE_STEP),0)
PP += -DGENMAP_RCB_PRE_STEP
endif

ifneq ($(PAUL),0)
PP += -DGENMAP_PAUL
endif

ifneq ($(GRAMMIAN),0)
PP += -DGENMAP_GRAMMIAN
endif

ifneq ($(UNDERSCORE),0)
PP += -DGENMAP_UNDERSCORE
endif

ifneq ($(BLAS),0)
PP += -DGENMAP_BLAS
LDFLAGS += -L$(BLASLIBPATH) -lblasLapack
endif

ifneq ($(MPI),0)
PP += -DMPI
endif
Expand All @@ -77,7 +101,8 @@ ifneq ($(INSTALLDIR),)
@mkdir -p $(INSTALLDIR)/lib 2>/dev/null
@cp -v $(LIB) $(INSTALLDIR)/lib 2>/dev/null
@mkdir -p $(INSTALLDIR)/include 2>/dev/null
@cp $(SRCDIR)/*.h $(SORTDIR)/*.h $(PRECONDDIR)/*.h $(INSTALLDIR)/include 2>/dev/null
@cp $(SRCDIR)/*.h $(SORTDIR)/*.h $(PRECONDDIR)/*.h \
$(INSTALLDIR)/include 2>/dev/null
endif

.PHONY: lib
Expand Down
8 changes: 4 additions & 4 deletions examples/gencon.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ int main(int argc,char *argv[]){
}

Mesh mesh;
read_re2_mesh(&mesh,argv[1],&comm);
read_geometry(&mesh,argv[1],&comm);

findMinNeighborDistance(mesh);

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

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

write_co2_file(mesh,co2FileName,&comm);
write_connectivity(mesh,co2FileName,&comm);

MeshFree(mesh);
mesh_free(mesh);
comm_free(&comm);
MPI_Finalize();

Expand Down
146 changes: 85 additions & 61 deletions examples/partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,97 +6,121 @@ Parition mesh using Nek5000's vertex connectivity (con) file.
#include <stdlib.h>
#include <mpi.h>

#include "conReader.h"
#include <gencon.h>
#include <genmap.h>
#include <parRSB.h>

#include "gslib.h"
#include "parRSB.h"
#include "quality.h"

#define MAXNV 8 /* maximum number of vertices per element */
typedef struct {
int proc;
long long id;
long long vtx[MAXNV];
} elm_data;

#define EXIT_ERROR() do{\
MPI_Finalize();\
return EXIT_FAILURE;\
} while(0)

int main(int argc, char *argv[]) {
struct comm comm;
struct crystal cr;
struct array eList;
elm_data *data;
MPI_Init(&argc, &argv);
int rank,size;
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);

if(argc!=3){
if(rank==0)
printf("Usage: %s <#nread> <mesh file>\n",argv[0]);
EXIT_ERROR();
}

int ierr;
int e, n, nel, nv;
int options[3];
int n_read = atoi(argv[1]);
char* mesh_name = argv[2];

MPI_Init(&argc, &argv);
comm_init(&comm, MPI_COMM_WORLD);
char geom_name[BUFSIZ];
strncpy(geom_name,mesh_name,BUFSIZ);
strncat(geom_name,".re2",BUFSIZ);

char conn_name[BUFSIZ];
strncpy(conn_name,mesh_name,BUFSIZ);
strncat(conn_name,".co2",BUFSIZ);

int color = MPI_UNDEFINED;
if(rank<n_read) color=1;
MPI_Comm comm_read;
MPI_Comm_split(MPI_COMM_WORLD, color, 0, &comm_read);

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

int nRead = atoi(argv[1]);
char* conFile = argv[2];
/* Read mesh data */
if(color==1){
struct comm comm; comm_init(&comm, comm_read);

if (comm.id < nRead) color = 1;
MPI_Comm comm_read;
MPI_Comm_split(comm.c, color, 0, &comm_read);
Mesh mesh;
read_geometry(&mesh,geom_name,&comm);
read_connectivity(mesh,conn_name,&comm);
get_vertex_ids(&vl,mesh);
get_vertex_coordinates(&coord,mesh);

ierr = 0;
struct con con = {};
if (color != MPI_UNDEFINED) ierr = conRead(conFile, &con, comm_read);
if(ierr) goto quit;
ndim = get_mesh_dim(mesh);
nelt = get_mesh_nel(mesh);

comm_bcast(&comm, &con.nv, sizeof(int), 0);
nv = con.nv;
nel = con.nel;
int *part = (int*) malloc(nel * sizeof(int));
mesh_free(mesh);
comm_free(&comm);
}

MPI_Bcast(&ndim,1,MPI_INT,0,MPI_COMM_WORLD);
nv=(ndim==3)?8:4;

/* Partition the mesh */
int options[3];
options[0] = 1; /* use custom options */
options[1] = 3; /* debug level */
options[1] = 2; /* debug level */
options[2] = 0; /* not used */

ierr = parRSB_partMesh(part, con.vl, nel, nv, options, comm.c);
if(ierr) goto quit;
int *part=(int*)calloc(nelt,sizeof(int));
int ierr=parRSB_partMesh(part,vl,coord,nelt,nv,options,MPI_COMM_WORLD);
if(ierr){
if(vl) free(vl);
if(coord) free(coord);
if(part) free(part);
EXIT_ERROR();
}

/* redistribute data */
array_init(elm_data, &eList, nel), eList.n = nel;
for(data = eList.ptr, e = 0; e < nel; ++e) {
data[e].proc = part[e];
data[e].id = con.el[e];
for(n = 0; n < nv; ++n) {
data[e].vtx[n] = con.vl[e * nv + n];
/* Redistribute data */
struct array elements;
array_init(elm_data,&elements,nelt);
elm_data *data;
int e,n;
for(data=elements.ptr,e=0; e<nelt; ++e) {
data[e].proc=part[e];
for(n=0; n<nv; ++n) {
data[e].vtx[n] = vl[e*nv+n];
}
}
free(part);
conFree(&con);
elements.n=nelt;

crystal_init(&cr, &comm);
sarray_transfer(elm_data, &eList, proc, 0, &cr);
struct comm comm; comm_init(&comm,MPI_COMM_WORLD);
struct crystal cr; crystal_init(&cr, &comm);
sarray_transfer(elm_data,&elements,proc,0,&cr);
crystal_free(&cr);
nel = eList.n;

long long *el = (long long*) malloc(nel * sizeof(long long));
long long *vl = (long long*) malloc(nv * nel * sizeof(long long));
for(data = eList.ptr, e = 0; e < nel; ++e) {
el[e] = data[e].id;
for(n = 0; n < nv; ++n) {
vl[e * nv + n] = data[e].vtx[n];
comm_free(&comm);

nelt=elements.n;
vl=(long long*) malloc(nv*nelt*sizeof(long long));
for(data=elements.ptr, e=0; e<nelt; ++e) {
for(n=0; n<nv; ++n){
vl[e*nv+n]=data[e].vtx[n];
}
}
array_free(&elements);

printPartStat(vl, nel, nv, comm.c);

free(el);
free(vl);
array_free(&eList);
comm_free(&comm);
printPartStat(vl, nelt, nv, MPI_COMM_WORLD);

quit:
MPI_Finalize();
return ierr;
if(part) free(part);
if(vl) free(vl);
if(coord) free(coord);
}
Loading

0 comments on commit 984e9d5

Please sign in to comment.