Skip to content

Commit

Permalink
Merge pull request #2531 from GEOS-ESM/bugfix/mathomp4/iso-c-use
Browse files Browse the repository at this point in the history
Explicitly use iso_c_binding types
  • Loading branch information
mathomp4 authored Jan 18, 2024
2 parents eb778a2 + bacfa7e commit 4f2a429
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Explictly `use` some `iso_c_binding` types previously pulled in through ESMF. This is fixed in future ESMF versions (8.7+) and so
we anticipate this here
- Add explicit `Fortran_MODULE_DIRECTORY` to `CMakeLists.txt` in benchmarks to avoid race condition in Ninja builds

### Removed

### Deprecated
Expand Down
5 changes: 3 additions & 2 deletions base/Plain_netCDF_Time.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Plain_netCDF_Time
! use MAPL_CommsMod
use, intrinsic :: iso_fortran_env, only: REAL32
use, intrinsic :: iso_fortran_env, only: REAL64
use, intrinsic :: iso_c_binding, only: C_INT
implicit none
public

Expand Down Expand Up @@ -451,7 +452,7 @@ subroutine bisect_find_LB_R8_I8(xa, x, n, n_LB, n_UB, rc)
if(present(n_LB)) LB=max(LB, n_LB)
if(present(n_UB)) UB=min(UB, n_UB)
klo=LB; khi=UB; dk=1

if ( xa(LB ) > xa(UB) ) then
klo= UB
khi= LB
Expand Down Expand Up @@ -673,7 +674,7 @@ function matches( string, substring )
RETURN
end function matches


subroutine split_string_by_space (string_in, length_mx, &
mxseg, nseg, str_piece, jstatus)
integer, intent (in) :: length_mx
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/io/checkpoint_simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
set(exe checkpoint_simulator.x)
set(MODULE_DIRECTORY ${esma_include}/benchmarks/io/checkpoint_simulator)

ecbuild_add_executable (
TARGET ${exe}
SOURCES checkpoint_simulator.F90
SOURCES checkpoint_simulator.F90
DEFINITIONS USE_MPI)

target_link_libraries (${exe} PRIVATE MAPL.shared MPI::MPI_Fortran FARGPARSE::fargparse esmf )
target_include_directories (${exe} PUBLIC $<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>)
set_target_properties (${exe} PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIRECTORY})

# CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/io/combo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(exe combo.x)
set(MODULE_DIRECTORY ${esma_include}/benchmarks/io/combo)

ecbuild_add_executable (
TARGET ${exe}
Expand All @@ -7,6 +8,7 @@ ecbuild_add_executable (

target_link_libraries (${exe} PRIVATE MAPL.shared MPI::MPI_Fortran FARGPARSE::fargparse)
target_include_directories (${exe} PUBLIC $<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>)
set_target_properties (${exe} PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIRECTORY})

# CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/io/gatherv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
set(MODULE_DIRECTORY ${esma_include}/benchmarks/io/gatherv)

ecbuild_add_executable (
TARGET gatherv.x
SOURCES GathervKernel.F90 GathervSpec.F90 driver.F90
DEFINITIONS USE_MPI)

target_link_libraries (gatherv.x PRIVATE MAPL.shared MPI::MPI_Fortran FARGPARSE::fargparse)
target_include_directories (gatherv.x PUBLIC $<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>)
set_target_properties (gatherv.x PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIRECTORY})

# CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/io/raw_bw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
set(MODULE_DIRECTORY ${esma_include}/benchmarks/io/raw_bw)

ecbuild_add_executable (
TARGET raw_bw.x
SOURCES BW_Benchmark.F90 BW_BenchmarkSpec.F90 driver.F90
DEFINITIONS USE_MPI)

target_link_libraries (raw_bw.x PRIVATE MAPL.shared MPI::MPI_Fortran FARGPARSE::fargparse)
target_include_directories (raw_bw.x PUBLIC $<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>)
set_target_properties (raw_bw.x PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIRECTORY})

# CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
Expand Down
12 changes: 6 additions & 6 deletions field_utils/FieldPointerUtilities.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module MAPL_FieldPointerUtilities
use ESMF
use MAPL_ExceptionHandling
use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer
use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer, c_loc
implicit none
private

Expand Down Expand Up @@ -483,14 +483,14 @@ logical function are_broadcast_conformable(x, y, rc) result(conformable)
integer, dimension(:), allocatable :: count_x, count_y
integer :: status
logical :: normal_conformable

conformable = .false.
! this should really used the geom and ungridded dims
! for now we will do this until we have a geom agnostic stuff worked out...
! the ideal algorithm would be if geom == geom and input does not have ungridded
! and thing we are copying to does, then we are "conformable"
normal_conformable = FIeldsAreConformable(x,y,_RC)

if (normal_conformable) then
conformable = .true.
_RETURN(_SUCCESS)
Expand Down Expand Up @@ -842,7 +842,7 @@ subroutine MAPL_FieldGetLocalElementCount(field,local_count,rc)
else
_FAIL("Unsupported rank")
end if
else
else
_FAIL("Unsupported type")
end if
_RETURN(_SUCCESS)
Expand Down Expand Up @@ -871,7 +871,7 @@ subroutine GetFieldsUndef_r4(fields,undef_values,rc)

integer :: status, i
logical :: isPresent

allocate(undef_values(size(fields)))
do i =1,size(fields)
call ESMF_AttributeGet(fields(i),name="missing_value",isPresent=isPresent,_RC)
Expand All @@ -888,7 +888,7 @@ subroutine GetFieldsUndef_r8(fields,undef_values,rc)

integer :: status, i
logical :: isPresent

allocate(undef_values(size(fields)))
do i =1,size(fields)
call ESMF_AttributeGet(fields(i),name="missing_value",isPresent=isPresent,_RC)
Expand Down

0 comments on commit 4f2a429

Please sign in to comment.