Skip to content

Commit

Permalink
Adapt to interface changes in Fortuno
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi committed Sep 28, 2024
1 parent 2387be0 commit 47b90d5
Show file tree
Hide file tree
Showing 30 changed files with 153 additions and 156 deletions.
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ with the uppercase version of your project's slug.)
Name of the subdirectory to put the installed module files into. Default:
``modules``.

``<PROJECTSLUG>_COARRAY_COMPILE_FLAGS``
Compiler flags to use when compiling coarray source code (only available if
the coarray template was chosen). Default: ``-coarray``.
``<PROJECTSLUG>_FFLAGS_COARRAY``
Fortran compiler flags to use when compiling coarray source code (only
available if the coarray template was chosen). Default: ``-coarray``.

``<PROJECTSLUG>_COARRAY_LINK_FLAGS``
``<PROJECTSLUG>_LDFLAGS_COARRAY``
Linker flags to use when linking coarray object files (only available if
the coarray template was chosen). Default: ``-coarray``.

Expand Down Expand Up @@ -263,11 +263,11 @@ during the configuration step.
the include folder. Therefore, the specified directory will be relative to
that folder. Default: ``modules``.

``coarray_compile_flags``
``fflags_coarray``
Compiler flags to use when compiling coarray source code (only available if
the coarray template was chosen). Default: ``-coarray``.

``coarray_link_flags``
``ldflags_coarray``
Linker flags to use when linking coarray object files (only available if
the coarray template was chosen). Default: ``-coarray``.

Expand Down
8 changes: 2 additions & 6 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
(r"./meson$", MESON_BUILD),
(r"./example$", WITH_EXAMPLE),
(r"./subprojects$", CMAKE_BUILD or MESON_BUILD),
(r"./subprojects/Fortuno.cmake$", CMAKE_BUILD and SERIAL_CODE),
(r"./subprojects/FortunoMpi.cmake$", CMAKE_BUILD and MPI_CODE),
(r"./subprojects/FortunoCoarray.cmake$", CMAKE_BUILD and COARRAY_CODE),
(r"./subprojects/fortuno.wrap$", MESON_BUILD and SERIAL_CODE),
(r"./subprojects/fortuno-mpi.wrap$", MESON_BUILD and MPI_CODE),
(r"./subprojects/fortuno-coarray.wrap$", MESON_BUILD and COARRAY_CODE),
(r"./subprojects/Fortuno.cmake$", CMAKE_BUILD),
(r"./subprojects/fortuno.wrap$", MESON_BUILD),
(r".*/CMakeLists.txt$", CMAKE_BUILD),
(r".*/fpm.toml$", FPM_BUILD),
(r".*/meson.build$", MESON_BUILD),
Expand Down
30 changes: 22 additions & 8 deletions templates/testapp-coarray.f90
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
program testapp
module test_{{cookiecutter.project_slug}}
use {{cookiecutter.project_slug}}, only : broadcast
use fortuno_coarray, only : as_char, test => coa_pure_case_item, context => coa_context,&
& execute_coa_cmd_app, is_equal, test_item
& is_equal, test_list
implicit none

call execute_coa_cmd_app(&
testitems=[&
test("broadcast", test_broadcast)&
]&
)

contains

function tests()
type(test_list) :: tests

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

end function tests


subroutine test_broadcast(ctx)
class(context), intent(inout) :: ctx

Expand All @@ -33,4 +37,14 @@ subroutine test_broadcast(ctx)

end subroutine test_broadcast

end module test_{{cookiecutter.project_slug}}


program testapp
use fortuno_coarray, only : execute_coa_cmd_app
use test_{{cookiecutter.project_slug}}, only : tests
implicit none

call execute_coa_cmd_app(tests())

end program testapp
36 changes: 25 additions & 11 deletions templates/testapp-mpi.f90
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
program testapp
module test_{{cookiecutter.project_slug}}
use {{cookiecutter.project_slug}}, only : broadcast
use fortuno_mpi, only : execute_mpi_cmd_app, global_comm, is_equal, test => mpi_case_item,&
& check => mpi_check, test_item, this_rank
use fortuno_mpi, only : global_comm, is_equal, test => mpi_case_item, check => mpi_check,&
& test_list, this_rank
implicit none

