Skip to content

Commit

Permalink
Merge pull request #2490 from chuckatkins/fix-cray-fortran
Browse files Browse the repository at this point in the history
Fortran: Fix submodule and preprocessor issues with Cray Fortran
  • Loading branch information
Chuck Atkins authored Oct 29, 2020
2 parents a2049b4 + 2dce6b4 commit bd6a788
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 76 deletions.
16 changes: 12 additions & 4 deletions bindings/Fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ FortranCInterface_VERIFY(CXX QUIET)
# Check whether the compiler supports Fortran submodule constructs we need.
adios2_check_fortran_submodules(ADIOS2_HAVE_FORTRAN_SUBMODULES)

# Leaving this workaround in place but commented out just in case we need to
# re-enable it in the future
#
# Cray submodules have naming issues so just don't use them for now
#if(CMAKE_Fortran_COMPILER_ID MATCHES "Cray")
# set(ADIOS2_HAVE_FORTRAN_SUBMODULES 0 CACHE INTERNAL "" FORCE)
#endif()

if(ADIOS2_USE_Fortran_flag_argument_mismatch)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif()
Expand All @@ -29,12 +37,12 @@ add_library(adios2_fortran
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_serial_smod.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_serial_smod.F90
modules/adios2_io_define_variable_mod.f90
modules/adios2_io_define_attribute_mod.f90
modules/adios2_engine_mod.f90
Expand Down Expand Up @@ -79,8 +87,8 @@ if(ADIOS2_HAVE_MPI)
target_compile_definitions(adios2_fortran PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:ADIOS2_HAVE_MPI_F>")

set(adios2_fortran_mpi_srcs
modules/adios2_adios_init_mod_mpi.F90
modules/adios2_io_open_mod_mpi.F90
modules/adios2_adios_init_mpi_smod.F90
modules/adios2_io_open_mpi_smod.F90
f2c/adios2_f2c_adios_mpi.cpp
f2c/adios2_f2c_io_mpi.cpp
)
Expand Down
4 changes: 2 additions & 2 deletions bindings/Fortran/modules/adios2_adios_init_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ module subroutine adios2_init_config_debug_mpi(adios, config_file, comm, ierr)

#else

use adios2_adios_init_mod_serial
use adios2_adios_init_serial_mod
# ifdef ADIOS2_HAVE_MPI_F
use adios2_adios_init_mod_mpi
use adios2_adios_init_mpi_mod
# endif

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
!

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
# define ADIOS2_MODULE_PROCEDURE module &
# define ADIOS2_MODULE_PROCEDURE module
#else
# define ADIOS2_MODULE_PROCEDURE
#endif

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
submodule ( adios2_adios_init_mod ) mpi
submodule ( adios2_adios_init_mod ) adios2_adios_init_mpi_smod
#else
module adios2_adios_init_mod_mpi
module adios2_adios_init_mpi_mod
#endif

use adios2_parameters_mod
Expand All @@ -33,8 +33,8 @@ module adios2_adios_init_mod_mpi

contains

ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_mpi(adios, comm, adios2_debug_mode, ierr)
ADIOS2_MODULE_PROCEDURE 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
Expand All @@ -44,8 +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)
ADIOS2_MODULE_PROCEDURE subroutine adios2_init_debug_mpi(adios, comm, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(in) :: comm
integer, intent(out) :: ierr
Expand All @@ -54,9 +53,8 @@ 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)
ADIOS2_MODULE_PROCEDURE 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
Expand All @@ -73,8 +71,8 @@ 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)
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
integer, intent(in) :: comm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
!

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
# define ADIOS2_MODULE_PROCEDURE module &
# define ADIOS2_MODULE_PROCEDURE module
#else
# define ADIOS2_MODULE_PROCEDURE
#endif

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
submodule ( adios2_adios_init_mod ) serial
submodule ( adios2_adios_init_mod ) adios2_adios_init_serial_smod
#else
module adios2_adios_init_mod_serial
module adios2_adios_init_serial_mod
#endif

