Skip to content

Commit fabcd44

Browse files
authored
Import gencon_and_mg_precon branch (#24)
1 parent 0cc6858 commit fabcd44

Some content is hidden

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

57 files changed

+4291
-484
lines changed

Makefile

+38-15
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,64 @@ DEBUG ?= 0
22
PAUL ?= 1
33
CC ?= mpicc
44
CFLAGS ?= -O2
5+
## ALGO=0 (Lanczos),1 (RQI),2 (FMG)
6+
ALGO ?= 0
7+
MPI ?= 1
58

6-
MKFILEPATH = $(abspath $(lastword $(MAKEFILE_LIST)))
7-
SRCROOT_ ?= $(patsubst %/,%,$(dir $(MKFILEPATH)))
8-
SRCROOT=$(realpath $(SRCROOT_))
9+
MKFILEPATH =$(abspath $(lastword $(MAKEFILE_LIST)))
10+
SRCROOT_ ?=$(patsubst %/,%,$(dir $(MKFILEPATH)))
11+
SRCROOT =$(realpath $(SRCROOT_))
912

1013
GSLIBDIR=$(GSLIBPATH)
1114

1215
SRCDIR =$(SRCROOT)/src
1316
SORTDIR =$(SRCROOT)/src/sort
17+
PRECONDDIR=$(SRCROOT)/src/precond
18+
GENCONDIR =$(SRCROOT)/src/gencon
1419
BUILDDIR =$(SRCROOT)/build
15-
EXAMPLEDIR=$(SRCROOT)/example
20+
EXAMPLEDIR=$(SRCROOT)/examples
1621
TESTDIR =$(SRCROOT)/tests
1722

1823
TARGET=parRSB
1924
LIB=$(BUILDDIR)/lib/lib$(TARGET).a
20-
EXAMPLE=$(EXAMPLEDIR)/example
2125

22-
INCFLAGS=-I$(SRCDIR) -I$(SORTDIR) -I$(GSLIBDIR)/include
26+
INCFLAGS=-I$(SRCDIR) -I$(SORTDIR) -I$(PRECONDDIR) -I$(GENCONDIR) -I$(GSLIBDIR)/include
2327
LDFLAGS:=-L$(BUILDDIR)/lib -l$(TARGET) -L $(GSLIBDIR)/lib -lgs -lm
2428

25-
SRCS =$(wildcard $(SRCDIR)/*.c)
26-
SORTSRCS=$(wildcard $(SORTDIR)/*.c)
27-
TESTSRCS=$(wildcard $(TESTDIR)/*.c)
29+
SRCS =$(wildcard $(SRCDIR)/*.c)
30+
SORTSRCS =$(wildcard $(SORTDIR)/*.c)
31+
PRECONDSRCS=$(wildcard $(PRECONDDIR)/*.c)
32+
GENCONSRCS =$(wildcard $(GENCONDIR)/*.c)
33+
TESTSRCS =$(wildcard $(TESTDIR)/*.c)
34+
EXAMPLESRCS=$(wildcard $(EXAMPLEDIR)/*.c)
2835

2936
SRCOBJS =$(patsubst $(SRCROOT)/%.c,$(BUILDDIR)/%.o,$(SRCS))
3037
SRCOBJS+=$(patsubst $(SRCROOT)/%.c,$(BUILDDIR)/%.o,$(SORTSRCS))
38+
SRCOBJS+=$(patsubst $(SRCROOT)/%.c,$(BUILDDIR)/%.o,$(PRECONDSRCS))
39+
SRCOBJS+=$(patsubst $(SRCROOT)/%.c,$(BUILDDIR)/%.o,$(GENCONSRCS))
3140
TESTOBJS=$(patsubst $(SRCROOT)/%.c,$(BUILDDIR)/%,$(TESTSRCS))
41+
EXAMPLEOBJS=$(patsubst $(SRCROOT)/%.c,$(BUILDDIR)/%,$(EXAMPLESRCS))
3242

3343
PP=
3444

3545
ifneq ($(DEBUG),0)
3646
PP += -g -DGENMAP_DEBUG
3747
endif
3848

49+
ifeq ($(ALGO),0)
50+
PP += -DGENMAP_LANCZOS
51+
else ifeq ($(ALGO),1)
52+
PP += -DGENMAP_RQI
53+
endif
54+
3955
ifneq ($(PAUL),0)
4056
PP += -DGENMAP_PAUL
4157
endif
4258

59+
ifneq ($(MPI),0)
60+
PP += -DMPI
61+
endif
62+
4363
INSTALLDIR=
4464
ifneq (,$(strip $(DESTDIR)))
4565
INSTALLDIR=$(realpath $(DESTDIR))
@@ -49,15 +69,15 @@ endif
4969
default: check lib install
5070

5171
.PHONY: all
52-
all: check lib tests example install
72+
all: check lib tests examples install
5373

5474
.PHONY: install
5575
install: lib
5676
ifneq ($(INSTALLDIR),)
5777
@mkdir -p $(INSTALLDIR)/lib 2>/dev/null
5878
@cp -v $(LIB) $(INSTALLDIR)/lib 2>/dev/null
5979
@mkdir -p $(INSTALLDIR)/include 2>/dev/null
60-
@cp $(SRCDIR)/*.h $(SORTDIR)/*.h $(INSTALLDIR)/include 2>/dev/null
80+
@cp $(SRCDIR)/*.h $(SORTDIR)/*.h $(PRECONDDIR)/*.h $(INSTALLDIR)/include 2>/dev/null
6181
endif
6282

6383
.PHONY: lib
@@ -76,18 +96,18 @@ $(BUILDDIR)/src/%.o: $(SRCROOT)/src/%.c
7696
$(CC) $(CFLAGS) $(PP) $(INCFLAGS) -c $< -o $@
7797

7898
.PHONY: examples
79-
examples: $(EXAMPLE)
99+
examples: install $(EXAMPLEOBJS)
80100

81-
$(EXAMPLE): install
82-
$(CC) $(CFLAGS) -I$(GSLIBDIR)/include -I$(SRCDIR) -I$(SORTDIR) $@.c -o $@ $(LDFLAGS)
101+
$(BUILDDIR)/examples/%: $(SRCROOT)/examples/%.c
102+
$(CC) $(CFLAGS) $(PP) $(INCFLAGS) $< -o $@ $(LDFLAGS)
83103

84104
.PHONY: tests
85105
tests: install $(TESTOBJS)
86106
@cp $(TESTDIR)/run-tests.sh $(BUILDDIR)/tests/
87107
@cd $(BUILDDIR)/tests && ./run-tests.sh
88108

89109
$(BUILDDIR)/tests/%: $(SRCROOT)/tests/%.c
90-
$(CC) $(CFLAGS) -I$(GSLIBDIR)/include -I$(SRCDIR) -I$(SORTDIR) $< -o $@ $(LDFLAGS)
110+
$(CC) $(CFLAGS) $(PP) $(INCFLAGS) $< -o $@ $(LDFLAGS)
91111

92112
.PHONY: clean
93113
clean:
@@ -102,4 +122,7 @@ print-%:
102122
@true
103123

104124
$(shell mkdir -p $(BUILDDIR)/src/sort)
125+
$(shell mkdir -p $(BUILDDIR)/src/precond)
126+
$(shell mkdir -p $(BUILDDIR)/src/gencon)
105127
$(shell mkdir -p $(BUILDDIR)/tests)
128+
$(shell mkdir -p $(BUILDDIR)/examples)
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/gencon.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#include <gencon-impl.h>
5+
6+
int main(int argc,char *argv[]){
7+
MPI_Init(&argc,&argv);
8+
struct comm comm; comm_init(&comm,MPI_COMM_WORLD);
9+
10+
if(argc<2){
11+
if(comm.id==0)
12+
printf("Usage: ./%s foo.re2 [tol]\n",argv[0]);
13+
MPI_Finalize();
14+
exit(1);
15+
}
16+
17+
Mesh mesh;
18+
read_re2_mesh(&mesh,argv[1],&comm);
19+
20+
findMinNeighborDistance(mesh);
21+
22+
double tol=(argc>2)?atof(argv[2]):0.2;
23+
24+
findSegments(mesh,&comm,tol);
25+
setGlobalID(mesh,&comm);
26+
sendBack(mesh,&comm);
27+
matchPeriodicFaces(mesh,&comm);
28+
29+
char co2FileName[BUFSIZ]; strncpy(co2FileName,argv[1],BUFSIZ);
30+
int len=strlen(co2FileName); assert(len>4 && len<BUFSIZ);
31+
co2FileName[len-2]='o',co2FileName[len-3]='c';
32+
33+
write_co2_file(mesh,co2FileName,&comm);
34+
35+
MeshFree(mesh);
36+
comm_free(&comm);
37+
MPI_Finalize();
38+
39+
return 0;
40+
}
File renamed without changes.
File renamed without changes.

src/gencon/distance.c

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <gencon-impl.h>
2+
3+
int NEIGHBOR_MAP[GC_MAX_VERTICES][GC_MAX_NEIGHBORS]={
4+
{1,2,4},
5+
{0,3,5},
6+
{0,3,6},
7+
{1,2,7},
8+
{0,5,6},
9+
{1,4,7},
10+
{2,4,7},
11+
{3,5,6}
12+
};
13+
14+
int findMinNeighborDistance(Mesh mesh){
15+
Point p=mesh->elements.ptr;
16+
Point e=p+mesh->nVertex*mesh->nelt;
17+
18+
int nDim=mesh->nDim;
19+
int nVertex=mesh->nVertex;
20+
21+
uint i,j,k,neighbor;
22+
GenmapScalar d;
23+
for(i=0; i<mesh->elements.n; i+=nVertex){
24+
for(j=0;j<nVertex;j++){
25+
p[i+j].dx=GENMAP_SCALAR_MAX;
26+
for(k=0;k<mesh->nNeighbors;k++){
27+
neighbor=NEIGHBOR_MAP[j][k];
28+
if(nDim==3)
29+
d=distance3D(p[i+j],p[i+neighbor]);
30+
else
31+
d=distance2D(p[i+j],p[i+neighbor]);
32+
p[i+j].dx=min(p[i+j].dx,d);
33+
}
34+
}
35+
}
36+
37+
return 0;
38+
}

src/gencon/gencon-impl.h

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#ifndef _GENMAP_GENCON_IMPL_H_
2+
#define _GENMAP_GENCON_IMPL_H_
3+
4+
#include <gencon.h>
5+
6+
#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]))
9+
#define distance3D(a,b) (distance2D(a,b)+sqrDiff((a).x[2],(b).x[2]))
10+
11+
#define min(a,b) ((a)<(b) ? (a) : (b))
12+
#define max(a,b) ((a)>(b) ? (a) : (b))
13+
14+
struct Point_private{
15+
GenmapScalar dx;
16+
GenmapScalar x[GC_MAX_DIM];
17+
uint proc;
18+
uint origin;
19+
int ifSegment;
20+
ulong sequenceId;
21+
ulong elementId;
22+
slong globalId;
23+
};
24+
25+
struct Face_private{
26+
struct Point_private vertex[GC_MAX_FACE_VERTICES];
27+
};
28+
29+
struct Element_private{
30+
struct Point_private vertex[GC_MAX_VERTICES];
31+
};
32+
33+
struct Boundary_private{
34+
ulong elementId;
35+
ulong faceId;
36+
struct Face_private face;
37+
uint proc;
38+
long bc[2];
39+
};
40+
41+
struct Mesh_private{
42+
ulong nelgt;
43+
ulong nelgv;
44+
uint nelt;
45+
int nDim;
46+
int nVertex;
47+
int nNeighbors;
48+
struct array elements;
49+
struct array boundary;
50+
};
51+
52+
int transferBoundaryFaces(Mesh mesh,struct comm *c);
53+
54+
/*
55+
Preprocessor Corner notation: Symmetric Corner notation:
56+
57+
4+-----+3 ^ s 3+-----+4 ^ s
58+
/ /| | / /| |
59+
/ / | | / / | |
60+
8+-----+7 +2 +----> r 7+-----+8 +2 +----> r
61+
| | / / | | / /
62+
| |/ / | |/ /
63+
5+-----+6 t 5+-----+6 t
64+
65+
66+
67+
i) Preprocessor notation:
68+
69+
+--------+ ^ S
70+
/ /| |
71+
/ 3 / | |
72+
4--> / / | |
73+
+--------+ 2 + +----> R
74+
| | / /
75+
| 6 | / /
76+
| |/ /
77+
+--------+ T
78+
1
79+
80+
ii) Symmetric notation:
81+
82+
+--------+ ^ S
83+
/ /| |
84+
/ 4 / | |
85+
1--> / / | |
86+
+--------+ 2 + +----> R
87+
| | / /
88+
| 6 | / /
89+
| |/ /
90+
+--------+ T
91+
3
92+
93+
EFACE(IFACE) - Given face number IFACE in symmetric notation,
94+
returns preprocessor notation face number.
95+
96+
EFACE1(IFACE) - Given face number IFACE in preprocessor notation,
97+
returns symmetric notation face number.
98+
99+
The following variables all take the symmetric notation of IFACE
100+
as arguments:
101+
102+
ICFACE(i,IFACE) - Gives the 4 vertices which reside on face IFACE
103+
as depicted below, e.g. ICFACE(i,2)=2,4,6,8.
104+
105+
3+-----+4 ^ Y
106+
/ 2 /| |
107+
Edge 1 extends / / | |
108+
from vertex 7+-----+8 +2 +----> X
109+
1 to 2. | 4 | / /
110+
| |/ /
111+
5+-----+6 Z
112+
3
113+
114+
IEDGFC(i,IFACE) - Gives the 4 edges which border the face IFACE
115+
Edge numbering is as follows:
116+
Edge = 1,2,3,4 run in +r direction
117+
Edge = 5,6,7,8 run in +s direction
118+
Edge = 9,10,11,12 run in +t direction
119+
120+
Ordering of each edge is such that a monotonically
121+
increasing sequence of vertices is associated with
122+
the start point of a corresponding set of
123+
monotonically increasing edge numbers, e.g.,
124+
125+
ICEDG(i,IEDGE) - Gives 3 variables for determining the stride along
126+
a given edge, IEDGE; i=1 gives the starting vertex
127+
i=2 gives the stopping vertex
128+
i=3 gives the stride size.
129+
130+
*/
131+
#endif

src/gencon/gencon.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef _GENMAP_GENCON_H_
2+
#define _GENMAP_GENCON_H_
3+
4+
#include <genmap-gslib.h>
5+
#include <genmap-types.h>
6+
7+
/* Upper bound for number of dimensions */
8+
#define GC_MAX_DIM 3
9+
10+
/* Boundary condition types */
11+
#define GC_PERIODIC "P "
12+
13+
/* Upper bounds for elements */
14+
#define GC_MAX_FACES 6
15+
#define GC_MAX_VERTICES 8
16+
#define GC_MAX_NEIGHBORS 3
17+
18+
/* Upper bounds for faces */
19+
#define GC_MAX_FACE_VERTICES 4
20+
21+
/* Header lengths */
22+
#define GC_RE2_HEADER_LEN 80
23+
#define GC_CO2_HEADER_LEN 132
24+
25+
typedef struct Point_private *Point;
26+
typedef struct Element_private *Element;
27+
typedef struct Boundary_private *BoundaryFace;
28+
typedef struct Mesh_private *Mesh;
29+
30+
extern int NEIGHBOR_MAP[GC_MAX_VERTICES][GC_MAX_NEIGHBORS];
31+
extern int PRE_TO_SYM_VERTEX[GC_MAX_VERTICES];
32+
extern int PRE_TO_SYM_FACE[GC_MAX_FACES];
33+
34+
/* Mesh */
35+
int MeshInit(Mesh *m_,int nel,int nDim);
36+
Element MeshGetElements(Mesh m);
37+
int MeshFree(Mesh m);
38+
39+
/* Read Nek5000 mesh files */
40+
int read_re2_mesh(Mesh *mesh,char *fname,struct comm *c);
41+
int read_co2_file(Mesh mesh,char *fname,struct comm *c);
42+
int write_co2_file(Mesh mesh,char *fname,struct comm *c);
43+
int read_co2_mesh(Mesh *mesh,char *fname,struct comm *c);
44+
45+
int findMinNeighborDistance(Mesh mesh);
46+
int findSegments(Mesh mesh,struct comm *c,GenmapScalar tol);
47+
int setGlobalID(Mesh mesh,struct comm *c);
48+
int sendBack(Mesh mesh,struct comm *c);
49+
int matchPeriodicFaces(Mesh mesh,struct comm *c);
50+
51+
#endif

0 commit comments

Comments
 (0)