call execute_mpi_cmd_app(&
testitems=[&
test("broadcast", test_broadcast)&
]&
)

contains

function tests()
type(test_list) :: tests

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

end function tests


subroutine test_broadcast()
integer, parameter :: sourcerank = 0, sourceval = 1, otherval = -1
integer :: buffer
integer, parameter :: sourcerank = 0, sourceval = 1, otherval = -1
integer :: buffer

! GIVEN source rank contains a different integer value as all other ranks
if (this_rank() == sourcerank) then
Expand All @@ -31,4 +35,14 @@ subroutine test_broadcast()

end subroutine test_broadcast

end module test_{{cookiecutter.project_slug}}


program testapp
use fortuno_mpi, only : execute_mpi_cmd_app
use test_{{cookiecutter.project_slug}}, only : tests
implicit none

call execute_mpi_cmd_app(tests())

end program testapp
34 changes: 23 additions & 11 deletions templates/testapp-serial.f90
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
program testapp
module test_{{cookiecutter.project_slug}}
use {{cookiecutter.project_slug}}, only : factorial
use fortuno_serial, only : execute_serial_cmd_app, is_equal, test => serial_case_item,&
& check => serial_check
use fortuno_serial, only : is_equal, test => serial_case_item, check => serial_check, test_list
implicit none

call execute_serial_cmd_app(&
testitems=[&
test("factorial_0", test_factorial_0),&
test("factorial_1", test_factorial_1),&
test("factorial_2", test_factorial_2)&
]&
)

contains

function tests()
type(test_list) :: tests

tests = test_list([&
test("factorial_0", test_factorial_0),&
test("factorial_1", test_factorial_1),&
test("factorial_2", test_factorial_2)&
])

end function tests

! Test: 0! = 1
subroutine test_factorial_0()
call check(factorial(0) == 1)
Expand All @@ -30,4 +32,14 @@ subroutine test_factorial_2()
call check(is_equal(factorial(2), 2))
end subroutine test_factorial_2

end module test_{{cookiecutter.project_slug}}


program testapp
use fortuno_serial, only : execute_serial_cmd_app
use test_{{cookiecutter.project_slug}}, only : tests
implicit none

call execute_serial_cmd_app(tests())

end program testapp
2 changes: 2 additions & 0 deletions test/runners/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
TEST_DIR="$(readlink -f $SCRIPT_DIR/..)"
COOKIECUTTER_ROOT_DIR="$(readlink -f $SCRIPT_DIR/../..)"
DISTRO_ID=$(python3 -c "import platform; print(platform.freedesktop_os_release()['ID'])")
LIB_DIR=$([[ "${DISTRO_ID}" =~ ^(ubuntu|debian)$ ]] && echo "lib" || echo "lib64")

build_dir=$1
if [[ -z ${build_dir} ]]; then
Expand Down
14 changes: 7 additions & 7 deletions test/runners/test.cmake-coarray.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ cmake\
-GNinja\
-B _build\
-DCMAKE_INSTALL_PREFIX=$PWD/_install\
-DTESTPROJECT_COARRAY_COMPILE_FLAGS=${FFLAGS_COARRAY}\
-DTESTPROJECT_COARRAY_LINK_FLAGS=${LDFLAGS_COARRAY}\
-DTESTPROJECT_FFLAGS_COARRAY=${FFLAGS_COARRAY}\
-DTESTPROJECT_LDFLAGS_COARRAY=${LDFLAGS_COARRAY}\
testproject/
cmake --build _build
ctest --test-dir _build
Expand All @@ -27,19 +27,19 @@ CMAKE_PREFIX_PATH=$PWD/_install\
-B _build_export_cmake\
-GNinja\
-DFIND_BY_CMAKE=ON\
-DCOARRAY_COMPILE_FLAGS=${FFLAGS_COARRAY}\
-DCOARRAY_LINK_FLAGS=${LDFLAGS_COARRAY}\
-DFFLAGS_COARRAY=${FFLAGS_COARRAY}\
-DLDFLAGS_COARRAY=${LDFLAGS_COARRAY}\
${TEST_DIR}/testers/export_test.coarray
cmake --build _build_export_cmake
./_build_export_cmake/app/export_test

