-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathMakefile.local.template
More file actions
132 lines (119 loc) · 8.44 KB
/
Makefile.local.template
File metadata and controls
132 lines (119 loc) · 8.44 KB
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
# a template for Makefile.local containing all machine-specific settings
# copy/rename this file to Makefile.local and change the settings and paths where needed;
# alternatively, you may run
# > python setup.py install
# which will figure out the settings and create Makefile.local itself
# compiler and linker: override the gnumake-default values,
# but only not if environment variables or command-line arguments to make are not set
ifeq ($(origin CXX),default)
FC = g++
endif
ifeq ($(origin FC),default)
FC = gfortran
endif
LINK = $(CXX)
# compilation and linking flags:
# CXXFLAGS apply to the complilation of both the AGAMA shared library and all programs that use it;
# COMPILE_FLAGS are the additional flags for the compilation of the shared library
# (but not example programs), and determine the available features (depending on the 3rd-party libraries);
# LINK_FLAGS determine the linker option for the shared library only.
# COMPILE_FLAGS_ALL: compilation flags for both the shared library and any programs that use it
# COMPILE_FLAGS_LIB: additional compilation flags for the library files only (src/*.cpp)
# LINK_FLAGS_ALL: linking flags for both the shared library (agama.so) and any executable programs, regardless of how they are linked
# LINK_FLAGS_LIB: additional linking flags for the shared library only (agama.so)
# LINK_FLAGS_LIB_AND_EXE_STATIC: additional linking flags for the shared library (agama.so) and executables that use the static library (agama.a)
# LINK_FLAGS_EXE_SHARED: additional linking flags for executables which use the shared library (agama.so)
# A note about optimization-specific flags: -march=native is not supported on some machines,
# and may be replaced by -march=core2 or whatever your processor name is.
# Intel compiler tends to perform very aggressive floating-point optimizations, which may lead to
# irreproducible run-to-run results because of subtle interplay between loop vectorization, OpenMP
# parallelization, and memory alignment; to prevent this, add the flag "-qno-opt-dynamic-align" to CXXFLAGS.
# Also do not use -O3 with Intel compiler and the Eigen library - it thwarts some of linear algebra routines.
# These problems may be avoided altogether by using -fp-model:precise switch, but it prevents many more
# useful optimizations.
# The clang compiler used by default on some (many?) Mac OS versions does not support OpenMP (duh!...),
# so one has to either disable it by removing the "-fopenmp" flag below (and of course sacrifice a lot
# in performance), or install an alternative compiler such as gcc or icc.
# Finally, -fPIC is necessary on 64-bit systems for compiling into a shared library
# (dunno why it isn't on by default!), and since the shared library agama.so includes all relevant
# third-party libraries (GSL, UNSIO, etc.), they also must be compiled with this flag!
# E.g., in the case of GSL you would need to run its "./configure" script with an extra option "CFLAGS=-fPIC"
COMPILE_FLAGS_ALL += -fPIC -fopenmp -Wall -O2 -march=native
LINK_FLAGS_ALL += -fopenmp
# uncomment if you have a C++11-compatible compiler (it is not required but may be more efficient)
COMPILE_FLAGS_ALL += -std=c++11
# GSL library is required; check the path names;
# it is recommended to link against the static library libgsl.a, so that it will be included into
# the shared library agama.so - for this you may need to replace -L/path -lgsl with the full path
# to the static library (e.g. /usr/local/lib/libgsl.a, and similarly for libcblas.a), because
# by default the linker prefers shared libgsl.so over static libgsl.a;
# note that GSL must be compiled with -fPIC flag
COMPILE_FLAGS_LIB += -I/path/to/gsl/include
LINK_FLAGS_LIB_AND_EXE_STATIC += -L/path/to/gsl/lib -lgsl -lgslcblas
# uncomment and check the dirnames to build the Python extension module.
# It gets a bit tricky when there is more than one version of Python installed in the system,
# e.g. a Mac OS with a system-default /usr/bin/python, another one coming from MacPorts or Homebrew,
# and yet another one from Anaconda. In this case one has to be careful in choosing the correct paths.
# Usually the default python version can be found by typing "which python" in the terminal,
# but getting the necessary compilation and linking flags is not so easy; one can try
# > python-config --includes --ldflags
# (or pythonX.Y-config, where X.Y is the version), and put these into COMPILE_FLAGS_LIB and LINK_FLAGS_LIB
# respectively, but this may not be enough.
# The full path to numpy headers is easier to find: just type
# > python -c 'import numpy; print(numpy.get_include())'
# Linking to an incorrect version of Python (i.e. not the one that is invoked when you type 'python'
# in the terminal) may result in various errors when trying to "import agama" within Python, such as
# "ImportError: numpy.core.multiarray failed to import", or
# "RuntimeError: module compiled against API version 9 but this version of numpy is 8", or
# "Fatal Python error: PyThreadState_Get: no current thread".
# In order to make the Agama extension available to Python, you may need to add the path to agama.so
# to the PYTHONPATH environment variable (better to do put it into .bashrc or .cshrc):
# > export PYTHONPATH=/path/to/agama:$PYTHONPATH (for bash)
# > setenv PYTHONPATH /path/to/agama:$PYTHONPATH (for csh/tcsh)
# If everything works well, you should be able to run
# > python -c 'import agama; print(agama.__version__)'
# or, better, run some of the example scripts in the "py" folder.
# Running the setup.py script to do all these chores is a highly recommended alternative.
COMPILE_FLAGS_LIB += -DHAVE_PYTHON -I/usr/include/python -I/path/to/numpy/core/include
LINK_FLAGS_LIB += -lpython
# uncomment the three lines below and adjust the paths to use Cuba library for multidimensional integration
# (otherwise use Cubature library bundled with the code).
# Note that Cuba is apparently less accurate at least for CylSpline integrands, so is not recommended.
#COMPILE_FLAGS_LIB += -DHAVE_CUBA -I/path/to/cuba
#LINK_FLAGS_LIB_AND_EXE_STATIC += -L/path/to/cuba -lcuba
# uncomment the lines below to use Eigen library for optimized linear algebra operations
# (strongly recommended for certain tasks, e.g. Schwarzschild modelling; otherwise slower
# internal and GSL analogues will be used); it's a header-only library and needs no linking
#COMPILE_FLAGS_LIB += -DHAVE_EIGEN -I/path/to/eigen
# uncomment to use the GNU linear programming library (needed for linear optimization solver);
# note that if you have CVXOPT, then GLPK is not needed
#COMPILE_FLAGS_LIB += -DHAVE_GLPK -I/path/to/glpk
#LINK_FLAGS_LIB_AND_EXE_STATIC += -L/path/to/glpk -lglpk
# uncomment to enable the quadratic optimization solver CVXOPT (written in Python);
# this only has effect if HAVE_PYTHON is defined.
# The easiest way to install CVXOPT is via 'pip install --user cvxopt', but this only gets you
# the binary distribution (available from Python, but not immediately useful to the C++ library).
# Therefore, you also need to download the source distribution, unpack it somewhere, and use this
# path appended with "src/C" in the INCLUDES directive below (this folder should contain cvxopt.h),
# or just copy the files cvxopt.h and blas_redefines.h into agama/src.
#COMPILE_FLAGS_LIB += -DHAVE_CVXOPT -I/path/to/cvxopt/src/C
# uncomment the lines below to use UNSIO library for input/output of N-body snapshots
# in NEMO and GADGET formats (in its absense only the text format is available)
# same considerations for static linking as for GSL
#COMPILE_FLAGS_LIB += -DHAVE_UNSIO -I/path/to/unsio
#LINK_FLAGS_LIB_AND_EXE_STATIC += -L/path/to/unsio -lunsio -lnemo
# some OS-dependent wizardry needed to ensure that the executables are linked to
# the shared library using a relative path, so that it will be looked for in the same
# folder as the executables (a symlink is created as exe/agama.so -> agama.so).
# This allows the executables to be copied/moved to and run from any other folder
# without the need to put agama.so into a system-wide folder such as /usr/local/lib,
# or add it to LD_LIBRARY_PATH, provided that a copy of the shared library or a symlink
# to it resides in the same folder as the executable program.
ifeq ($(shell uname -s),Darwin)
# on MacOS we need to modify the header of the shared library, which is then
# automatically used to embed the correct relative path into each executable
LINK_FLAGS_LIB += -Wl,-install_name,@executable_path/agama.so
else
# on Linux we need to pass this flag to every compiled executable in the exe/ subfolder
LINK_FLAGS_EXE_SHARED += -Wl,-rpath,'$$ORIGIN'
endif