forked from GalacticDynamics-Oxford/Agama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.local.template
111 lines (101 loc) · 6.96 KB
/
Makefile.local.template
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
# 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 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.
#
# 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"
CXXFLAGS += -fPIC -fopenmp -Wall -O2 -march=native
# uncomment if you have a C++11-compatible compiler (it is not required but may be more efficient)
CXXFLAGS += -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 += -I/path/to/gsl/include
LINK_FLAGS += -L/path/to/gsl/lib -lgsl -lgslcblas
# uncomment and check the dirnames to build the Python plugin.
# 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 path to the python shared library is not so easy;
# one may end up printing all existing versions by typing
# > find / -name libpython* 2>/dev/null
# and then choosing the correct one manually (i.e. if the Python executable is in /opt/local/bin,
# the appropriate shared library would most likely be also in /opt/local/lib/..., etc.)
# The full path to numpy headers is easier to find: just type
# > python -c 'import numpy.distutils; print(numpy.distutils.misc_util.get_numpy_include_dirs())'
# 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 lib/agama.so
# to the PYTHONPATH environment variable (better to do put it into .bashrc or .cshrc):
# > export PYTHONPATH=/path/to/agama/lib:$PYTHONPATH (for bash)
# > setenv PYTHONPATH /path/to/agama/lib:$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 pytests folder.
# on MacOS the following line may need to be added:
# LINK_FLAGS += -L/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
# on some systems -lpython should be replaced by -lpython2.7 or -lpython2.6
COMPILE_FLAGS += -DHAVE_PYTHON -I/usr/include/python -I/path/to/numpy/core/include
LINK_FLAGS += -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 += -DHAVE_CUBA -I/path/to/cuba
#LINK_FLAGS += -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 += -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 += -DHAVE_GLPK -I/path/to/glpk
#LINK_FLAGS += -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 += -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 += -DHAVE_UNSIO -I/path/to/unsio
#LINK_FLAGS += -L/path/to/unsio -lunsio -lnemo