PKG_CONFIG_PATH=$PWD/_install/lib/pkgconfig\
PKG_CONFIG_PATH=$PWD/_install/${LIB_DIR}/pkgconfig\
cmake\
-B _build_export_pkgconf\
-GNinja\
-DFIND_BY_CMAKE=OFF\
-DCOARRAY_COMPILE_FLAGS=${FFLAGS_COARRAY}\
-DCOARRAY_LINK_FLAGS=${LDFLAGS_COARRAY}\
-DFFLAGS_COARRAY=${FFLAGS_COARRAY}\
-DLDFLAGS_COARRAY=${LDFLAGS_COARRAY}\
${TEST_DIR}/testers/export_test.coarray
cmake --build _build_export_pkgconf
./_build_export_pkgconf/app/export_test
2 changes: 1 addition & 1 deletion test/runners/test.cmake-mpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CMAKE_PREFIX_PATH=$PWD/_install\
cmake --build _build_export_cmake
mpirun -n 2 ./_build_export_cmake/app/export_test

PKG_CONFIG_PATH=$PWD/_install/lib/pkgconfig\
PKG_CONFIG_PATH=$PWD/_install/${LIB_DIR}/pkgconfig\
cmake\
-B _build_export_pkgconf\
-GNinja\
Expand Down
8 changes: 7 additions & 1 deletion test/runners/test.cmake-serial.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
set -e -v -x

SCRIPT_DIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
DISTRO_ID=$(python3 -c "import platform; print(platform.freedesktop_os_release()['ID'])")
if [[ "${DISTRO_ID}" =~ ^(ubuntu|debian)$ ]]; then
LIB_DIR="lib"
else
LIB_DIR="lib64"
fi

source ${SCRIPT_DIR}/init.sh

Expand Down Expand Up @@ -29,7 +35,7 @@ CMAKE_PREFIX_PATH=$PWD/_install\
cmake --build _build_export_cmake
./_build_export_cmake/app/export_test

PKG_CONFIG_PATH=$PWD/_install/lib/pkgconfig\
PKG_CONFIG_PATH=$PWD/_install/${LIB_DIR}/pkgconfig\
cmake\
-B _build_export_pkgconf\
-GNinja\
Expand Down
8 changes: 4 additions & 4 deletions test/runners/test.meson-coarray.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ cookiecutter \
meson setup\
--prefix $PWD/_install\
--libdir $PWD/_install/lib\
-Dcoarray_compile_flags=${FFLAGS_COARRAY}\
-Dcoarray_link_flags=${LDFLAGS_COARRAY}\
-Dfflags_coarray=${FFLAGS_COARRAY}\
-Dldflags_coarray=${LDFLAGS_COARRAY}\
_build testproject
meson compile -C _build
meson test -C _build --verbose
Expand All @@ -24,8 +24,8 @@ LD_LIBRARY_PATH="${PWD}/_install/lib:${LD_LIBRARY_PATH}"\

PKG_CONFIG_PATH=$PWD/_install/lib/pkgconfig\
meson setup\
-Dcoarray_compile_flags=${FFLAGS_COARRAY}\
-Dcoarray_link_flags=${LDFLAGS_COARRAY}\
-Dfflags_coarray=${FFLAGS_COARRAY}\
-Dldflags_coarray=${LDFLAGS_COARRAY}\
_build_export\
${TEST_DIR}/testers/export_test.coarray
meson compile -C _build_export
Expand Down
16 changes: 8 additions & 8 deletions test/testers/export_test.coarray/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ project(export_test LANGUAGES Fortran)

option(FIND_BY_CMAKE "Use find_package() to find installed project (otherwise pkg-config)" ON)

set(COARRAY_COMPILE_FLAGS "" CACHE STRING "Extra flags to use for compiling coarray source files")
set(FFLAGS_COARRAY "" CACHE STRING "Extra flags to use for compiling coarray source files")

set(COARRAY_LINK_FLAGS "" CACHE STRING "Extra flags to use for linking coarray object files")
set(LDFFLAGS_COARRAY "" CACHE STRING "Extra flags to use for linking coarray object files")

