CRPropa / CRPropa3

CRPropa is a public astrophysical simulation framework for propagating extraterrestrial ultra-high energy particles. https://crpropa.github.io/CRPropa3/
https://crpropa.desy.de
GNU General Public License v3.0
72 stars 69 forks source link

Installing CRPropa on macOS #509

Closed carmeloevoli closed 6 days ago

carmeloevoli commented 1 week ago

Ciao,

I want to share my experience in installing CRPropa on macOS, specifically tailored for systems where the setup may differ from the official documentation.

Note: The only bottleneck was installing GALACTICMAGNETICLENS due to a conflict with the Eigen3 library. I recommend keeping this library out of the package and having it external and optional. My installation works using the -DENABLE_GALACTICMAGNETICLENS=FALSE option.

System Information:

Installation Steps

1. Use Homebrew to install all necessary packages:

brew install python virtualenv hdf5 fftw cfitsio muparser libomp numpy swig llvm zlib

2. Create the relevant aliases for Python and LLVM paths:

export PYTHON_DIR=/opt/homebrew/Cellar/python@3.13/3.13.0_1
export PYTHON_FRAMEWORK=/opt/homebrew/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/
export LLVM_DIR=/opt/homebrew/Cellar/llvm/19.1.3

3. Download the CRPropa source code and create a virtual environment directory:

git clone https://github.com/CRPropa/CRPropa3.git
export CRPROPA_DIR=$HOME/.virtualenvs/crpropa
mkdir -p $CRPROPA_DIR

4. Create and activate a virtual environment for the installation:

virtualenv -p /opt/homebrew/bin/python3 $CRPROPA_DIR
source $CRPROPA_DIR/bin/activate
pip install numpy
pip install matplotlib

5. Run the cmake command with the specified options to prepare the installation:

cmake .. \
-DCMAKE_INSTALL_PREFIX=$CRPROPA_DIR \
-DPython_EXECUTABLE=$PYTHON_DIR/bin/python3 \
-DPython_LIBRARY=$PYTHON_FRAMEWORK/lib/libpython3.13.dylib \
-DPython_INCLUDE_PATH=$PYTHON_FRAMEWORK/include/python3.13 \
-DCMAKE_C_COMPILER=$LLVM_DIR/bin/clang \
-DCMAKE_CXX_COMPILER=$LLVM_DIR/bin/clang++ \
-DOpenMP_CXX_FLAGS="-fopenmp -I$LLVM_DIR/lib/clang/19/include" \
-DOpenMP_C_FLAGS="-fopenmp -I$LLVM_DIR/lib/clang/19/include" \
-DOpenMP_libomp_LIBRARY=$LLVM_DIR/lib/libomp.dylib \
-DCMAKE_SHARED_LINKER_FLAGS="-L$LLVM_DIR/lib -lomp -Wl,-rpath,$LLVM_DIR/lib" \
-DOpenMP_C_LIB_NAMES=libomp \
-DOpenMP_CXX_LIB_NAMES=libomp \
-DNO_TCMALLOC=TRUE \
-DENABLE_GALACTICMAGNETICLENS=FALSE

6. Check the configuration using ccmake:

ccmake ..
lukasmerten commented 6 days ago

Hi @carmeloevoli Thanks for providing your detailed installation instructions. The Galactic lenses are indeed a problem, not only on MacOS. We are working on a new version of the lenses that also include the latest Galactic magnetic field models.