Unverified Commit 4e57dba2 authored by Atkins, Charles Vernon's avatar Atkins, Charles Vernon Committed by GitHub
Browse files

Merge pull request #2022 from bradking/bindings-fortran-submodules

bindings: Convert Fortran MPI- and non-MPI implementations to submodules
parents d272191b cd520361
......@@ -8,6 +8,9 @@ include(FortranCInterface)
FortranCInterface_HEADER(FC.h MACRO_NAMESPACE "FC_")
FortranCInterface_VERIFY(CXX QUIET)
# Check whether the compiler supports Fortran submodule constructs we need.
adios2_check_fortran_submodules(ADIOS2_HAVE_FORTRAN_SUBMODULES)
add_library(adios2_f
f2c/adios2_f2c_adios.cpp
f2c/adios2_f2c_attribute.cpp
......@@ -22,12 +25,12 @@ add_library(adios2_f
modules/adios2_parameters_mod.f90
modules/adios2_adios_mod.f90
modules/adios2_adios_init_mod.F90
modules/adios2_adios_init_mod_serial.f90
modules/adios2_adios_init_mod_serial.F90
modules/adios2_attribute_mod.f90
modules/adios2_attribute_data_mod.f90
modules/adios2_io_mod.f90
modules/adios2_io_open_mod.F90
modules/adios2_io_open_mod_serial.f90
modules/adios2_io_open_mod_serial.F90
modules/adios2_io_define_variable_mod.f90
modules/adios2_io_define_attribute_mod.f90
modules/adios2_engine_mod.f90
......@@ -49,15 +52,18 @@ target_include_directories(adios2_f
target_link_libraries(adios2_f PRIVATE adios2)
if(ADIOS2_HAVE_FORTRAN_SUBMODULES)
target_compile_definitions(adios2_f PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:ADIOS2_HAVE_FORTRAN_SUBMODULES>")
endif()
if(ADIOS2_HAVE_MPI)
target_compile_definitions(adios2_f PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:ADIOS2_HAVE_MPI_F>")
target_sources(adios2_f PRIVATE
modules/adios2_adios_init_mod_mpi.f90
modules/adios2_io_open_mod_mpi.f90
modules/adios2_adios_init_mod_mpi.F90
modules/adios2_io_open_mod_mpi.F90
f2c/adios2_f2c_adios_mpi.cpp
f2c/adios2_f2c_io_mpi.cpp
)
target_compile_definitions(adios2_f PUBLIC ADIOS2_HAVE_MPI_F)
target_link_libraries(adios2_f PRIVATE MPI::MPI_Fortran MPI::MPI_C)
endif()
......@@ -71,7 +77,7 @@ install(
install(
DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/adios2/fortran
FILES_MATCHING
PATTERN "adios2*.mod"
FILES_MATCHING
PATTERN "adios2*.mod"
PATTERN "CMakeFiles" EXCLUDE
)
......@@ -7,8 +7,71 @@
!
module adios2_adios_init_mod
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
use adios2_parameters_mod
implicit none
interface adios2_init
module subroutine adios2_init_serial(adios, adios2_debug_mode, ierr)
type(adios2_adios), intent(out) :: adios
logical, intent(in) :: adios2_debug_mode
integer, intent(out) :: ierr
end subroutine
module subroutine adios2_init_debug_serial(adios, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(out) :: ierr
end subroutine
module subroutine adios2_init_config_serial(adios, config_file, adios2_debug_mode, ierr)
type(adios2_adios), intent(out) :: adios
character*(*), intent(in) :: config_file
logical, intent(in) :: adios2_debug_mode
integer, intent(out) :: ierr
end subroutine
module subroutine adios2_init_config_debug_serial(adios, config_file, ierr)
type(adios2_adios), intent(out) :: adios
character*(*), intent(in) :: config_file
integer, intent(out) :: ierr
end subroutine
# ifdef ADIOS2_HAVE_MPI_F
module subroutine adios2_init_mpi(adios, comm, adios2_debug_mode, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(in) :: comm
logical, intent(in) :: adios2_debug_mode
integer, intent(out) :: ierr
end subroutine
module subroutine adios2_init_debug_mpi(adios, comm, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(in) :: comm
integer, intent(out) :: ierr
end subroutine
module subroutine adios2_init_config_mpi(adios, config_file, comm, adios2_debug_mode, ierr)
type(adios2_adios), intent(out) :: adios
character*(*), intent(in) :: config_file
integer, intent(in) :: comm
logical, intent(in) :: adios2_debug_mode
integer, intent(out) :: ierr
end subroutine
module subroutine adios2_init_config_debug_mpi(adios, config_file, comm, ierr)
type(adios2_adios), intent(out) :: adios
character*(*), intent(in) :: config_file
integer, intent(in) :: comm
integer, intent(out) :: ierr
end subroutine
# endif
end interface
#else
use adios2_adios_init_mod_serial
#ifdef ADIOS2_HAVE_MPI_F
# ifdef ADIOS2_HAVE_MPI_F
use adios2_adios_init_mod_mpi
# endif
#endif
end module
......@@ -2,24 +2,38 @@
! Distributed under the OSI-approved Apache License, Version 2.0. See
! accompanying file Copyright.txt for details.
!
! adios2_adios_init_mod_mpi.f90 : ADIOS2 Fortran bindings for ADIOS
! adios2_adios_init_mod_mpi.F90 : ADIOS2 Fortran bindings for ADIOS
! class Init functions (MPI variants)
!
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
# define ADIOS2_MODULE_PROCEDURE module &
#else
# define ADIOS2_MODULE_PROCEDURE
#endif
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
submodule ( adios2_adios_init_mod ) mpi
#else
module adios2_adios_init_mod_mpi
#endif
use adios2_parameters_mod
use adios2_functions_mod
implicit none
#ifndef ADIOS2_HAVE_FORTRAN_SUBMODULES
interface adios2_init
module procedure adios2_init_mpi
module procedure adios2_init_debug_mpi
module procedure adios2_init_config_mpi
module procedure adios2_init_config_debug_mpi
end interface
#endif
contains
ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_mpi(adios, comm, adios2_debug_mode, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(in) :: comm
......@@ -30,6 +44,7 @@ contains
end subroutine
ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_debug_mpi(adios, comm, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(in) :: comm
......@@ -39,6 +54,7 @@ contains
end subroutine
ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_config_mpi(adios, config_file, comm, adios2_debug_mode, &
ierr)
type(adios2_adios), intent(out) :: adios
......@@ -57,6 +73,7 @@ contains
end subroutine
ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_config_debug_mpi(adios, config_file, comm, ierr)
type(adios2_adios), intent(out) :: adios
character*(*), intent(in) :: config_file
......@@ -67,4 +84,8 @@ contains
end subroutine
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
end submodule
#else
end module
#endif
......@@ -2,24 +2,38 @@
! Distributed under the OSI-approved Apache License, Version 2.0. See
! accompanying file Copyright.txt for details.
!
! adios2_adios_init_mod_serial.f90 : ADIOS2 Fortran bindings for ADIOS
! adios2_adios_init_mod_serial.F90 : ADIOS2 Fortran bindings for ADIOS
! class Init functions (serial variants)
!
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
# define ADIOS2_MODULE_PROCEDURE module &
#else
# define ADIOS2_MODULE_PROCEDURE
#endif
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
submodule ( adios2_adios_init_mod ) serial
#else
module adios2_adios_init_mod_serial
#endif
use adios2_parameters_mod
use adios2_functions_mod
implicit none
#ifndef ADIOS2_HAVE_FORTRAN_SUBMODULES
interface adios2_init
module procedure adios2_init_serial
module procedure adios2_init_debug_serial
module procedure adios2_init_config_serial
module procedure adios2_init_config_debug_serial
end interface
#endif
contains
ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_serial(adios, adios2_debug_mode, ierr)
type(adios2_adios), intent(out) :: adios
logical, intent(in) :: adios2_debug_mode
......@@ -29,6 +43,7 @@ contains
end subroutine
ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_debug_serial(adios, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(out) :: ierr
......@@ -37,6 +52,7 @@ contains
end subroutine
ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_config_serial(adios, config_file, adios2_debug_mode, ierr)
type(adios2_adios), intent(out) :: adios
character*(*), intent(in) :: config_file
......@@ -51,6 +67,7 @@ contains
end subroutine
ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_config_debug_serial(adios, config_file, ierr)
type(adios2_adios), intent(out) :: adios
character*(*), intent(in) :: config_file
......@@ -60,4 +77,8 @@ contains
end subroutine
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
end submodule
#else
end module
#endif
......@@ -6,8 +6,43 @@
!
module adios2_io_open_mod
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
use adios2_parameters_mod
implicit none
interface adios2_open
module subroutine adios2_open_old_comm(engine, io, name, adios2_mode, ierr)
type(adios2_engine), intent(out) :: engine
type(adios2_io), intent(in) :: io
character*(*), intent(in) :: name
integer, intent(in) :: adios2_mode
integer, intent(out) :: ierr
end subroutine
# ifdef ADIOS2_HAVE_MPI_F
module subroutine adios2_open_new_comm(engine, io, name, adios2_mode, comm, ierr)
type(adios2_engine), intent(out) :: engine
type(adios2_io), intent(in) :: io
character*(*), intent(in) :: name
integer, intent(in) :: adios2_mode
integer, intent(in) :: comm
integer, intent(out) :: ierr
end subroutine
# endif
end interface
#else
use adios2_io_open_mod_serial
#ifdef ADIOS2_HAVE_MPI_F
# ifdef ADIOS2_HAVE_MPI_F
use adios2_io_open_mod_mpi
# endif
#endif
end module
......@@ -2,20 +2,34 @@
! Distributed under the OSI-approved Apache License, Version 2.0. See
! accompanying file Copyright.txt for details.
!
! adios2_io_open_mod_mpi.f90 : ADIOS2 Fortran bindings for IO
! adios2_io_open_mod_mpi.F90 : ADIOS2 Fortran bindings for IO
! class open function (MPI variants)
!
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
# define ADIOS2_MODULE_PROCEDURE module &
#else
# define ADIOS2_MODULE_PROCEDURE
#endif
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
submodule ( adios2_io_open_mod ) mpi
#else
module adios2_io_open_mod_mpi
#endif
use adios2_parameters_mod
implicit none
#ifndef ADIOS2_HAVE_FORTRAN_SUBMODULES
interface adios2_open
module procedure adios2_open_new_comm
end interface
#endif
contains
ADIOS2_MODULE_PROCEDURE
subroutine adios2_open_new_comm(engine, io, name, adios2_mode, comm, ierr)
type(adios2_engine), intent(out) :: engine
type(adios2_io), intent(in) :: io
......@@ -37,4 +51,8 @@ contains
end subroutine
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
end submodule
#else
end module
#endif
......@@ -2,20 +2,34 @@
! Distributed under the OSI-approved Apache License, Version 2.0. See
! accompanying file Copyright.txt for details.
!
! adios2_io_open_mod_serial.f90 : ADIOS2 Fortran bindings for IO
! adios2_io_open_mod_serial.F90 : ADIOS2 Fortran bindings for IO
! class open function (serial variants)
!
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
# define ADIOS2_MODULE_PROCEDURE module &
#else
# define ADIOS2_MODULE_PROCEDURE
#endif
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
submodule ( adios2_io_open_mod ) serial
#else
module adios2_io_open_mod_serial
#endif
use adios2_parameters_mod
implicit none
#ifndef ADIOS2_HAVE_FORTRAN_SUBMODULES
interface adios2_open
module procedure adios2_open_old_comm
end interface
#endif
contains
ADIOS2_MODULE_PROCEDURE
subroutine adios2_open_old_comm(engine, io, name, adios2_mode, ierr)
type(adios2_engine), intent(out) :: engine
type(adios2_io), intent(in) :: io
......@@ -35,4 +49,8 @@ contains
end subroutine
#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
end submodule
#else
end module
#endif
......@@ -199,3 +199,29 @@ function(SetupTestPipeline basename pipeline do_setup)
endforeach()
endfunction()
macro(adios2_check_fortran_submodules var)
include(CheckFortranSourceCompiles)
CHECK_Fortran_SOURCE_COMPILES([[
module foo
interface bar
module subroutine bar_integer(x)
integer, intent(in) :: x
end subroutine
module subroutine bar_real(x)
real, intent(in) :: x
end subroutine
end interface
end module
submodule ( foo ) sub
contains
module subroutine bar_integer(x)
integer, intent(in) :: x
end subroutine
module subroutine bar_real(x)
real, intent(in) :: x
end subroutine
end submodule
program main
end program
]] ${var} SRC_EXT F90)
endmacro()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment