-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
305 lines (280 loc) · 12.2 KB
/
setup.py
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#!/usr/bin/env python
#
# pyLOM, setup.
#
# Setup and cythonize code.
#
# Last rev: 28/10/2021
from __future__ import print_function, division
import os, sys, numpy as np, mpi4py
from setuptools import setup, Extension, find_packages
from Cython.Build import cythonize
## Read INIT file
with open('pyLOM/__init__.py') as f:
for l in f.readlines():
if '__version__' in l:
__version__ = eval(l.split('=')[1].strip())
## Read README file
with open('README.md') as f:
readme = f.read()
## Read compilation options
options = {}
with open('options.cfg') as f:
for line in f.readlines():
if '#' in line or len(line) == 1: continue # Skip comment
linep = line.split('=')
options[linep[0].strip()] = linep[1].strip()
if options[linep[0].strip()] == 'ON': options[linep[0].strip()] = True
if options[linep[0].strip()] == 'OFF': options[linep[0].strip()] = False
options['MODULES_COMPILED'] = options['MODULES_COMPILED'].lower().split(',')
## Set up compiler options and flags
ICC = 'icx' if 'ACC' in options['PLATFORM'] else 'icc'
CC = 'mpicc' if options['FORCE_GCC'] or not os.system('which %s > /dev/null'%ICC) == 0 else 'mpiicc'
CXX = 'mpicxx' if options['FORCE_GCC'] or not os.system('which %s > /dev/null'%ICC) == 0 else 'mpiicpc'
FC = 'mpifort' if options['FORCE_GCC'] or not os.system('which %s > /dev/null'%ICC) == 0 else 'mpiifort'
CFLAGS = ''
CXXFLAGS = ' -std=c++11'
FFLAGS = ''
DFLAGS = ' -DNPY_NO_DEPRECATED_API'
if options['USE_MKL']: DFLAGS += ' -DUSE_MKL'
if options['USE_FFTW']: DFLAGS += ' -DUSE_FFTW3'
if options['USE_GESVD']: DFLAGS += ' -DUSE_LAPACK_DGESVD'
if CC == 'mpicc':
# Using GCC as a compiler
CFLAGS += ' -O0 -g -rdynamic -fPIC' if options['DEBUGGING'] else ' -O%s -ffast-math -fPIC' % options['OPTL']
CXXFLAGS += ' -O0 -g -rdynamic -fPIC' if options['DEBUGGING'] else ' -O%s -ffast-math -fPIC' % options['OPTL']
FFLAGS += ' -O0 -g -rdynamic -fPIC' if options['DEBUGGING'] else ' -O%s -ffast-math -fPIC' % options['OPTL']
# Vectorization flags
if options['VECTORIZATION']:
CFLAGS += ' -march=native -ftree-vectorize'
CXXFLAGS += ' -march=native -ftree-vectorize'
FFLAGS += ' -march=native -ftree-vectorize'
# OpenMP flag
if options['OPENMP_PARALL']:
CFLAGS += ' -fopenmp'
CXXFLAGS += ' -fopenmp'
else:
# Using GCC as a compiler
CFLAGS += ' -O0 -g -traceback -fPIC' if options['DEBUGGING'] else ' -O%s -fPIC' % options['OPTL']
CXXFLAGS += ' -O0 -g -traceback -fPIC' if options['DEBUGGING'] else ' -O%s -fPIC' % options['OPTL']
FFLAGS += ' -O0 -g -traceback -fPIC' if options['DEBUGGING'] else ' -O%s -fPIC' % options['OPTL']
# Vectorization flags
if options['VECTORIZATION']:
CFLAGS += ' -x%s -mtune=%s' % (options['HOST'],options['TUNE'])
CXXFLAGS += ' -x%s -mtune=%s' % (options['HOST'],options['TUNE'])
FFLAGS += ' -x%s -mtune=%s' % (options['HOST'],options['TUNE'])
# OpenMP flag
if options['OPENMP_PARALL']:
CFLAGS += ' -qopenmp'
CXXFLAGS += ' -qopenmp'
DFLAGS += ' -DUSE_OMP'
## Set up environment variables
os.environ['CC'] = CC
os.environ['CXX'] = CXX
os.environ['CFLAGS'] = CFLAGS + DFLAGS
os.environ['CXXFLAGS'] = CXXFLAGS + DFLAGS
os.environ['LDSHARED'] = CC + ' -shared'
## Libraries and includes
include_dirs = []
extra_objects = []
libraries = ['m']
# OSX needs to also link with python for reasons...
if sys.platform == 'darwin': libraries += [f'python{sys.version_info[0]}.{sys.version_info[1]}']
if options['USE_FFTW']:
# NFFT
include_dirs += ['Deps/nfft/include']
extra_objects += ['Deps/nfft/lib/libnfft3.a','Deps/nfft/lib/libnfft3f.a']
# FFTW
include_dirs += ['Deps/fftw/include']
extra_objects += ['Deps/fftw/lib/libfftw3.a','Deps/fftw/lib/libfftw3f.a']
if options['OPENMP_PARALL']: extra_objects += ['Deps/fftw/lib/libfftw3_omp.a','Deps/fftw/lib/libfftw3f_omp.a']
DFLAGS += ' -DUSE_FFTW3'
else:
# KISSFFT
include_dirs += ['Deps/kissfft/include/kissfft']
extra_objects += ['Deps/kissfft/lib/libkissfft-double.a']
# Select which libraries to use depending on the compilation options
if options['USE_MKL']:
# Link with Intel MKL using the intel compilers
# this is the most performing option available
mklroot = 'Deps/oneAPI/mkl'
include_dirs += [os.path.join(mklroot,'include')]
if options['OPENMP_PARALL']:
extra_objects += [os.path.join(mklroot,'libmkl_intel_thread.a' if CC == 'mpiicc' else 'libmkl_gcc_thread.a')]
else:
extra_objects += [os.path.join(mklroot,'libmkl_intel.a' if CC == 'mpiicc' else 'libmkl_gcc.a')]
else:
# Link with OpenBLAS which has a decent performance but is not
# as fast as Intel MKL
include_dirs += ['Deps/lapack/include/openblas']
extra_objects += ['Deps/lapack/lib/libopenblas.a']
libraries += ['gfortran']
# Classical LAPACK & BLAS library has a very bad performance
# but is left here for nostalgia
# include_dirs += ['Deps/lapack/include/']
# extra_objects += ['Deps/lapack/lib/liblapacke.a','Deps/lapack/lib/liblapack.a','Deps/lapack/lib/libcblas.a','Deps/lapack/lib/libblas.a']
# libraries += ['gfortran']
## Modules
# vmmath module
Module_cfuncs = Extension('pyLOM.vmmath.cfuncs',
sources = ['pyLOM/vmmath/cfuncs.pyx',
'pyLOM/vmmath/src/vector_matrix.c',
'pyLOM/vmmath/src/averaging.c',
'pyLOM/vmmath/src/svd.c',
'pyLOM/vmmath/src/fft.c',
'pyLOM/vmmath/src/geometric.c',
'pyLOM/vmmath/src/truncation.c',
'pyLOM/vmmath/src/stats.c',
'pyLOM/vmmath/src/regression.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_maths = Extension('pyLOM.vmmath.maths',
sources = ['pyLOM/vmmath/maths.pyx',
'pyLOM/vmmath/src/vector_matrix.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_averaging = Extension('pyLOM.vmmath.averaging',
sources = ['pyLOM/vmmath/averaging.pyx',
'pyLOM/vmmath/src/averaging.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_svd = Extension('pyLOM.vmmath.svd',
sources = ['pyLOM/vmmath/svd.pyx',
'pyLOM/vmmath/src/vector_matrix.c',
'pyLOM/vmmath/src/svd.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_fft = Extension('pyLOM.vmmath.fft',
sources = ['pyLOM/vmmath/fft.pyx',
'pyLOM/vmmath/src/fft.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_geometric = Extension('pyLOM.vmmath.geometric',
sources = ['pyLOM/vmmath/geometric.pyx',
'pyLOM/vmmath/src/geometric.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_truncation = Extension('pyLOM.vmmath.truncation',
sources = ['pyLOM/vmmath/truncation.pyx',
'pyLOM/vmmath/src/vector_matrix.c',
'pyLOM/vmmath/src/truncation.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_stats = Extension('pyLOM.vmmath.stats',
sources = ['pyLOM/vmmath/stats.pyx',
'pyLOM/vmmath/src/stats.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_regression = Extension('pyLOM.vmmath.regression',
sources = ['pyLOM/vmmath/regression.pyx',
'pyLOM/vmmath/src/vector_matrix.c',
'pyLOM/vmmath/src/regression.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
# low-order modules
Module_POD = Extension('pyLOM.POD.wrapper',
sources = ['pyLOM/POD/wrapper.pyx',
'pyLOM/vmmath/src/vector_matrix.c',
'pyLOM/vmmath/src/averaging.c',
'pyLOM/vmmath/src/svd.c',
'pyLOM/vmmath/src/truncation.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_DMD = Extension('pyLOM.DMD.wrapper',
sources = ['pyLOM/DMD/wrapper.pyx',
'pyLOM/vmmath/src/vector_matrix.c',
'pyLOM/vmmath/src/averaging.c',
'pyLOM/vmmath/src/svd.c',
'pyLOM/vmmath/src/truncation.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
Module_SPOD = Extension('pyLOM.SPOD.wrapper',
sources = ['pyLOM/SPOD/wrapper.pyx',
'pyLOM/vmmath/src/vector_matrix.c',
'pyLOM/vmmath/src/averaging.c',
'pyLOM/vmmath/src/svd.c',
'pyLOM/vmmath/src/fft.c',
],
language = 'c',
include_dirs = include_dirs + ['pyLOM/vmmath/src',np.get_include(),mpi4py.get_include()],
extra_objects = extra_objects,
libraries = libraries,
)
## Build modules
# Math module
Module_Math = [Module_cfuncs]
Module_Math += [Module_maths] if 'math.maths' in options['MODULES_COMPILED'] else []
Module_Math += [Module_averaging] if 'math.averaging' in options['MODULES_COMPILED'] else []
Module_Math += [Module_svd] if 'math.svd' in options['MODULES_COMPILED'] else []
Module_Math += [Module_fft] if 'math.fft' in options['MODULES_COMPILED'] else []
Module_Math += [Module_geometric] if 'math.geometric' in options['MODULES_COMPILED'] else []
Module_Math += [Module_truncation] if 'math.truncation' in options['MODULES_COMPILED'] else []
Module_Math += [Module_stats] if 'math.stats' in options['MODULES_COMPILED'] else []
Module_Math += [Module_regression] if 'math.regression' in options['MODULES_COMPILED'] else []
# ROM module
Module_ROM = [Module_POD] if 'rom.pod' in options['MODULES_COMPILED'] else []
Module_ROM += [Module_DMD] if 'rom.dmd' in options['MODULES_COMPILED'] else []
Module_ROM += [Module_SPOD] if 'rom.spod' in options['MODULES_COMPILED'] else []
## Decide which modules to compile
modules_list = Module_Math + Module_ROM if options['USE_COMPILED'] else []
## Main setup
setup(
name = 'pyLowOrder',
version = __version__,
author = 'Benet Eiximeno, Beka Begiashvili, Arnau Miro, Eusebio Valero, Oriol Lehmkuhl',
author_email = 'benet.eiximeno@bsc.es, beka.begiashvili@alumnos.upm.es, arnau.mirojane@bsc.es, eusebio.valero@upm.es, oriol.lehmkuhl@bsc.es',
maintainer = 'Benet Eiximeno, Arnau Miro',
maintainer_email = 'benet.eiximeno@bsc.es, arnau.mirojane@bsc.es',
ext_modules = cythonize(modules_list,
language_level = str(sys.version_info[0]), # This is to specify python 3 synthax
annotate = True # This is to generate a report on the conversion to C code
),
long_description = readme,
url = 'https://github.com/ArnauMiro/pyLowOrder',
packages = find_packages(exclude=('Converters','Examples','Deps','Testsuite','Tools')),
install_requires = ['numpy','matplotlib','cython>=3.0.0','h5py>=3.0.0','mpi4py>=4.0.0','nfft']
)