1 | ======================== Recipe 2 : using anaconda ========================= |
---|
2 | |
---|
3 | # install packages using macports |
---|
4 | sudo port install openmpi |
---|
5 | # activate what we have just installed (mandatory) |
---|
6 | sudo port select mpi openmpi-mp-fortran |
---|
7 | # my anaconda is in my $HOME - no need for sudo |
---|
8 | pip install mpi4py |
---|
9 | conda install netcdf4 |
---|
10 | |
---|
11 | compile the remap library |
---|
12 | run the remap.py script |
---|
13 | |
---|
14 | ==================== Checking which libraries are loaded ====================== |
---|
15 | |
---|
16 | Useful to make sure that mpirun, remap and python use the same MPI library. |
---|
17 | |
---|
18 | sudo dtruss -f -t open sudo -u $(whoami) mpirun -np 1 python test.py 2>out |
---|
19 | grep mpich out |
---|
20 | grep openmpi out |
---|
21 | |
---|
22 | where test.py contains |
---|
23 | from mpi4py import MPI |
---|
24 | import netCDF4 |
---|
25 | import ctypes as ct |
---|
26 | import os |
---|
27 | test = ct.cdll.LoadLibrary(os.path.realpath('libmapper.so')) |
---|
28 | |
---|
29 | If grep finds both mpich and openmpi, something is wrong ! |
---|
30 | |
---|
31 | ====================== Various ways to mess up python/netCDF/MPI on MacOS ==================== |
---|
32 | |
---|
33 | Anaconda vs macports python |
---|
34 | =========================== |
---|
35 | I have several pythons installed : 3 from Apple, one from macports and one from the Anaconda distribution, which is the default on my path. |
---|
36 | |
---|
37 | * find whether we use python from MacPorts or anaconda |
---|
38 | which python |
---|
39 | the one from macports is in /opt/local/bin |
---|
40 | |
---|
41 | * check active macports python version |
---|
42 | port select python |
---|
43 | (mine : python27) |
---|
44 | |
---|
45 | * if desired, set the path to avoid anaconda |
---|
46 | echo $PATH |
---|
47 | result : /Users/dubos/anaconda/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin |
---|
48 | export PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin |
---|
49 | |
---|
50 | Below, [with macports] assumes that « which python » finds /opt/local/bin/python » while [with anaconda] assumes it finds the anaconda-provided python. |
---|
51 | |
---|
52 | Python-netCDF |
---|
53 | ============= |
---|
54 | [with macports] : |
---|
55 | sudo port install py-netcdf4 |
---|
56 | |
---|
57 | [with anaconda] : |
---|
58 | conda install netcdf4 |
---|
59 | Notice that this will also compile its own instance of netCDF. |
---|
60 | |
---|
61 | Notice that in principle one could install python-netcdf using pip or easy_install. In my case it fails - there is a version mismatch for the HDF library at runtime |
---|
62 | |
---|
63 | MPI |
---|
64 | === |
---|
65 | Macports can install openmpi, mpich or both (I have both). If both are installed one is activated by « port select ». |
---|
66 | |
---|
67 | It will install it for a specific compiler. |
---|
68 | * checking your active compiler |
---|
69 | port select gcc |
---|
70 | * installing openmpi |
---|
71 | sudo port install openmpi |
---|
72 | * checking for which gcc openmpi has been compiled |
---|
73 | port installed openmpi-default |
---|
74 | * checking your active mpi |
---|
75 | port select mpi |
---|
76 | * selecting openmpi (for example) |
---|
77 | sudo port select mpi openmpi-mp-fortran |
---|
78 | |
---|
79 | MPI4py |
---|
80 | ====== |
---|
81 | It is important to compile the mapper library with the same MPI as mpi4py ! |
---|
82 | easy_install fails on my Mac so I must use pip |
---|
83 | |
---|
84 | [with MacPorts] : |
---|
85 | sudo port install py-pip |
---|
86 | sudo port select pip pip27 |
---|
87 | sudo pip install mpi4py |
---|
88 | |
---|
89 | [with anaconda] : pip is already installed, |
---|
90 | which pip |
---|
91 | pip install mpi4py |
---|
92 | |
---|
93 | |
---|