Skip to content

Commit

Permalink
Add MPI interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi committed Sep 27, 2024
1 parent 72a4f88 commit fc9337f
Show file tree
Hide file tree
Showing 71 changed files with 2,228 additions and 116 deletions.
132 changes: 100 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
env:
BUILD_DIR: _build
INSTALL_DIR: _install
FPM_EXPORT_DIR: _fpm_export

jobs:

Expand All @@ -22,12 +23,41 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
compiler: [intel, gnu]
exclude:
# MacOS has no Intel compiler
- os: macos-latest
compiler: intel
include:
- os: ubuntu-latest
compiler: gnu
mpi: nompi
interface: serial
- os: ubuntu-latest
compiler: gnu
mpi: mpich
interface: mpi
# CMake config file of OpenMPI is broken on ubuntu 22.04
# - os: ubuntu-latest
# compiler: gnu
# mpi: openmpi
# interface: mpi
- os: ubuntu-latest
compiler: intel
mpi: nompi
interface: serial
- os: ubuntu-latest
compiler: intel
mpi: impi
interface: mpi
- os: macos-latest
compiler: gnu
mpi: nompi
interface: serial
# MPICH on MacOS lacks mpi_f08 interface
# - os: macos-latest
# compiler: gnu
# mpi: mpich
# interface: mpi
- os: macos-latest
compiler: gnu
mpi: openmpi
interface: mpi

steps:

