Skip to content

Commit

Permalink
dont even try to use cmake in macos
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Dec 15, 2023
1 parent 7d16d16 commit 525b3d3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 144 deletions.
56 changes: 7 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ set(VERSION "\"4.0\"")
set(nnpdfcpp_VERSION 4.0)

# check for dependencies
find_package(PythonInterp 3 REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_search_module(LIBARCHIVE REQUIRED libarchive)
pkg_search_module(SQLITE3 REQUIRED sqlite3)
pkg_search_module(GSL REQUIRED gsl)
pkg_search_module(YAML REQUIRED yaml-cpp)


option(ENABLE_OPENMP "Enable openmp parallelism." OFF)
option(ENABLE_OPENMPI "Enable openMPI parallelism." OFF)
option(ENABLE_TESTS "Enable unit test" OFF)
option(ENABLE_ASAN "Enable ASAN" OFF)
option(ENABLE_DEAD_STRIP "Enable use of flag `-dead_strip-dylibs`" OFF)
option(NNPDF_DEV "n3fit and validphys in developer mode" ON)
set(PROFILE_PREFIX "" CACHE STRING "Where you store the 'data' folder. Default empty uses CMAKE_INSTALL_PREFIX/share/NNPDF.")

Expand All @@ -49,19 +45,6 @@ else (PROFILE_PREFIX)
set(PROFILE_PREFIX "${CMAKE_INSTALL_PREFIX}/share/NNPDF")
endif()

if (ENABLE_OPENMPI)
set(LIBNNPDF_HAVE_MPI "#define OPENMPI")
endif()

set(LIBNNPDF_HAVE_SSE "#define SSE_CONV")


if(ENABLE_OPENMP)
find_package(OpenMP REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif(ENABLE_OPENMP)

# LHAPDF
find_program(LHAPDF_CONFIG lhapdf-config REQUIRED)
if (LHAPDF_CONFIG)
Expand Down Expand Up @@ -99,50 +82,25 @@ if (APFEL_CONFIG)
set(APFEL_LIBRARIES ${APFEL_LIBRARIES} CACHE STRING INTERNAL)
endif(APFEL_CONFIG)

set(DEFAULT_CXX_OPTIONS "-Wall -Wextra -march=nocona -mtune=haswell -fvisibility-inlines-hidden -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe")
set(DEFAULT_CXX_OPTIONS "-Wall -Wextra -fvisibility-inlines-hidden -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe")

#strip linker flags to avoid duplication of asan flags
string(REPLACE "-fsanitize=address" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
string(REPLACE "-fsanitize=address" "" CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")

set(CMAKE_ALL_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")

#dead_strip_dylibs can cause issues, warn if we remove it
if(ENABLE_DEAD_STRIP)
if(NOT ${CMAKE_ALL_LINKER_FLAGS} MATCHES "-Wl,-dead_strip_dylibs")
message(WARNING "ENABLE_DEAD_STRIP was set true but there were no occurences of the flag `dead_strip_dylibs` found")
endif(NOT ${CMAKE_ALL_LINKER_FLAGS} MATCHES "-Wl,-dead_strip_dylibs")
else(ENABLE_DEAD_STRIP)
if(CMAKE_ALL_LINKER_FLAGS MATCHES "-Wl,-dead_strip_dylibs")
message(WARNING "removing all occurence of flag: `dead_strip_dylibs` (default behaviour). If you are sure this flag is required then ENABLE_DEAD_STRIP")
string(REPLACE "-Wl,-dead_strip_dylibs" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
string(REPLACE "-Wl,-dead_strip_dylibs" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
string(REPLACE "-Wl,-dead_strip_dylibs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
#executable linker flags get set later
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}" CACHE STRING "Flags used by the linker during the creation of modules during all build types" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" CACHE STRING "Flags used by the linker during the creation of shared libraries during all build types" FORCE)
endif(CMAKE_ALL_LINKER_FLAGS MATCHES "-Wl,-dead_strip_dylibs")
endif(ENABLE_DEAD_STRIP)

# Flags for ASAN
if(ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "-fsanitize=address ${DEFAULT_CXX_OPTIONS} ${LHAPDF_CXX_FLAGS} ${APFEL_CXX_FLAGS} ${YAML_CFLAGS} ${SQLITE3_CFLAGS} ${GSL_CFLAGS} ${LIBARCHIVE_CFLAGS}" CACHE STRING "compile flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g" CACHE STRING "debug compile flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=address ${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "linker flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-fsanitize=address ${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "debug linker flags" FORCE)
else(ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${DEFAULT_CXX_OPTIONS} ${LHAPDF_CXX_FLAGS} ${APFEL_CXX_FLAGS} ${YAML_CFLAGS} ${SQLITE3_CFLAGS} ${GSL_CFLAGS} ${LIBARCHIVE_CFLAGS}" CACHE STRING "compile flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g" CACHE STRING "debug compile flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "linker flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "debug linker flags" FORCE)
endif(ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${DEFAULT_CXX_OPTIONS} ${LHAPDF_CXX_FLAGS} ${APFEL_CXX_FLAGS} ${YAML_CFLAGS} ${SQLITE3_CFLAGS} ${GSL_CFLAGS} ${LIBARCHIVE_CFLAGS}" CACHE STRING "compile flags" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g" CACHE STRING "debug compile flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "linker flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING "debug linker flags" FORCE)

# libnnpdf configuration
add_subdirectory(libnnpdf)

# evolven3fit
add_subdirectory(evolven3fit)
install(FILES ${PROJECT_SOURCE_DIR}/validphys2/src/validphys/datafiles/theory.db DESTINATION share/NNPDF)
install(FILES ${PROJECT_SOURCE_DIR}/validphys2/src/validphys/datafiles/theory.db DESTINATION ${PROFILE_PREFIX}/)

if(NNPDF_DEV)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-deps -e ${PROJECT_SOURCE_DIR})")
Expand Down
7 changes: 0 additions & 7 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ requirements:
- recommonmark
- sphinx_rtd_theme >0.5
- sphinxcontrib-bibtex
- curio >=1.0
- pineappl >=0.6.2
- eko >=0.14.0
- fiatlux
Expand All @@ -63,12 +62,6 @@ test:
- pytest
- coverage
- pytest-mpl
#Build dependencies for catch tests
- {{ compiler("cxx") }}
- {{ compiler("c") }}
- sysroot_linux-64==2.17 # [linux]
- swig ==3.0.10
- cmake

source_files:
- "*"
Expand Down
100 changes: 12 additions & 88 deletions doc/sphinx/source/get-started/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ explained above, if the user has not already done so.
Installation from source on M1/M2 Macs
--------------------------------------

Installation on M1/M2 Macs is not directly supported, so everything needs to be
built manually. The following steps are required:
Installation on M1/M2 Macs directly with cmake is not directly supported.
So it is better to install directly with ``pip``, this means ``evolven3fit``.
If you install following this tutorial PDFs will need to be evolved with ``evolven3fit_new``.
Make sure you have a valid installation of ``pandoc`` available in your system:

1. Clone the repositories

Expand All @@ -255,33 +257,27 @@ built manually. The following steps are required:
cd nnpdfgit
git clone [email protected]:NNPDF/nnpdf.git
git clone [email protected]:NNPDF/binary-bootstrap.git
git clone https://github.com/scarrazza/apfel.git
2. Execute binary bootstrap to set the channels in ``.condarc``
2. Execute binary bootstrap to set the channels in ``.condarc`` and install miniconda

.. code::
./binary-bootstrap/bootstrap.sh
3. Setup conda environment using python 3.9
3. Setup conda environment using python 3.10

.. code::
conda create -n nnpdf-dev python=3.9
conda create -n nnpdf-dev python=3.10
conda activate nnpdf-dev
4. Install ARM compiler

.. code::
conda install clangxx_osx-arm64
5. LHAPDF
4. Install ARM compiler and LHAPDF (skip if you don't want to install LHAPDF):

Download version 6.4.0 and decompress

.. code::
conda install clangxx_osx-arm64
wget -O LHAPDF-6.4.0.tar.gz https://lhapdf.hepforge.org/downloads/?f=LHAPDF-6.4.0.tar.gz
tar -xzvf LHAPDF-6.4.0.tar.gz
rm LHAPDF-6.4.0.tar.gz
Expand Down Expand Up @@ -311,85 +307,13 @@ built manually. The following steps are required:
lhapdf install CT18NNLO
python -c "import lhapdf"
6. Apfel


First, we need to install some dependencies:
5. Install NNPDF packages (``validphys``, ``n3fit`` and ``evolven3fit_new``) and its dependencies

.. code::
conda install pkg-config swig cmake
Then build it

.. code::
cd ../../../apfel
autoreconf -f -i
PYTHON=$(which python) ./configure --prefix=$CONDA_PREFIX
make clean
make -j
make install
7. validphys

First install reportengine and validobj, then validphys itself:

.. code::
pip install reportengine validobj
cd ../nnpdf/validphys2
pip install -e .
8. nnpdf

Install other dependencies

.. code::
conda install libarchive sqlite gsl yaml-cpp
Run cmake in nnpdf/build directory:

.. code::
cd ..
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
Edit the file ``nnpdfgit/nnpdf/CMakeLists.txt`` :

- on line 8 change the option to true, so it says:

.. code::
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
- comment out line 58 (:code:`set(LIBNNPDF_HAVE_SSE "#define SSE_CONV")`)

- line 104 should read:

.. code::
set(DEFAULT_CXX_OPTIONS "-Wall -Wextra -fvisibility-inlines-hidden -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe")
(so delete ``-march=nocona -mtune=haswell``).

Then make:

.. code::
make -j
make install
Install remaining packages

.. code::
pip install seaborn prompt_toolkit scipy psutil hyperopt
9. Install tensorflow
6. Note for tensorflow

Not specifying versions will install at the time of writing macos 2.12.0 and metal 0.8.0, which both work.
They only give warnings on the optimizers, that the legacy versions are faster.
Expand All @@ -401,7 +325,7 @@ built manually. The following steps are required:
pip install tensorflow-macos==2.9.2
pip install tensorflow-metal==0.5.0
10. Test
7. Test

.. code::
Expand Down

0 comments on commit 525b3d3

Please sign in to comment.