if (COARRAY_COMPILE_FLAGS)
set(_coarray_compile_flags "${COARRAY_COMPILE_FLAGS}")
if (FFLAGS_COARRAY)
set(_fflags_coarray "${FFLAGS_COARRAY}")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
set(_coarray_compile_flags "-coarray")
set(_fflags_coarray "-coarray")
endif ()
if (COARRAY_LINK_FLAGS)
set(_coarray_link_flags "${COARRAY_LINK_FLAGS}")
if (LDFLAGS_COARRAY)
set(_ldflags_coarray "${LDFLAGS_COARRAY}")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
set(_coarray_link_flags "-coarray")
set(_ldflags_coarray "-coarray")
endif ()

if (FIND_BY_CMAKE)
Expand Down
4 changes: 2 additions & 2 deletions test/testers/export_test.coarray/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_executable(export_test export_test.f90)
target_link_libraries(export_test PRIVATE TestProject::testproject)
target_compile_options(export_test PRIVATE ${_coarray_compile_flags})
target_link_options(export_test PRIVATE ${_coarray_link_flags})
target_compile_options(export_test PRIVATE ${_fflags_coarray})
target_link_options(export_test PRIVATE ${_ldflags_coarray})
4 changes: 2 additions & 2 deletions test/testers/export_test.coarray/app/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export_test_exe = executable(
'export_test_app',
sources: export_test_sources,
dependencies: export_test_deps,
fortran_args: coarray_compile_flags,
link_args: coarray_link_flags,
fortran_args: fflags_coarray,
link_args: ldflags_coarray,
)
4 changes: 2 additions & 2 deletions test/testers/export_test.coarray/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ project(
version: '0.0.0'
)

coarray_compile_flags = get_option('coarray_compile_flags')
coarray_link_flags = get_option('coarray_link_flags')
fflags_coarray = get_option('fflags_coarray')
ldflags_coarray = get_option('ldflags_coarray')

testproject_dep = dependency('testproject', required: true)

Expand Down
4 changes: 2 additions & 2 deletions test/testers/export_test.coarray/meson.options
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
option(
'coarray_compile_flags', type: 'array', value: [],
'fflags_coarray', type: 'array', value: [],
description: 'Fortran compiler arguments to use when compiling coarray sources'
)

option(
'coarray_link_flags', type: 'array', value: [],
'ldflags_coarray', type: 'array', value: [],
description: 'Fortran linker arguments to use when linking coarray sources'
)
10 changes: 2 additions & 8 deletions {{ cookiecutter.project_slug }}/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ set(
)
{% if cookiecutter.parallelization == "coarray" -%}
set(
{{cookiecutter.__project_slug_upper}}_COARRAY_COMPILE_FLAGS
{{cookiecutter.__project_slug_upper}}_FFLAGS_COARRAY
"-coarray"
CACHE STRING
"{{cookiecutter.project_name}}: Extra flags to use for compiling coarray source files"
)
set(
{{cookiecutter.__project_slug_upper}}_COARRAY_LINK_FLAGS
{{cookiecutter.__project_slug_upper}}_LDFLAGS_COARRAY
"-coarray"
CACHE STRING
"{{cookiecutter.project_name}}: Extra flags to use for linking coarray object files"
Expand Down Expand Up @@ -112,13 +112,7 @@ if ({{cookiecutter.__project_slug_upper}}_BUILD_EXAMPLES)
endif ()
{%- endif %}
if ({{cookiecutter.__project_slug_upper}}_BUILD_TESTS)
{% if cookiecutter.parallelization == "serial" -%}
include(subprojects/Fortuno.cmake)
{%- elif cookiecutter.parallelization == "mpi" -%}
include(subprojects/FortunoMpi.cmake)
{%- elif cookiecutter.parallelization == "coarray" -%}
include(subprojects/FortunoCoarray.cmake)
{%- endif %}
enable_testing()
add_subdirectory(test)
endif ()
Expand Down
4 changes: 2 additions & 2 deletions {{ cookiecutter.project_slug }}/app/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
sources: {{cookiecutter.project_slug}}_app_sources,
dependencies: {{cookiecutter.project_slug}}_app_deps,
{% if cookiecutter.__coarray_code == "True" -%}
fortran_args: coarray_compile_flags,
link_args: coarray_link_flags,
fortran_args: fflags_coarray,
link_args: ldflags_coarray,
{% endif %}
install: true,
)
Loading

0 comments on commit 47b90d5

Please sign in to comment.