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

Commit

Permalink
Another major restructuring to place the python code more central to …
Browse files Browse the repository at this point in the history
…the project. More inclusion of scikit-build stuff in the cmake files, though not complete
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 8, 2023
1 parent 2fea0be commit 447eaaf
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 127 deletions.
72 changes: 32 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,58 @@
# You should have received a copy of the GNU General Public License along with Swiftest.
# If not, see: https://www.gnu.org/licenses.

# CMake project file for SWIFTEST

# CMake project file for Swiftest
##################################################
# Define the project and the depencies that it has
##################################################

CMAKE_MINIMUM_REQUIRED(VERSION 3.20.1)
# Get version stored in text file
FILE(READ "version.txt" VERSION)
PROJECT(swiftest VERSION ${VERSION} LANGUAGES Fortran)
PROJECT(swiftest VERSION ${VERSION} LANGUAGES C Fortran)

# The following section is modified from Numpy f2py documentation
IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n")
ENDIF()

# Ensure scikit-build modules
IF (NOT SKBUILD)
FIND_PACKAGE(Python3 COMPONENTS Interpreter Development REQUIRED)
EXECUTE_PROCESS(
COMMAND "${Python3_EXECUTABLE}"
-c "import os, skbuild; print(os.path.dirname(skbuild.__file__))"
OUTPUT_VARIABLE SKBLD_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
LIST(APPEND CMAKE_MODULE_PATH "${SKBLD_DIR}/resources/cmake")
MESSAGE(STATUS "Looking in ${SKBLD_DIR}/resources/cmake for CMake modules")
ENDIF()

# scikit-build style includes
FIND_PACKAGE(Cython REQUIRED)
SET(PYTHON_EXTENSION_MODULE_SUFFIX "${Python3_SOABI}" CACHE STRING "Suffix for python extension modules")

# Communicate version number and other CMake build variables to the source code
SET(SETUP_PY_IN "${PROJECT_SOURCE_DIR}/setup.py.in")
SET(SETUP_PY_OUT "${PROJECT_SOURCE_DIR}/setup.py")
CONFIGURE_FILE(${SETUP_PY_IN} ${SETUP_PY_OUT})

INCLUDE(CTest)

# Add our local modlues to the module path
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# Uncomment if it is required that Fortran 90 is supported
IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
MESSAGE(FATAL_ERROR "Fortran compiler does not support F90")
ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)