Expand All @@ -38,9 +68,10 @@ jobs:
if: ${{ contains(matrix.compiler, 'intel') }}
uses: rscohn2/setup-oneapi@v0
with:
# Note: intel 2024.1 and 2024.2 fail to build Fortuno properly due to a compiler bug,
# see https://community.intel.com/t5/Intel-Fortran-Compiler/Compiler-bug-Procedure-pointer-association-status-gets-lost/m-p/1612121#M172850
components: ifx@2024.0.0
components: |
ifx
icx
impi
- name: Setup Intel environment
if: ${{ contains(matrix.compiler, 'intel') }}
Expand All @@ -49,6 +80,9 @@ jobs:
printenv >> ${GITHUB_ENV}
echo "FC=ifx" >> ${GITHUB_ENV}
echo "FPM_FC=ifx" >> ${GITHUB_ENV}
# Overriding default FPM_FFLAGS as default setting contains '-standard-semantics'
# which is incompatible with intel MPI.
echo "FPM_FFLAGS='-warn all -check all,nouninit -error-limit 1 -O0 -g -stand f18 -traceback'" >> ${GITHUB_ENV}
- name: Setup GNU compiler
if: ${{ contains(matrix.compiler, 'gnu') }}
Expand All @@ -63,59 +97,93 @@ jobs:
echo "FC=${{ env.FC }}" >> ${GITHUB_ENV}
echo "FPM_FC=${{ env.FC }}" >> ${GITHUB_ENV}
- name: Setup build tools
- name: Setup MPICH on Ubuntu
if: ${{ contains(matrix.os, 'ubuntu') && contains(matrix.mpi, 'mpich') }}
run: |
pip install cmake fpm meson ninja fypp
sudo apt-get update
sudo apt-get install -y mpich
- name: Build Fortuno with CMake
- name: Setup OpenMPI on Ubuntu
if: ${{ contains(matrix.os, 'ubuntu') && contains(matrix.mpi, 'openmpi') }}
run: |
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -B ${BUILD_DIR} -G Ninja
cmake --build ${BUILD_DIR}
cmake --install ${BUILD_DIR}
rm -rf ${BUILD_DIR}
sudo apt-get update
sudo apt-get install -y openmpi-common openmpi-bin
- name: Build Fortuno with Fpm
- name: Setup MPICH on MacOS
if: ${{ contains(matrix.os, 'macos') && contains(matrix.mpi, 'mpich') }}
run: |
fpm build
rm -rf build
brew install mpich
- name: Build Fortuno with Meson
- name: Setup OpenMPI on MacOS
if: ${{ contains(matrix.os, 'macos') && contains(matrix.mpi, 'openmpi') }}
run: |
meson setup -Dbuild_examples=true ${BUILD_DIR}
ninja -C ${BUILD_DIR}
brew install openmpi
- name: Setup serial interface options
if: ${{ contains(matrix.interface, 'serial') }}
run: |
echo "CMAKE_OPTIONS=-DFORTUNO_BUILD_SERIAL_INTERFACE=ON" >> ${GITHUB_ENV}
echo "MESON_OPTIONS=-Dbuild_serial_interface=true" >> ${GITHUB_ENV}
echo "MESON_FALLBACK_OPTIONS=-Dfortuno:build_serial_interface=true" >> ${GITHUB_ENV}
echo "INTERFACE=serial" >> ${GITHUB_ENV}
echo "RUN_PREFIX=" >> ${GITHUB_ENV}
- name: Setup mpi interface options
if: ${{ contains(matrix.interface, 'mpi') }}
run: |
echo "CMAKE_OPTIONS=-DFORTUNO_BUILD_MPI_INTERFACE=ON" >> ${GITHUB_ENV}
echo "MESON_OPTIONS=-Dbuild_mpi_interface=true" >> ${GITHUB_ENV}
echo "MESON_FALLBACK_OPTIONS=-Dfortuno:build_mpi_interface=true" >> ${GITHUB_ENV}
echo "INTERFACE=mpi" >> ${GITHUB_ENV}
echo "RUN_PREFIX=mpirun -n 2" >> ${GITHUB_ENV}
- name: Setup build tools
run: |
pip install cmake fpm meson ninja fypp
- name: Build Fortuno
run: |
cmake ${CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -B ${BUILD_DIR} -G Ninja
cmake --build ${BUILD_DIR}
cmake --install ${BUILD_DIR}
rm -rf ${BUILD_DIR}
- name: Test CMake export
run: |
CMAKE_PREFIX_PATH=${INSTALL_DIR} cmake -B ${BUILD_DIR} -G Ninja test/export
CMAKE_PREFIX_PATH=${INSTALL_DIR} cmake -B ${BUILD_DIR} -G Ninja test/export/${INTERFACE}
cmake --build ${BUILD_DIR}
${BUILD_DIR}/app/testapp
${BUILD_DIR}/app/testapp_fypp
${RUN_PREFIX} ${BUILD_DIR}/app/testapp
${RUN_PREFIX} ${BUILD_DIR}/app/testapp_fypp
rm -rf ${BUILD_DIR}
- name: Test fpm export
run: |
cd test/export
fpm run testapp
./devel/fpm-export/fpm-export.sh ${INTERFACE} ${FPM_EXPORT_DIR}
fpm run -C ${FPM_EXPORT_DIR}/test/export/${INTERFACE} testapp
rm -rf ${FPM_EXPORT_DIR}
- name: Test Meson pkgconfig export
# Meson only detects OpenMPI reliably (as of version 1.3.2)
if: ${{ !contains(matrix.interface, 'mpi') || contains(matrix.mpi, 'openmpi') }}
run: |
export PKG_CONFIG_PATH="${PWD}/${INSTALL_DIR}/lib/pkgconfig:${PKG_CONFIG_PATH}"
cd test/export
cd test/export/${INTERFACE}
meson setup --wrap-mode nofallback ${BUILD_DIR}
ninja -C ${BUILD_DIR}
${BUILD_DIR}/testapp
${RUN_PREFIX} ${BUILD_DIR}/testapp
rm -rf ./${BUILD_DIR}
- name: Test Meson subproject export
# Meson only detects OpenMPI reliably (as of version 1.3.2)
if: ${{ !contains(matrix.interface, 'mpi') || contains(matrix.mpi, 'openmpi') }}
run: |
FORTUNO_DIR=${PWD}
GIT_REV=$(git rev-parse HEAD)
cd test/export
cd test/export/${INTERFACE}
mkdir subprojects
echo -e "[wrap-git]\ndirectory=fortuno\n" > subprojects/fortuno.wrap
echo -e "url=file://${FORTUNO_DIR}\nrevision=${GIT_REV}\n" >> subprojects/fortuno.wrap
meson setup --wrap-mode forcefallback ${BUILD_DIR}
meson setup ${MESON_FALLBACK_OPTIONS} --wrap-mode forcefallback ${BUILD_DIR}
ninja -C ${BUILD_DIR}
${BUILD_DIR}/testapp
${RUN_PREFIX} ${BUILD_DIR}/testapp
rm -rf subprojects ${BUILD_DIR}
24 changes: 23 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ option(FORTUNO_BUILD_SHARED_LIBS "Fortuno: Build as shared library" ${PROJECT_IS

option(
FORTUNO_BUILD_SERIAL_INTERFACE
"Fortuno: whether serial interface should be built (or only core library)"
"Fortuno: whether serial interface should be built"
ON
)

option(
FORTUNO_BUILD_MPI_INTERFACE
"Fortuno: whether MPI interface should be built"
OFF
)

cmake_dependent_option(
FORTUNO_BUILD_TESTS "Fortuno: Build test suite" ${PROJECT_IS_TOP_LEVEL}
"FORTUNO_BUILD_SERIAL_INTERFACE" OFF
Expand Down Expand Up @@ -79,6 +85,13 @@ find_program(FYPP fypp)
set(BUILD_SHARED_LIBS ${FORTUNO_BUILD_SHARED_LIBS})
fortuno_setup_build_type("RelWithDebInfo")

if (FORTUNO_BUILD_MPI_INTERFACE)
find_package(MPI REQUIRED)
if(NOT MPI_FORTRAN_FOUND)
message(FATAL_ERROR "Failed to detect MPI-framework for Fortran")
endif()
endif ()

#[=================================================================================================[
# Main definition #
]=================================================================================================]
Expand Down Expand Up @@ -112,6 +125,15 @@ if (FORTUNO_INSTALL)
)
endif ()

if (FORTUNO_BUILD_MPI_INTERFACE)
configure_file(cmake/fortuno-mpi.pc.in fortuno-mpi.pc @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/fortuno-mpi.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT Fortuno_development
)
endif ()

# cmake export files
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/FortunoConfigVersion.cmake
Expand Down
7 changes: 7 additions & 0 deletions cmake/fortuno-mpi.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@

Requires: fortuno
Cflags: -I@CMAKE_INSTALL_FULL_LIBDIR@/@FORTUNO_MPI_INSTALL_MODULEDIR@
Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lfortuno-mpi
19 changes: 19 additions & 0 deletions devel/fpm-export/fpm-export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

SCRIPT_DIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"

configdir=$1
destdir=$2

if [[ $# != 2 ]]; then
echo "Need two arguments." >&2
exit 1
fi

rsync \
-av \
--exclude-from=${SCRIPT_DIR}/${configdir}/rsync.ignore \
--include-from=${SCRIPT_DIR}/${configdir}/rsync.include \
--exclude='*' \
${SCRIPT_DIR}/../../ ${destdir}
cp ${SCRIPT_DIR}/${configdir}/fpm.toml ${destdir}
14 changes: 14 additions & 0 deletions devel/fpm-export/mpi/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name = "fortuno-mpi"
version = "0.1.0"
license = "BSD-2-Clause-Patent"
author = "Fortuno authors"
maintainer = "aradi@uni-bremen.de"
copyright = "Copyright 2024, Fortuno authors"

[fortran]
# Enabling the implicit options seems to be necessary for using fpm with meta-dependency mpi.
# Do not worry, the project does not make use of them. ;-)
implicit-typing = true
implicit-external = true
source-form = "free"

5 changes: 5 additions & 0 deletions devel/fpm-export/mpi/rsync.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*~
*.mod
*.a
*.o

14 changes: 14 additions & 0 deletions devel/fpm-export/mpi/rsync.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fpm.serial.toml
LICENSE
src/
src/fortuno.f90
src/fortuno/
src/fortuno/**
src/fortuno_mpi.f90
src/fortuno_mpi/
src/fortuno_mpi/**
test/
test/export/
test/export/mpi/
test/export/mpi/**

12 changes: 0 additions & 12 deletions fpm.toml → devel/fpm-export/serial/fpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,7 @@ author = "Fortuno authors"
maintainer = "aradi@uni-bremen.de"
copyright = "Copyright 2024, Fortuno authors"

[build]
auto-executables = false
auto-tests = true
auto-examples = false
module-naming = false

[install]
library = true

[fortran]
implicit-typing = false
implicit-external = false
source-form = "free"

[example]
name = "testapp"
5 changes: 5 additions & 0 deletions devel/fpm-export/serial/rsync.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*~
*.mod
*.a
*.o

14 changes: 14 additions & 0 deletions devel/fpm-export/serial/rsync.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fpm.serial.toml
LICENSE
src/
src/fortuno.f90
src/fortuno/
src/fortuno/**
src/fortuno_serial.f90
src/fortuno_serial/
src/fortuno_serial/**
test/
test/export/
test/export/serial/
test/export/serial/**

41 changes: 12 additions & 29 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,16 @@

list(APPEND CMAKE_MESSAGE_CONTEXT Example)

add_library(fortuno_example_mylib)
set_target_properties(
fortuno_example_mylib PROPERTIES
OUTPUT_NAME mylib
)
target_sources(
fortuno_example_mylib PRIVATE
mylib.f90
)
if (FORTUNO_BUILD_SERIAL_INTERFACE)
add_subdirectory(serial)
if (FYPP)
add_subdirectory(serial-fypp)
endif ()
endif ()

add_executable(fortuno_example_testapp)
set_target_properties(
fortuno_example_testapp PROPERTIES
OUTPUT_NAME testapp
)
target_sources(
fortuno_example_testapp PRIVATE
testapp.f90
test_fixtured.f90
test_fixtured_module.f90
test_fixtured_suite.f90
test_parametrized.f90
test_simple.f90
)
target_link_libraries(fortuno_example_testapp PRIVATE fortuno_example_mylib Fortuno::fortuno_serial)


if (FYPP)
add_subdirectory(fypp)
endif ()
if (FORTUNO_BUILD_MPI_INTERFACE)
add_subdirectory(mpi)
if (FYPP)
add_subdirectory(mpi-fypp)
endif ()
endif ()
Loading

0 comments on commit fc9337f

Please sign in to comment.