use adios2_parameters_mod
Expand All @@ -33,8 +33,8 @@ module adios2_adios_init_mod_serial

contains

ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_serial(adios, adios2_debug_mode, ierr)
ADIOS2_MODULE_PROCEDURE 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
Expand All @@ -43,17 +43,16 @@ subroutine adios2_init_serial(adios, adios2_debug_mode, ierr)

end subroutine

ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_debug_serial(adios, ierr)
ADIOS2_MODULE_PROCEDURE subroutine adios2_init_debug_serial(adios, ierr)
type(adios2_adios), intent(out) :: adios
integer, intent(out) :: ierr

call adios2_init_config_serial(adios, char(0), .true., ierr)

end subroutine

ADIOS2_MODULE_PROCEDURE
subroutine adios2_init_config_serial(adios, config_file, adios2_debug_mode, ierr)
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
logical, intent(in) :: adios2_debug_mode
Expand All @@ -67,8 +66,8 @@ 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)
ADIOS2_MODULE_PROCEDURE 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
Expand Down
4 changes: 2 additions & 2 deletions bindings/Fortran/modules/adios2_io_open_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ module subroutine adios2_open_new_comm(engine, io, name, adios2_mode, comm, ierr

#else

use adios2_io_open_mod_serial
use adios2_io_open_serial_mod
# ifdef ADIOS2_HAVE_MPI_F
use adios2_io_open_mod_mpi
use adios2_io_open_mpi_mod
# endif

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
!

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
# define ADIOS2_MODULE_PROCEDURE module &
# define ADIOS2_MODULE_PROCEDURE module
#else
# define ADIOS2_MODULE_PROCEDURE
#endif

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
submodule ( adios2_io_open_mod ) mpi
submodule ( adios2_io_open_mod ) adios2_io_open_mpi_smod
#else
module adios2_io_open_mod_mpi
module adios2_io_open_mpi_mod
#endif

use adios2_parameters_mod
Expand All @@ -29,8 +29,8 @@ module adios2_io_open_mod_mpi

contains

ADIOS2_MODULE_PROCEDURE
subroutine adios2_open_new_comm(engine, io, name, adios2_mode, comm, ierr)
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
character*(*), intent(in) :: name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
!

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
# define ADIOS2_MODULE_PROCEDURE module &
# define ADIOS2_MODULE_PROCEDURE module
#else
# define ADIOS2_MODULE_PROCEDURE
#endif

#ifdef ADIOS2_HAVE_FORTRAN_SUBMODULES
submodule ( adios2_io_open_mod ) serial
submodule ( adios2_io_open_mod ) adios2_io_open_serial_smod
#else
module adios2_io_open_mod_serial
module adios2_io_open_serial_mod
#endif

use adios2_parameters_mod
Expand All @@ -29,8 +29,8 @@ module adios2_io_open_mod_serial

contains

ADIOS2_MODULE_PROCEDURE
subroutine adios2_open_old_comm(engine, io, name, adios2_mode, ierr)
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
character*(*), intent(in) :: name
Expand Down
22 changes: 22 additions & 0 deletions cmake/DetectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ endif()
if(CMAKE_Fortran_COMPILER_LOADED)
set(ADIOS2_HAVE_Fortran TRUE)
list(APPEND mpi_find_components Fortran)

include(CheckFortranSourceCompiles)
check_fortran_source_compiles("
program testargs
integer :: n
character(len=256) :: v
n = command_argument_count()
call get_command_argument(0, v)
end program testargs"
ADIOS2_HAVE_FORTRAN_F03_ARGS
SRC_EXT F90
)
check_fortran_source_compiles("
program testargs
integer :: n
character(len=256) :: v
n = iargc()
call getarg(0, v)
end program testargs"
ADIOS2_HAVE_FORTRAN_GNU_ARGS
SRC_EXT F90
)
endif()

# MPI
Expand Down
4 changes: 4 additions & 0 deletions examples/hello/insituMPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

if(ADIOS2_HAVE_Fortran)
add_library(helloInsituArgs OBJECT helloInsituArgs.F90)
target_compile_definitions(helloInsituArgs PRIVATE
$<$<BOOL:${ADIOS2_HAVE_FORTRAN_F03_ARGS}>:ADIOS2_HAVE_FORTRAN_F03_ARGS>
$<$<BOOL:${ADIOS2_HAVE_FORTRAN_GNU_ARGS}>:ADIOS2_HAVE_FORTRAN_GNU_ARGS>
)

add_executable(hello_insituMPIWriter_f
helloInsituMPIWriter.f90
Expand Down
30 changes: 17 additions & 13 deletions examples/hello/insituMPI/helloInsituArgs.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ end subroutine usage
!!***************************
subroutine processArgs(rank, nproc, isWriter)

#if defined(_CRAYFTN) || !defined(__GFORTRAN__) && !defined(__GNUC__)
interface
integer function iargc()
end function iargc
end interface
#if defined(ADIOS2_HAVE_FORTRAN_F03_ARGS)
# define ADIOS2_ARGC() command_argument_count()
# define ADIOS2_ARGV(i, v) call get_command_argument(i, v)
#elif defined(ADIOS2_HAVE_FORTRAN_GNU_ARGS)
# define ADIOS2_ARGC() iargc()
# define ADIOS2_ARGV(i, v) call getarg(i, v)
#else
# define ADIOS2_ARGC() 1
# define ADIOS2_ARGV(i, v)
#endif

integer, intent(in) :: rank
Expand All @@ -57,20 +61,20 @@ end function iargc
endif

!! process arguments
numargs = iargc()
numargs = ADIOS2_ARGC()
!print *,"Number of arguments:",numargs
if ( numargs < expargs ) then
call usage(isWriter)
call exit(1)
endif
call getarg(1, xmlfile)
call getarg(2, npx_str)
call getarg(3, npy_str)
ADIOS2_ARGV(1, xmlfile)
ADIOS2_ARGV(2, npx_str)
ADIOS2_ARGV(3, npy_str)
if (isWriter) then
call getarg(4, ndx_str)
call getarg(5, ndy_str)
call getarg(6, steps_str)
call getarg(7, time_str)
ADIOS2_ARGV(4, ndx_str)
ADIOS2_ARGV(5, ndy_str)
ADIOS2_ARGV(6, steps_str)
ADIOS2_ARGV(7, time_str)
endif
read (npx_str,'(i5)') npx
read (npy_str,'(i5)') npy
Expand Down
8 changes: 8 additions & 0 deletions testing/adios2/engine/staging-common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,17 @@ if(ADIOS2_HAVE_Fortran)
TestCommonReadF.F90
$<TARGET_OBJECTS:TestCommonData_f>
)
target_compile_definitions(TestCommonRead_f PRIVATE
$<$<BOOL:${ADIOS2_HAVE_FORTRAN_F03_ARGS}>:ADIOS2_HAVE_FORTRAN_F03_ARGS>
$<$<BOOL:${ADIOS2_HAVE_FORTRAN_GNU_ARGS}>:ADIOS2_HAVE_FORTRAN_GNU_ARGS>
)
set_target_properties(TestCommonWrite_f TestCommonRead_f PROPERTIES
LINKER_LANGUAGE Fortran
)
target_compile_definitions(TestCommonWrite_f PRIVATE
$<$<BOOL:${ADIOS2_HAVE_FORTRAN_F03_ARGS}>:ADIOS2_HAVE_FORTRAN_F03_ARGS>
$<$<BOOL:${ADIOS2_HAVE_FORTRAN_GNU_ARGS}>:ADIOS2_HAVE_FORTRAN_GNU_ARGS>
)
if(ADIOS2_HAVE_MPI)
target_link_libraries(TestCommonWrite_f adios2_fortran_mpi MPI::MPI_Fortran)
target_link_libraries(TestCommonRead_f adios2_fortran_mpi MPI::MPI_Fortran)
Expand Down
Loading

0 comments on commit bd6a788

Please sign in to comment.