IF (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
SET(COMPILER_OPTIONS "Intel" CACHE STRING "Compiler identified as Intel")
ELSEIF (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
SET(COMPILER_OPTIONS "GNU" CACHE STRING "Compiler identified as gfortran")
ELSE ()
MESSAGE(FATAL_ERROR "Compiler not recognized!")
ENDIF ()
# Add our local modules to the module path
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# 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(${CMAKE_MODULE_PATH}/SetParallelizationLibrary.cmake)
INCLUDE(${CMAKE_MODULE_PATH}/SetUpNetCDF.cmake)
IF (COMPILER_OPTIONS STREQUAL "Intel")
INCLUDE(${CMAKE_MODULE_PATH}/SetMKL.cmake)
ENDIF ()

# This INCLUDE statement executes code that sets the compile flags for DEBUG,
# RELEASE, PROFILING, and TESTING.
INCLUDE(${CMAKE_MODULE_PATH}/SetFortranFlags.cmake)

INCLUDE_DIRECTORIES($ENV{NETCDF_FORTRAN_HOME}/include;$ENV{NETCDF_HOME}/include)
############################################################
# Define the actual files and folders that make up the build
############################################################


# Define some directories
SET(SRC ${CMAKE_SOURCE_DIR}/src)
SET(LIB ${CMAKE_SOURCE_DIR}/lib)
SET(BIN ${CMAKE_SOURCE_DIR}/bin)
SET(MOD ${CMAKE_SOURCE_DIR}/include)
#SET(TEST ${CMAKE_SOURCE_DIR}/test)
SET(PY ${CMAKE_SOURCE_DIR}/python)
#SET(TEST ${CMAKE_SOURCE_DIR}/tests)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB})
Expand All @@ -76,7 +69,6 @@ SET(CMAKE_Fortran_MODULE_DIRECTORY ${MOD})

# The source for the SWIFTEST binary and have it placed in the bin folder
ADD_SUBDIRECTORY(${SRC} ${BIN})
ADD_SUBDIRECTORY(${PY})

# # Set up test directory
# ENABLE_TESTING()
Expand Down
38 changes: 17 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_deps

ENV INSTALL_DIR="/usr/local"
ENV CC="${ONEAPI_ROOT}/compiler/latest/linux/bin/icx"
ENV FC="${ONEAPI_ROOT}/compiler/latest/linux/bin/ifx"
ENV CXX="${ONEAPI_ROOT}/compiler/latest/linux/bin/icpx"
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 F77="${FC}"
ENV CFLAGS="-fPIC"

# Get the HDF5, NetCDF-C, and NetCDF-Fortran libraries
RUN wget -qO- https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.14/hdf5-1.14.1/src/hdf5-1.14.1-2.tar.gz | tar xvz && \
Expand Down Expand Up @@ -65,7 +66,6 @@ ENV HDF5_INCLUDE_DIR="${HDF5_ROOT}/include"
ENV HDF5_PLUGIN_PATH="${HDF5_LIBDIR}/plugin"

# NetCDF-Fortran library
ENV CFLAGS="-fPIC"
ENV FCFLAGS="${CFLAGS} -standard-semantics"
ENV FFLAGS=${CFLAGS}
ENV CPPFLAGS="-I${INSTALL_DIR}/include"
Expand All @@ -77,7 +77,8 @@ RUN cd netcdf-fortran-4.6.1 && \

FROM intel/oneapi-hpckit:2023.1.0-devel-ubuntu20.04 as build_driver
SHELL ["/bin/bash", "-c"]
COPY --from=build_deps /usr/local/. /usr/local/
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 && \
Expand All @@ -89,12 +90,6 @@ RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py311_23.5.2-0-Linux-x86
conda install -c conda-forge scikit-build -y&& \
conda install -c anaconda cython -y

ENV INSTALL_DIR="/usr/local"
ENV CC="${ONEAPI_ROOT}/compiler/latest/linux/bin/icx"
ENV FC="${ONEAPI_ROOT}/compiler/latest/linux/bin/ifx"
ENV CXX="${ONEAPI_ROOT}/compiler/latest/linux/bin/icpx"
ENV F77="${FC}"

# 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
# remaining # compatible with a wide range of CPUs. To get the highest performance, you can pass "host" as an argument, but the
Expand All @@ -119,7 +114,7 @@ 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/usr/local/lib"
ENV LDFLAGS="-L${INSTALL_DIR}/lib"
ENV LIBS="-lhdf5_hl -lhdf5 -lz"

COPY ./cmake/ /swiftest/cmake/
Expand All @@ -138,8 +133,8 @@ RUN cd swiftest && \
cmake --build build && \
cmake --install build

RUN cd swiftest/python && \
python setup.py build_ext --inplace
# RUN cd swiftest/python && \
# python setup.py build_ext --inplace


# This build target creates a container that executes just the driver program
Expand All @@ -159,19 +154,20 @@ COPY --from=build_driver /usr/local/lib/libswiftest.a /
FROM scratch as export_module
COPY --from=build_driver /swiftest/include/ /swiftest/


# This build target creates a container with a conda environment with all dependencies needed to run the Python front end and
# analysis tools
FROM continuumio/miniconda3 as python
SHELL ["/bin/bash", "--login", "-c"]
ENV INSTALL_DIR="/usr/local"
ENV CONDA_DIR="/opt/conda"
ENV SHELL="/bin/bash"
ENV PATH="/opt/conda/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/lib"
ENV PATH="${CONDA_DIR}/bin:${PATH}"
ENV LD_LIBRARY_PATH="${INSTALL_DIR}/lib"

COPY --from=build_driver /usr/local/bin/swiftest_driver /opt/conda/bin/swiftest_driver
COPY --from=build_driver /usr/local/lib/libswiftest.a /opt/conda/lib/libswiftest.a
COPY --from=build_driver /swiftest/include/ /opt/conda/include/swiftest/
COPY ./python/. /opt/conda/pkgs/swiftest/
COPY --from=build_driver ${INSTALL_DIR}/bin/swiftest_driver ${CONDA_DIR}/bin/swiftest_driver
COPY --from=build_driver ${INSTALL_DIR}/lib/libswiftest.a ${CONDA_DIR}/conda/lib/libswiftest.a
COPY --from=build_driver /swiftest/include/ ${CONDA_DIR}/include/swiftest/
COPY ./python/. ${CONDA_DIR}/pkgs/swiftest/
COPY environment.yml .

RUN conda update --all -y && \
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/FindCoarray_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#=============================================================================

INCLUDE (${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
INCLUDE (FindPackageHandleStandardArgs)

STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT)
IF(BT STREQUAL "DEBUG")
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/FindOpenMP_Fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#=============================================================================

INCLUDE (${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
INCLUDE (FindPackageHandleStandardArgs)

IF (COMPILER_OPTIONS STREQUAL "Intel")
IF (USE_SIMD)
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/SetFortranFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
####################################################################
# Make sure that the default build type is RELEASE if not specified.
####################################################################
INCLUDE(${CMAKE_MODULE_PATH}/SetCompileFlag.cmake)
INCLUDE(SetCompileFlag)

# Make sure the build type is uppercase
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" BT)
Expand Down
1 change: 0 additions & 1 deletion python/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions python/CMakeLists.txt

This file was deleted.

42 changes: 0 additions & 42 deletions python/setup.py

This file was deleted.

9 changes: 4 additions & 5 deletions python/setup.py.in → setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
If not, see: https://www.gnu.org/licenses.
"""

#from skbuild import setup
from setuptools import setup
from skbuild import setup
from setuptools import find_packages, Extension
from Cython.Build import cythonize
import os

# Build the pybindings extension that allows us to run the Fortran driver as a Python module.
root_dir = 'pybindings'
include_dirs = "${SWIFTEST_INCLUDE_DIR}"
include_dirs = ""
include_dirs = include_dirs.split()
include_dirs.append(root_dir)
link_flags = "${SWIFTEST_LINK_FLAGS}"
link_flags = ""
link_flags = link_flags.split()

pybindings_extension = [Extension('swiftest.bindings',
Expand All @@ -32,7 +31,7 @@
)]

setup(name='swiftest',
version='${CMAKE_PROJECT_VERSION}',
version='2023.8.0',
author='David A. Minton',
author_email='daminton@purdue.edu',
url='https://github.itap.purdue.edu/MintonGroup/swiftest',
Expand Down
31 changes: 31 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@ set(GLOBAL_MODULE_IN ${SRC}/globals/globals_module.f90.in)
set(GLOBAL_MODULE_OUT ${SRC}/globals/globals_module.f90)
CONFIGURE_FILE(${GLOBAL_MODULE_IN} ${GLOBAL_MODULE_OUT})

IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
MESSAGE(FATAL_ERROR "Fortran compiler does not support F90")
ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)

IF (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
SET(COMPILER_OPTIONS "Intel" CACHE STRING "Compiler identified as Intel")
ELSEIF (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
SET(COMPILER_OPTIONS "GNU" CACHE STRING "Compiler identified as gfortran")
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")
INCLUDE(SetMKL)
ENDIF ()

# This INCLUDE statement executes code that sets the compile flags for DEBUG,
# RELEASE, PROFILING, and TESTING.
INCLUDE(SetFortranFlags)

INCLUDE_DIRECTORIES($ENV{NETCDF_FORTRAN_HOME}/include;$ENV{NETCDF_HOME}/include)


# Add the source files
SET(STRICT_MATH_FILES
${SRC}/collision/collision_generate.f90
Expand Down
2 changes: 1 addition & 1 deletion src/globals/globals_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module globals
integer(I4B), parameter :: UPPERCASE_OFFSET = iachar('A') - iachar('a') !! ASCII character set parameter for lower to upper
!! conversion - offset between upper and lower

character(*), parameter :: VERSION = "2023.08.00" !! Swiftest version
character(*), parameter :: VERSION = "2023.8.0" !! Swiftest version

!> Symbolic name for integrator types
character(*), parameter :: UNKNOWN_INTEGRATOR = "UKNOWN INTEGRATOR"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 447eaaf

Please sign in to comment.