Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Fixed some issues related to getting the NetCDF libraries linked and …
Browse files Browse the repository at this point in the history
…included correctly without relying on environment variables
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 9, 2023
1 parent dd2730f commit 66c6187
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 48 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.20.1)
# Get version stored in text file
FILE(READ "version.txt" VERSION)
PROJECT(swiftest VERSION ${VERSION} LANGUAGES C Fortran)
MESSAGE(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}\nPROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}\n")

# Set some options the user may choose
OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" OFF)
OPTION(USE_OPENMP "Use OpenMP for parallelization" ON)
OPTION(USE_SIMD "Use SIMD vectorization" ON)
OPTION(BUILD_SHARED_LIBS "Build using shared libraries" ON)

# The following section is modified from Numpy f2py documentation
IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
Expand Down
59 changes: 31 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ RUN cd netcdf-fortran-4.6.1 && \

FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_driver
SHELL ["/bin/bash", "-c"]
ENV INSTALL_DIR="/usr/local"
COPY --from=build_deps ${INSTALL_DIR}/. ${INSTALL_DIR}/
ENV PATH /root/miniconda3/bin:$PATH

RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py311_23.5.2-0-Linux-x86_64.sh && \
/bin/bash Miniconda3-py311_23.5.2-0-Linux-x86_64.sh -b && \
/root/miniconda3/bin/conda init bash && \
source /root/.bashrc && conda update --all -y && \
conda install conda-libmamba-solver -y && \
conda config --set solver libmamba && \
conda install -c conda-forge scikit-build -y&& \
conda install -c anaconda cython -y

# The MACHINE_CODE_VALUE argument is a string that is used when compiling the swiftest_driver. It is appended to the "-x" compiler
# option: (-x${MACHINE_CODE_VALUE}). The default value is set to "sse2" which allows for certain SIMD instructions to be used while
Expand All @@ -103,39 +91,56 @@ ARG BUILD_TYPE="RELEASE"
# Additional CMAKE options:
ARG EXTRA_CMAKE_OPTIONS=""

# Swiftest
ENV INSTALL_DIR="/usr/local"
ENV NETCDF_HOME=${INSTALL_DIR}
ENV NETCDF_FORTRAN_HOME=${NETCDF_HOME}
ENV NETCDF_LIBRARY=${NETCDF_HOME}
ENV FOR_COARRAY_NUM_IMAGES=1
ENV OMP_NUM_THREADS=1

ENV FC="${ONEAPI_ROOT}/mpi/latest/bin/mpiifort"
ENV CC="${ONEAPI_ROOT}/mpi/latest/bin/mpicc -cc=icx"
ENV CXX="${ONEAPI_ROOT}/mpi/latest/bin/mpicc -cc=icpx"
ENV FFLAGS="-fPIC -standard-semantics"
ENV LDFLAGS="-L${INSTALL_DIR}/lib"
ENV LIBS="-lhdf5_hl -lhdf5 -lz"
ENV PATH /root/miniconda3/bin:$PATH

COPY --from=build_deps ${INSTALL_DIR}/. ${INSTALL_DIR}/
COPY ./cmake/ /swiftest/cmake/
COPY ./src/ /swiftest/src/
COPY ./CMakeLists.txt /swiftest/
COPY ./python/ /swiftest/python/
COPY ./swiftest/ /swiftest/swiftest/
COPY ./version.txt /swiftest/
COPY ./setup.py /swiftest/
COPY ./requirements.txt /swiftest/
COPY ./pyproject.toml /swiftest/
COPY ./environment.yml /swiftest/

RUN cd swiftest && \
cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-DMACHINE_CODE_VALUE=${MACHINE_CODE_VALUE} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DUSE_COARRAY=OFF \
-DBUILD_SHARED_LIBS=OFF \
${EXTRA_CMAKE_OPTIONS} && \
cmake --build build && \
cmake --install build
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py311_23.5.2-0-Linux-x86_64.sh && \
/bin/bash Miniconda3-py311_23.5.2-0-Linux-x86_64.sh -b && \
/root/miniconda3/bin/conda init bash && \
source /root/.bashrc && conda update --all -y && \
conda install conda-libmamba-solver -y && \
conda config --set solver libmamba && \
conda env create -f environment.yml && \
conda init bash && \
echo "conda activate swiftest-env" >> ~/.bashrc && \
source ~/.bashrc && \
conda install -c conda-forge scikit-build -y&& \
conda install -c anaconda cython -y

# RUN cd swiftest/python && \
# python setup.py build_ext --inplace
# RUN cd swiftest && \
# cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
# -DMACHINE_CODE_VALUE=${MACHINE_CODE_VALUE} \
# -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
# -DUSE_COARRAY=OFF \
# -DBUILD_SHARED_LIBS=OFF \
# ${EXTRA_CMAKE_OPTIONS} && \
# cmake --build build && \
# cmake --install build

