-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmakehelm
224 lines (171 loc) · 5.67 KB
/
makehelm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# Makefile for FMM2d
# # This is the only makefile; there are no makefiles in subdirectories.
# Users should not need to edit this makefile (doing so would make it
# hard to stay up to date with repo version). Rather in order to
# change OS/environment-specific compilers and flags, create
# the file make.inc, which overrides the defaults below (which are
# for ubunutu linux/gcc system).
# compiler, and linking from C, fortran
CC=gcc
CXX=g++
FC=gfortran
###export OMP_NUM_THREADS=1
# set compiler flags for c and fortran
FFLAGS= -fPIC -O3 -march=native -funroll-loops -std=legacy -w
CFLAGS= -std=c99
CFLAGS+= $(FFLAGS)
CXXFLAGS= -std=c++11 -DSCTL_PROFILE=-1
CXXFLAGS+=$(FFLAGS)
# set linking libraries
CLIBS = -lgfortran -lm -ldl
LIBS = -lm
# extra flags for multithreaded: C/Fortran, MATLAB
OMPFLAGS =-fopenmp
OMPLIBS =-lgomp
# Python Exetucable
PYTHON=python
# flags for MATLAB MEX compilation..
MFLAGS=-compatibleArrayDims -DMWF77_UNDERSCORE1
MWFLAGS=-c99complex
MOMPFLAGS = -D_OPENMP
# location of MATLAB's mex compiler
MEX=mex
# For experts, location of Mwrap executable
MWRAP=../../mwrap/mwrap
MEXLIBS=-lm -lstdc++ -ldl -lgfortran
FMM_INSTALL_DIR=$(PREFIX)
ifeq ($(PREFIX),)
FMM_INSTALL_DIR = ${HOME}/lib
endif
DYLIBS = $(LIBS)
LIBNAME=libfmm2d
DYNAMICLIB = $(LIBNAME).so
STATICLIB = $(LIBNAME).a
LIMPLIB = $(DYNAMICLIB)
LLINKLIB = -lfmm2d
# For your OS, override the above by placing make variables in make.inc
-include make.inc
# additional compile flags for FAST_KER
ifeq ($(FAST_KER),ON)
LIBS += -lstdc++
DYLIBS += -lstdc++
CLIBS += -lstdc++
FFLAGS += -lstdc++
CFLAGS += -lstdc++
OMP = ON
endif
# multi-threaded libs & flags needed
ifneq ($(OMP),OFF)
CFLAGS += $(OMPFLAGS)
FFLAGS += $(OMPFLAGS)
MFLAGS += $(MOMPFLAGS)
LIBS += $(OMPLIBS)
DYLIBS += $(OMPLIBS)
MEXLIBS += $(OMPLIBS)
endif
# vectorized kernel directory
SRCDIR = ./vec-kernels/src
INCDIR = ./vec-kernels/include
LIBDIR = lib-static
# objects to compile
#
# Common objects
COM = src/common
COMOBJS = $(COM)/cdjseval2d.o $(COM)/dfft.o \
$(COM)/fmmcommon2d.o $(COM)/next235.o $(COM)/prini.o \
$(COM)/tree_routs2d.o $(COM)/pts_tree2d.o \
$(COM)/cumsum.o $(COM)/hank103.o
# Helmholtz objects
HELM = src/helmholtz
HOBJS = $(HELM)/h2dcommon.o $(HELM)/h2dterms.o \
$(HELM)/helmrouts2d.o $(HELM)/hfmm2dnew.o $(HELM)/hfmm2dwrap.o \
$(HELM)/wideband2dnew.o $(HELM)/hndiv2d.o
ifneq ($(FAST_KER),ON)
HOBJS += $(HELM)/helmkernels2d.o
endif
ifeq ($(FAST_KER),ON)
HOBJS += $(HELM)/helmkernels2d.o
endif
# Test objects
TOBJS = $(COM)/hkrand.o $(COM)/dlaran.o
OBJS = $(COMOBJS) $(HOBJS)
.PHONY: usage install lib test all python
default: usage
cxxkernel: $(CXXOBJ)
$(SRCDIR)/libkernels.o: $(SRCDIR)/libkernels.cpp
$(CXX) $(CXXFLAGS) -I$(INCDIR) -c $^ -o $@
usage:
@echo "Makefile for FMM2d. Specify what to make:"
@echo " make install - compile and install the main library"
@echo " make install PREFIX=(INSTALL_DIR) - compile and install the main library at custom location given by PREFIX"
@echo " make lib - compile the main library (in lib/ and lib-static/)"
@echo " make test - compile and run validation tests (will take a couple of mins)"
@echo " make objclean - removal all object files, preserving lib & MEX"
@echo " make clean - also remove lib, MEX, py, and demo executables"
@echo "For faster (multicore) making, append the flag -j"
@echo " 'make [task] OMP=OFF' for single-threaded"
# implicit rules for objects (note -o ensures writes to correct dir)
%.o: %.cpp %.h
$(CXX) -c $(CXXFLAGS) $< -o $@
%.o: %.c %.h
$(CC) -c $(CFLAGS) $< -o $@
%.o: %.f %.h
$(FC) -c $(FFLAGS) $< -o $@
%.o: %.f90
$(FC) -c $(FFLAGS) $< -o $@
# build the library...
lib: $(STATICLIB) $(DYNAMICLIB)
ifneq ($(OMP),OFF)
@echo "$(STATICLIB) and $(DYNAMICLIB) built, multithread versions"
else
@echo "$(STATICLIB) and $(DYNAMICLIB) built, single-threaded versions"
endif
install: $(STATICLIB) $(DYNAMICLIB)
echo $(FMM_INSTALL_DIR)
mkdir -p $(FMM_INSTALL_DIR)
cp -f lib/$(DYNAMICLIB) $(FMM_INSTALL_DIR)/
cp -f lib-static/$(STATICLIB) $(FMM_INSTALL_DIR)/
[ ! -f lib/$(LIMPLIB) ] || cp lib/$(LIMPLIB) $(FMM_INSTALL_DIR)/
@echo "Make sure to include " $(FMM_INSTALL_DIR) " in the appropriate path variable"
@echo " LD_LIBRARY_PATH on Linux"
@echo " PATH on windows"
@echo " DYLD_LIBRARY_PATH on Mac OSX (not needed if default installation directory is used"
@echo " "
@echo "In order to link against the dynamic library, use -L"$(FMM_INSTALL_DIR) " -lfmm2d"
$(STATICLIB): $(OBJS)
ar rcs $(STATICLIB) $(OBJS)
mv $(STATICLIB) lib-static/
$(DYNAMICLIB): $(OBJS)
$(FC) -shared -fPIC $(OBJS) -o $(DYNAMICLIB) $(DYLIBS)
mv $(DYNAMICLIB) lib/
[ ! -f $(LIMPLIB) ] || mv $(LIMPLIB) lib/
# testing routines
#
test: $(STATICLIB) $(TOBJS) test/hfmm2d
(cd test/helmholtz; ./run_helmtest2.sh)
cat print_testreshelm.txt
rm print_testreshelm.txt
test/hfmm2d:
$(FC) $(FFLAGS) test/helmholtz/test_hfmm2d.f $(TOBJS) $(COMOBJS) $(HOBJS) -o test/helmholtz/int2-test-hfmm2d $(LIBS)
#python
python: $(STATICLIB)
cd python && \
FMM_FLIBS='$(LIBS) $(OMPFLAGS)' $(PYTHON) -m pip install -e .
# matlab..
MWRAPFILE = fmm2d
GATEWAY = $(MWRAPFILE)
matlab: $(STATICLIB) matlab/$(GATEWAY).c
$(MEX) matlab/$(GATEWAY).c lib-static/$(STATICLIB) $(MFLAGS) \
-output matlab/fmm2d $(MEXLIBS)
mex: $(STATICLIB)
cd matlab; $(MWRAP) $(MWFLAGS) -list -mex $(GATEWAY) -mb $(MWRAPFILE).mw;\
$(MWRAP) $(MWFLAGS) -mex $(GATEWAY) -c $(GATEWAY).c $(MWRAPFILE).mw;\
$(MEX) $(GATEWAY).c ../lib-static/$(STATICLIB) $(MFLAGS) -output $(MWRAPFILE) \
$(MEXLIBS); \
clean: objclean
rm -f lib-static/*.a lib/*.so lib/*.dll lib/*.lib
rm -f test/laplace/int2-*
rm -f test/helmholtz/int2-*
objclean:
rm -f $(OBJS) $(COBJS) $(TOBJS)
rm -f test/laplace/*.o test/helmholtz/*.o