Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake development #76

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
46d0152
Dockerfile for development environment
stenczelt Jul 6, 2021
5ca5980
initial CMake files, building it up incrementally
stenczelt Jul 7, 2021
90036c2
libchord with glob + automatic dependency inspection
stenczelt Jul 7, 2021
adb4616
shared and static libchord as well
stenczelt Jul 7, 2021
1dc47ff
lib and bin dir centrally
stenczelt Jul 7, 2021
a88bc7c
likelyhood examples, lib for each of them
stenczelt Jul 7, 2021
c5a2114
cmake for drivers
stenczelt Jul 7, 2021
01ee82d
executables for examples
stenczelt Jul 7, 2021
e862cc3
executables for examples: the program is better off being compiled wi…
stenczelt Jul 7, 2021
8f15fba
CI action (seed) for CMake build
stenczelt Jul 7, 2021
6eca9d1
add MPI and link to everything
stenczelt Jul 7, 2021
5119428
intel dockerfile and reorganisation of docker files
stenczelt Jul 11, 2021
ed5ca64
newer CMake version in both dockerfiles
stenczelt Jul 12, 2021
5d18e48
switch for compilers, arguments need looking at
stenczelt Jul 12, 2021
2936de1
enforce linking with Fortran compiler
stenczelt Jul 12, 2021
28552da
action with intel compilers
stenczelt Jul 12, 2021
2587697
explicitly set the CXX compiler in intel build
stenczelt Jul 12, 2021
0ab564c
MacOS build
stenczelt Jul 12, 2021
fa7f5e4
building of the python extension module
stenczelt Jul 25, 2021
f7edac3
copy of setup.py for CMake - will modify
stenczelt Jul 25, 2021
fa43e07
nicer suffix finding
stenczelt Jul 25, 2021
a709d00
wrap python build into an option
stenczelt Jul 25, 2021
8e9f490
CMake for the python package
stenczelt Jul 26, 2021
aa8bff2
install python deps in GNU Dockerfile
stenczelt Jul 26, 2021
6dc3d85
directly build the python .so file
stenczelt Jul 26, 2021
36c57da
include the rest of the info in CMake setup.py template as well
stenczelt Jul 26, 2021
d04a227
add some classifiers for the package
stenczelt Jul 26, 2021
d72b992
readme location
stenczelt Jul 26, 2021
06064c2
CI: dependency installations
stenczelt Jul 26, 2021
3f84c80
CI: python3 in MacOS as well + tests
stenczelt Jul 26, 2021
67aec13
update docker files:
stenczelt Jul 26, 2021
b9adafc
install for user if needed
stenczelt Jul 26, 2021
b9a3d3d
MPI preprocessing directive same in CXX and Fortran
stenczelt Aug 10, 2021
7101e15
allow manual dispatch of CI as well
stenczelt Aug 10, 2021
7f71d62
CI no cron job in fork
stenczelt Aug 13, 2021
d79af5e
CI: update cmake steps
stenczelt Aug 13, 2021
f9da08a
compile option for GCC 10<= to understand MPI's interfaces
stenczelt Aug 13, 2021
bdca09a
CMake: allowed mixed AppleClang+gfortran build
stenczelt Sep 20, 2021
55e16c3
CI: MacOS with GCC & Clang as well
stenczelt Sep 20, 2021
31b6eec
CMake: change bin and lib paths
stenczelt Sep 20, 2021
ae03fa5
CI: correct syntax
stenczelt Sep 29, 2021
9cad3a9
Merge branch 'master' into cmake-dev
williamjameshandley Mar 5, 2022
93138ae
Bumped version number
williamjameshandley Mar 5, 2022
71a2798
Bumped version number
williamjameshandley Mar 5, 2022
03a52f9
Merge branch 'master' into cmake-dev
williamjameshandley Mar 5, 2022
9b15441
Merge branch 'master' into cmake-dev
williamjameshandley May 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: "0 0 * * *"
# don't run the CRON part in my fork
# schedule:
# - cron: "0 0 * * *"

workflow_dispatch:

Expand Down
83 changes: 83 additions & 0 deletions .github/workflows/run_cmake.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This workflow carries out the build of the package with CMake