# RUN cd swiftest && \
# pip install . -v

# This build target creates a container that executes just the driver program
FROM ubuntu:20.04 as driver
Expand Down Expand Up @@ -176,8 +181,6 @@ RUN conda update --all -y && \
conda env create -f environment.yml && \
conda init bash && \
echo "conda activate swiftest-env" >> ~/.bashrc && \
conda install -c anaconda cython -y && \
cd /opt/conda/pkgs/swiftest && pip install -e . && \
conda clean --all -y && \
mkdir -p /.astropy && \
chmod -R 777 /.astropy && \
Expand Down
1 change: 0 additions & 1 deletion cmake/Modules/SetUpNetCDF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ IF(NOT NETCDF_FOUND)
FIND_PACKAGE(NETCDF REQUIRED)
ENDIF(NOT NETCDF_FOUND)

INCLUDE_DIRECTORIES(${NETCDF_INCLUDE_DIR})
17 changes: 8 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
"""

from skbuild import setup
from Cython.Build import cythonize
import os

cmake_args = [
'-DCMAKE_BUILD_TYPE=RELEASE',
'-DMACHINE_CODE_VALUE="generic"',
'-DUSE_COARRAY:BOOL=OFF',
'-DUSE_OPENMP:BOOL=ON',
]

with open('version.txt') as version_file:
version = version_file.read().strip()
Expand Down Expand Up @@ -43,13 +48,7 @@
'Programming Language :: Python :: 3',
],
keywords='astronomy astrophysics planetary nbody integrator symplectic wisdom-holman',
cmake_args=[
'-DCMAKE_BUILD_TYPE=RELEASE',
'-DMACHINE_CODE_VALUE="generic"',
'-DUSE_COARRAY:BOOL=OFF',
'-DUSE_OPENMP:BOOL=ON',
'-DBUILD_SHARED_LIBS:BOOL=OFF'
],
cmake_args=cmake_args,
install_requires= [
'numpy>=1.24.3',
'scipy>=1.10.1',
Expand Down
17 changes: 10 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ ELSE ()
MESSAGE(FATAL_ERROR "Compiler not recognized!")
ENDIF ()

# Set some options the user may choose
OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" OFF)
OPTION(USE_OPENMP "Use OpenMP for parallelization" ON)
OPTION(USE_SIMD "Use SIMD vectorization" ON)
OPTION(BUILD_SHARED_LIBS "Build using shared libraries" ON)

INCLUDE(SetParallelizationLibrary)
INCLUDE(SetUpNetCDF)
IF (COMPILER_OPTIONS STREQUAL "Intel")
Expand Down Expand Up @@ -159,7 +153,16 @@ ADD_LIBRARY(${SWIFTEST_LIBRARY} ${SWIFTEST_src})
SET(SWIFTEST_DRIVER swiftest_driver)
ADD_EXECUTABLE(${SWIFTEST_DRIVER} ${DRIVER_src})

TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_FORTRAN_LIBRARIES} ${NETCDF_LIBRARIES} $ENV{LIBS})
TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_DRIVER} PUBLIC ${NETCDF_INCLUDE_DIR})
TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_INCLUDE_DIR})

IF (BUILD_SHARED_LIBS)
TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_LIBRARIES})
TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY})
ELSE ()
TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC ${NETCDF_LIBRARIES} $ENV{LIBS})
TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY} ${NETCDF_LIBRARIES} $ENV{LIBS})
ENDIF (BUILD_SHARED_LIBS)

IF(USE_OPENMP)
SET_PROPERTY(TARGET ${SWIFTEST_LIBRARY} ${SWIFTEST_DRIVER} APPEND_STRING PROPERTY COMPILE_FLAGS "${OpenMP_Fortran_FLAGS} ")
Expand Down
3 changes: 1 addition & 2 deletions swiftest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ ENDIF()

SET(SWIFTEST_BINDINGS _bindings)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${MOD})
ADD_CYTHON_TARGET(${SWIFTEST_BINDINGS})
ADD_LIBRARY(${SWIFTEST_BINDINGS} MODULE ${SWIFTEST_BINDINGS})
#MESSAGE(STATUS "Module linked libraries\nswiftest: ${SWIFTEST_LIBRARY}\nnetcdf: ${NETCDF_LIBRARIES}\nLIBS: $ENV{LIBS}")
TARGET_LINK_LIBRARIES(${SWIFTEST_BINDINGS} swiftest ${NETCDF_LIBRARIES} $ENV{LIBS})
PYTHON_EXTENSION_MODULE(${SWIFTEST_BINDINGS})
TARGET_INCLUDE_DIRECTORIES(${SWIFTEST_BINDINGS} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${MOD} ${NETCDF_INCLUDE_DIR})
INSTALL(TARGETS ${SWIFTEST_BINDINGS} LIBRARY DESTINATION swiftest)

0 comments on commit 66c6187

Please sign in to comment.