Skip to content

Commit

Permalink
Add coarray interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi committed Sep 27, 2024
1 parent fc9337f commit 8294924
Show file tree
Hide file tree
Showing 39 changed files with 1,446 additions and 11 deletions.
29 changes: 22 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jobs:
compiler: intel
mpi: impi
interface: mpi
- os: ubuntu-latest
compiler: intel
mpi: nompi
interface: coarray
- os: macos-latest
compiler: gnu
mpi: nompi
Expand Down Expand Up @@ -123,20 +127,31 @@ jobs:
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 "MESON_OPTIONS_NOFALLBACK=" >> ${GITHUB_ENV}
echo "MESON_OPTIONS_FALLBACK=-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 "MESON_OPTIONS_NOFALLBACK=" >> ${GITHUB_ENV}
echo "MESON_OPTIONS_FALLBACK=-Dfortuno:build_mpi_interface=true" >> ${GITHUB_ENV}
echo "INTERFACE=mpi" >> ${GITHUB_ENV}
echo "RUN_PREFIX=mpirun -n 2" >> ${GITHUB_ENV}
- name: Setup coarray interface options
if: ${{ contains(matrix.interface, 'coarray') }}
run: |
echo "CMAKE_OPTIONS=-DFORTUNO_BUILD_COARRAY_INTERFACE=ON -DFORTUNO_COARRAY_COMPILE_FLAGS='-coarray' -DFORTUNO_COARRAY_LINK_FLAGS='-coarray'" >> ${GITHUB_ENV}
echo "MESON_OPTIONS_NOFALLBACK=-Dcoarray_compile_flags=-coarray -Dcoarray_link_flags=-coarray" >> ${GITHUB_ENV}
echo "MESON_OPTIONS_FALLBACK=-Dcoarray_compile_flags=-coarray -Dcoarray_link_flags=-coarray -Dfortuno:build_coarray_interface=true -Dfortuno:coarray_compile_flags=-coarray -Dfortuno:coarray_link_flags=-coarray" >> ${GITHUB_ENV}
echo "FPM_FFLAGS=${FPM_FFLAGS} -coarray" >> ${GITHUB_ENV}
echo "FPM_LDFLAGS=${FPM_LDFLAGS} -coarray" >> ${GITHUB_ENV}
echo "INTERFACE=coarray" >> ${GITHUB_ENV}
echo "RUN_PREFIX=" >> ${GITHUB_ENV}
- name: Setup build tools
run: |
pip install cmake fpm meson ninja fypp
Expand All @@ -153,7 +168,7 @@ jobs:
CMAKE_PREFIX_PATH=${INSTALL_DIR} cmake -B ${BUILD_DIR} -G Ninja test/export/${INTERFACE}
cmake --build ${BUILD_DIR}
${RUN_PREFIX} ${BUILD_DIR}/app/testapp
${RUN_PREFIX} ${BUILD_DIR}/app/testapp_fypp
# ${RUN_PREFIX} ${BUILD_DIR}/app/testapp_fypp
rm -rf ${BUILD_DIR}
- name: Test fpm export
Expand All @@ -168,7 +183,7 @@ jobs:
run: |
export PKG_CONFIG_PATH="${PWD}/${INSTALL_DIR}/lib/pkgconfig:${PKG_CONFIG_PATH}"
cd test/export/${INTERFACE}
meson setup --wrap-mode nofallback ${BUILD_DIR}
meson setup ${MESON_OPTIONS_NOFALLBACK} --wrap-mode nofallback ${BUILD_DIR}
ninja -C ${BUILD_DIR}
${RUN_PREFIX} ${BUILD_DIR}/testapp
rm -rf ./${BUILD_DIR}
Expand All @@ -183,7 +198,7 @@ jobs:
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 ${MESON_FALLBACK_OPTIONS} --wrap-mode forcefallback ${BUILD_DIR}
meson setup ${MESON_OPTIONS_FALLBACK} --wrap-mode forcefallback ${BUILD_DIR}
ninja -C ${BUILD_DIR}
${RUN_PREFIX} ${BUILD_DIR}/testapp
rm -rf subprojects ${BUILD_DIR}
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ option(
OFF
)

option(
FORTUNO_BUILD_COARRAY_INTERFACE
"Fortuno: whether the coarray 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 @@ -68,6 +74,17 @@ set(
"Fortuno: Flags neeeded to enforce thread-safe build during linking"
)

set(
FORTUNO_COARRAY_COMPILE_FLAGS "" CACHE STRING
"Fortuno: Flags needed for coarray features when compling"
)

set(
FORTUNO_COARRAY_LINK_FLAGS "" CACHE STRING
"Fortuno: Flags neeeded for coarray features when linking"
)


#[=================================================================================================[
# Project configuration #
]=================================================================================================]
Expand Down Expand Up @@ -134,6 +151,15 @@ if (FORTUNO_INSTALL)
)
endif ()

if (FORTUNO_BUILD_COARRAY_INTERFACE)
configure_file(cmake/fortuno-coarray.pc.in fortuno-coarray.pc @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/fortuno-coarray.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
42 changes: 42 additions & 0 deletions cmake/FortunoHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,45 @@ function (fortuno_preprocess preproc preprocopts oldext newext oldfiles newfiles
set(${newfiles} "${_newfiles}" PARENT_SCOPE)

endfunction ()


# Creates the target CoarrayBuildInterface with coarray build options
function (fortuno_create_coarray_build_target)

if (NOT TARGET CoarrayBuildInterface)
add_library(CoarrayBuildInterface INTERFACE)
target_compile_options(
CoarrayBuildInterface INTERFACE
${FORTUNO_COARRAY_COMPILE_FLAGS}
)
target_link_options(
CoarrayBuildInterface INTERFACE
${FORTUNO_COARRAY_LINK_FLAGS}
)
endif ()

endfunction ()


# Applies coarray build flags to a target
function (fortuno_add_coarray_build_flags target)

fortuno_create_coarray_build_target()

# TODO: Delete first branch once cmake minimum version is 3.26 or above
# Older CMake versions have problems during installation if the CoarrayBuildInterface target is
# linked directly with any target, therefore applying a workaround.
if (CMAKE_VERSION VERSION_LESS 3.26)
get_target_property(_compile_flags CoarrayBuildInterface INTERFACE_COMPILE_OPTIONS)
if (_compile_flags)
target_compile_options(${target} PRIVATE ${_compile_flags})
endif ()
get_target_property(_link_flags CoarrayBuildInterface INTERFACE_LINK_OPTIONS)
if (_link_flags)
target_link_options(${target} PRIVATE ${_link_flags})
endif ()
else ()
target_link_libraries(${target} PRIVATE $<BUILD_LOCAL_INTERFACE:CoarrayBuildInterface>)
endif ()

endfunction ()
7 changes: 7 additions & 0 deletions cmake/fortuno-coarray.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_COA_INSTALL_MODULEDIR@
Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lfortuno-coarray
11 changes: 11 additions & 0 deletions devel/fpm-export/coarray/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = "fortuno-coarray"
version = "0.1.0"
license = "BSD-2-Clause-Patent"
author = "Fortuno authors"
maintainer = "aradi@uni-bremen.de"
copyright = "Copyright 2024, Fortuno authors"

[fortran]
implicit-typing = false
implicit-external = false
source-form = "free"
5 changes: 5 additions & 0 deletions devel/fpm-export/coarray/rsync.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*~
*.mod
*.a
*.o

12 changes: 12 additions & 0 deletions devel/fpm-export/coarray/rsync.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
LICENSE
src/
src/fortuno.f90
src/fortuno/
src/fortuno/**
src/fortuno_coarray.f90
src/fortuno_coarray/
src/fortuno_coarray/**
test/
test/export/
test/export/coarray/
test/export/coarray/**
1 change: 0 additions & 1 deletion devel/fpm-export/mpi/rsync.include
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fpm.serial.toml
LICENSE
src/
src/fortuno.f90
Expand Down
2 changes: 0 additions & 2 deletions devel/fpm-export/serial/rsync.include
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fpm.serial.toml
LICENSE
src/
src/fortuno.f90
Expand All @@ -11,4 +10,3 @@ test/
test/export/
test/export/serial/
test/export/serial/**

7 changes: 7 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ if (FORTUNO_BUILD_MPI_INTERFACE)
add_subdirectory(mpi-fypp)
endif ()
endif ()

if (FORTUNO_BUILD_COARRAY_INTERFACE)
add_subdirectory(coarray)
# if (FYPP)
# add_subdirectory(mpi-fypp)
# endif ()
endif ()
32 changes: 32 additions & 0 deletions example/coarray/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file is part of Fortuno.
# Licensed under the BSD-2-Clause Plus Patent license.
# SPDX-License-Identifier: BSD-2-Clause-Patent

list(APPEND CMAKE_MESSAGE_CONTEXT Coarray)

add_library(fortuno_example_coarray_mylib)
set_target_properties(
fortuno_example_coarray_mylib PROPERTIES
OUTPUT_NAME mylib
)
target_sources(
fortuno_example_coarray_mylib PRIVATE
mylib.f90
)
fortuno_add_coarray_build_flags(fortuno_example_coarray_mylib)

add_executable(fortuno_example_coarray_testapp)
set_target_properties(
fortuno_example_coarray_testapp PROPERTIES
OUTPUT_NAME testapp
)
target_sources(
fortuno_example_coarray_testapp PRIVATE
test_simple.f90
testapp.f90
)
target_link_libraries(
fortuno_example_coarray_testapp PRIVATE
fortuno_example_coarray_mylib Fortuno::fortuno_coarray
)
fortuno_add_coarray_build_flags(fortuno_example_coarray_testapp)
26 changes: 26 additions & 0 deletions example/coarray/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is part of Fortuno.
# Licensed under the BSD-2-Clause Plus Patent license.
# SPDX-License-Identifier: BSD-2-Clause-Patent

example_mylib_lib = library(
'mylib',
sources: ['mylib.f90'],
install: false,
fortran_args: coarray_compile_flags,
link_args: coarray_link_flags,
)
example_mylib_dep = declare_dependency(
link_with: example_mylib_lib,
)

example_testapp_exe = executable(
'testapp',
sources: [
'test_simple.f90',
'testapp.f90',
],
dependencies: [example_mylib_dep, fortuno_coarray_dep],
install: false,
fortran_args: coarray_compile_flags,
link_args: coarray_link_flags,
)
30 changes: 30 additions & 0 deletions example/coarray/mylib.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
! This file is part of Fortuno.
! Licensed under the BSD-2-Clause Plus Patent license.
! SPDX-License-Identifier: BSD-2-Clause-Patent

!> Demo module/library to be tested
module mylib
implicit none

private
public :: broadcast

contains


!> Broadcasts a scalar integer.
subroutine broadcast(buffer, source)

!> Buffer to broadcast
integer, intent(inout) :: buffer

!> Source image
integer, intent(in) :: source

integer :: stat

call co_broadcast(buffer, source)

end subroutine broadcast

end module mylib
55 changes: 55 additions & 0 deletions example/coarray/test_simple.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
! This file is part of Fortuno.
! Licensed under the BSD-2-Clause Plus Patent license.
! SPDX-License-Identifier: BSD-2-Clause-Patent

module test_simple
use mylib, only : broadcast
use fortuno_coarray, only : as_char, test => coa_pure_case_item, context => coa_context,&
& is_equal, test_list
implicit none

contains


!> Returns the tests from this module
function tests()
type(test_list) :: tests

tests = test_list([&
test("broadcast", test_broadcast)&
])

end function tests


!> Broadcast test with collective communication
subroutine test_broadcast(ctx)
class(context), intent(inout) :: ctx

integer, parameter :: sourceimg = 1, sourceval = 100, otherval = -1
integer :: buffer

character(:), allocatable :: msg

! GIVEN source rank contains a different integer value as all other ranks
if (this_image() == sourceimg) then
buffer = sourceval
else
buffer = otherval
end if

! WHEN source rank broadcasts its value
call broadcast(buffer, sourceimg)

! Make every third rank fail for demonstration purposes
if (mod(this_image() - 1, 3) == 2) then
buffer = sourceval + 1
msg = "Failing on image " // as_char(this_image()) // " on purpose"
end if

! THEN each rank must contain source rank's value
call ctx%check(is_equal(buffer, sourceval), msg=msg)

end subroutine test_broadcast

end module test_simple
13 changes: 13 additions & 0 deletions example/coarray/testapp.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
! This file is part of Fortuno.
! Licensed under the BSD-2-Clause Plus Patent license.
! SPDX-License-Identifier: BSD-2-Clause-Patent

!> Test app, collecting and executing the tests
program testapp
use fortuno_coarray, only : execute_coa_cmd_app
use test_simple, only : tests
implicit none

call execute_coa_cmd_app(tests())

end program testapp
Loading

0 comments on commit 8294924

Please sign in to comment.