name: CMake build

on:
push:
workflow_dispatch:

jobs:
build-GNU:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install gfortran libopenmpi-dev cmake python3-dev pip
pip install scipy matplotlib getdist anesthetic ipython mpi4py

- name: Run CMake
run: cmake -B build

- name: Build
run: make -C build install

- name: Test pypolychord
run: python run_pypolychord.py

- name: Test pypolychord (MPI)
run: mpirun -np 2 python run_pypolychord.py

build-Intel:
runs-on: ubuntu-latest
container:
image: intel/oneapi-hpckit

steps:
- uses: actions/checkout@v2

- name: Run CMake
run: cmake -B build -DCMAKE_Fortran_COMPILER=ifort -DCMAKE_CXX_COMPILER=icpc

- name: Build
run: make -C build install

- name: Test pypolychord
run: python run_pypolychord.py

- name: Test pypolychord (MPI)
run: mpirun -np 2 python run_pypolychord.py

build-MacOS:
runs-on: macos-latest
strategy:
matrix:
cc: [ gcc, clang ]

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
brew install cmake gcc openmpi
pip3 install numpy scipy matplotlib getdist anesthetic ipython mpi4py

- name: Run CMake - GCC
if: ${{ env.cc == 'gcc' }}
run: cmake -B build -DCMAKE_Fortran_COMPILER=gfortran-11 -DCMAKE_CXX_COMPILER=gcc-11

- name: Run CMake - AppleClang
if: ${{ env.cc == 'clang' }}
run: cmake -B build -DCMAKE_Fortran_COMPILER=gfortran-11

- name: Build
run: make -C build install

- name: Test pypolychord
run: python run_pypolychord.py

- name: Test pypolychord (MPI)
run: mpirun -np 2 python run_pypolychord.py
145 changes: 145 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
cmake_minimum_required(VERSION 3.4)

project(PolyChordLite Fortran)

# languages
enable_language(CXX)
enable_language(Fortran)

# options
option(MPI "Build with MPI" ON)
option(python "Build PyPolyChord package" ON)
option(python_user_install "Install Python package for user (--user)" ON)

# enforce matching of the CXX and Fortran compilers
if (NOT "${CMAKE_Fortran_COMPILER_ID}" MATCHES "${CMAKE_CXX_COMPILER_ID}"
AND NOT ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU" AND
"${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang"))
message(FATAL_ERROR "You need to use the same vendor for your C++ and Fortran compiler")
endif ()

# flags for all three compiler types
# todo: inspect the flags and implement in a nicer way
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel")
message("Using INTEL compilers")

set(CMAKE_Fortran_FLAGS "-fpp -fpic -assume noold_maxminloc -heap-arrays -ipo -O3 -no-prec-div -xHost -w -vec-report0 -qopt-report0")
set(CMAKE_CXX_FLAGS "-std=c++11 -fpic -ipo -O3 -no-prec-div -xHost -w -vec-report0 -qopt-report0")

add_compile_options("-nofor-main")
link_libraries("-nofor-main")

elseif ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
message("Using GNU compilers")

set(CMAKE_Fortran_FLAGS "-ffree-line-length-none -cpp -fPIC -fno-stack-arrays -Ofast")
set(CMAKE_CXX_FLAGS "-std=c++11 -fPIC -Ofast")

# for GitHub actions MacOS -- debug only
add_compile_options("-lstdc++")
link_libraries("-lstdc++")

if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 10.0)
# GCC 10 is complaining about MPI interfaces, turn this to warnings
SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif ()

elseif ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Cray")
message("Using Cray compilers")

set(CMAKE_Fortran_FLAGS "-fpp -fpic -qopenmp -dynamic")
set(CMAKE_CXX_FLAGS "-fpic -qopenmp -dynamic")

endif ()

# find MPI & link to everything from now on
if (MPI)
find_package(MPI REQUIRED)
message(STATUS "MPI_Fortran_COMPILER: ${MPI_Fortran_COMPILER}")
link_libraries(MPI::MPI_Fortran)
link_libraries(MPI::MPI_CXX)

# definitions
add_compile_definitions(USE_MPI)
endif (MPI)

# this will be module building directory, allows linking
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/generated/mods)

# on installation we get this prefix as well
set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR})

# target directories -> stuff installed in these directories
set(target_lib_dir ${PROJECT_SOURCE_DIR}/lib)
set(target_bin_dir ${PROJECT_SOURCE_DIR}/bin)

# directories where we want to make things
add_subdirectory(src)
add_subdirectory(likelihoods)

if (python)
#################################################################
# The Compiled .so file
#################################################################

# PyPolyChord stuff
message(STATUS "Enabling Python package build")
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)

# find out the suffix for the current python version
EXECUTE_PROCESS(
COMMAND ${Python3_EXECUTABLE} "-c" "import sysconfig;print(sysconfig.get_config_var('EXT_SUFFIX'))"
OUTPUT_VARIABLE python_so_suffix
)
STRING(REPLACE "\n" "" python_so_suffix ${python_so_suffix})
message(STATUS "Python shared object suffix is: ${python_so_suffix}")

# the extension module
add_library(_pypolychord SHARED pypolychord/_pypolychord.cpp $<TARGET_OBJECTS:objlib_chord>)
set_target_properties(_pypolychord
PROPERTIES
OUTPUT_NAME _pypolychord
PREFIX ""
SUFFIX "${python_so_suffix}"
)
# dependencies and includes
target_link_libraries(_pypolychord Python3::Python Python3::NumPy)
target_include_directories(_pypolychord PUBLIC src/polychord) # PolyChord headers for python extensions

# remember the place of this
set(target_python_so ${CMAKE_CURRENT_BINARY_DIR}/_pypolychord${python_so_suffix})

# place all outputs in one place
install(TARGETS _pypolychord
LIBRARY DESTINATION ${target_lib_dir})

#################################################################
# The simple python module
#################################################################

# hack ofr version
set(PACKAGE_VERSION "1.18.2")

set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup_cmake_template.py")
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
set(DEPS "${CMAKE_CURRENT_SOURCE_DIR}/pypolychord/__init__.py")
set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp") # dummy target for dependence

# fill in the variables of the setup.py file
configure_file(${SETUP_PY_IN} ${SETUP_PY})

# custom target
add_custom_command(OUTPUT ${OUTPUT}
COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} build
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
DEPENDS ${DEPS} _pypolychord)
add_custom_target(target ALL DEPENDS ${OUTPUT})

# installation with setup.py
if (python_user_install)
install(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} install)")
else (python_user_install)
install(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${SETUP_PY} install --user)")
endif (python_user_install)

endif (python)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ endif


ifeq ($(MPI),1)
FFLAGS += -DMPI
FFLAGS += -DUSE_MPI
CXXFLAGS += -DUSE_MPI
endif

Expand Down
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
:target: https://arxiv.org/abs/1506.00171
:alt: Open-access paper

PolyChord v 1.20.1

PolyChord v 1.21.0
Will Handley, Mike Hobson & Anthony Lasenby

[email protected]
Expand Down
40 changes: 40 additions & 0 deletions devtools/docker_gnu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM ubuntu:latest
MAINTAINER "Tamas K Stenczel <[email protected]>"

# Time Zone data
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/London

RUN apt-get -q update && \
apt-get -qy install --no-install-recommends \
# general
make \
gfortran \
libopenmpi-dev \
libblas-dev \
liblapack-dev \
libfftw3-3 \
# cmake and tools
cmake vim git wget ca-certificates \
g++ \
python3-dev pip \
&& rm -rf /var/lib/apt/lists/*

RUN pip3 install scipy matplotlib getdist anesthetic ipython mpi4py

# reinstall newer cmake, same as in the Intel image
ARG cmake_url=https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0-linux-x86_64.sh
ADD $cmake_url /
RUN file=$(basename "$cmake_url") && \
bash $file --prefix=/usr --skip-license && \
rm $file

# DEV use: oh-my-zsh instead of bash
# Uses "robbyrussell" theme (original Oh My Zsh theme), with no plugins
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)" -- \
-t robbyrussell
ENTRYPOINT "/usr/bin/zsh"
WORKDIR /work

# python executable
RUN echo "alias python=python3" >> /root/.zshrc
Loading