Skip to content

Commit

Permalink
Merge pull request #2022 from bradking/bindings-fortran-submodules
Browse files Browse the repository at this point in the history
bindings: Convert Fortran MPI- and non-MPI implementations to submodules
  • Loading branch information
Chuck Atkins authored Mar 6, 2020
2 parents d272191 + cd52036 commit 4e57dba
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 13 deletions.
20 changes: 13 additions & 7 deletions bindings/Fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()

Expand All @@ -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
)
65 changes: 64 additions & 1 deletion bindings/Fortran/modules/adios2_adios_init_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +44,7 @@ subroutine adios2_init_mpi(adios, comm, adios2_debug_mode, ierr)

end subroutine

ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_debug_mpi(adios, comm, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(in) :: comm
Expand All @@ -39,6 +54,7 @@ subroutine adios2_init_debug_mpi(adios, comm, ierr)

end subroutine

ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_config_mpi(adios, config_file, comm, adios2_debug_mode, &
ierr)
type(adios2_adios), intent(out) :: adios
Expand All @@ -57,6 +73,7 @@ subroutine adios2_init_config_mpi(adios, config_file, comm, adios2_debug_mode, &

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
Expand All @@ -67,4 +84,8 @@ subroutine adios2_init_config_debug_mpi(adios, config_file, comm, ierr)

end subroutine

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
end submodule
#else
end module
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +43,7 @@ subroutine adios2_init_serial(adios, adios2_debug_mode, ierr)

end subroutine

ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_debug_serial(adios, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(out) :: ierr
Expand All @@ -37,6 +52,7 @@ subroutine adios2_init_debug_serial(adios, ierr)

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
Expand All @@ -51,6 +67,7 @@ subroutine adios2_init_config_serial(adios, config_file, adios2_debug_mode, ierr

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
Expand All @@ -60,4 +77,8 @@ subroutine adios2_init_config_debug_serial(adios, config_file, ierr)

end subroutine

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
end submodule
#else
end module
#endif
37 changes: 36 additions & 1 deletion bindings/Fortran/modules/adios2_io_open_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,4 +51,8 @@ subroutine adios2_open_new_comm(engine, io, name, adios2_mode, comm, ierr)

end subroutine

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
end submodule
#else
end module
#endif
Loading

0 comments on commit 4e57dba

Please sign in to comment.