From 1aa5ab1afac7a342fd33ab1e06f8c4e3411159a2 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Tue, 16 Jan 2024 11:01:56 -0500 Subject: [PATCH 1/2] Explicitly use iso_c_binding types This PR adds two explicit `use` of two `iso_c_binding` types that currently are brought in (inadvertently) via `use ESMF`. This has been fixed in ESMF upstream (`develop` at least), so this fix is in anticipation of ESMF 8.7 testing. --- CHANGELOG.md | 3 +++ base/Plain_netCDF_Time.F90 | 5 +++-- field_utils/FieldPointerUtilities.F90 | 12 ++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c50ea8f9ef5f..e91fbd76dc26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ 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 + ### Removed ### Deprecated diff --git a/base/Plain_netCDF_Time.F90 b/base/Plain_netCDF_Time.F90 index be20b3d76bb1..8bc269aa391e 100644 --- a/base/Plain_netCDF_Time.F90 +++ b/base/Plain_netCDF_Time.F90 @@ -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 @@ -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 @@ -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 diff --git a/field_utils/FieldPointerUtilities.F90 b/field_utils/FieldPointerUtilities.F90 index b1a22258fcc8..8773ccd83436 100644 --- a/field_utils/FieldPointerUtilities.F90 +++ b/field_utils/FieldPointerUtilities.F90 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) From 7258afff12cdd1ffedc71a336d30a846c749cdb7 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Wed, 17 Jan 2024 11:02:38 -0500 Subject: [PATCH 2/2] Fixes for ninja build race condition --- CHANGELOG.md | 1 + benchmarks/io/checkpoint_simulator/CMakeLists.txt | 4 +++- benchmarks/io/combo/CMakeLists.txt | 2 ++ benchmarks/io/gatherv/CMakeLists.txt | 3 +++ benchmarks/io/raw_bw/CMakeLists.txt | 3 +++ 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e91fbd76dc26..000355edd51e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 diff --git a/benchmarks/io/checkpoint_simulator/CMakeLists.txt b/benchmarks/io/checkpoint_simulator/CMakeLists.txt index 718d3b706d4e..fedd46d5f3f4 100644 --- a/benchmarks/io/checkpoint_simulator/CMakeLists.txt +++ b/benchmarks/io/checkpoint_simulator/CMakeLists.txt @@ -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 $) +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") diff --git a/benchmarks/io/combo/CMakeLists.txt b/benchmarks/io/combo/CMakeLists.txt index c0d2aa99a884..99a92e1b46a6 100644 --- a/benchmarks/io/combo/CMakeLists.txt +++ b/benchmarks/io/combo/CMakeLists.txt @@ -1,4 +1,5 @@ set(exe combo.x) +set(MODULE_DIRECTORY ${esma_include}/benchmarks/io/combo) ecbuild_add_executable ( TARGET ${exe} @@ -7,6 +8,7 @@ ecbuild_add_executable ( target_link_libraries (${exe} PRIVATE MAPL.shared MPI::MPI_Fortran FARGPARSE::fargparse) target_include_directories (${exe} PUBLIC $) +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") diff --git a/benchmarks/io/gatherv/CMakeLists.txt b/benchmarks/io/gatherv/CMakeLists.txt index 5510ff1c3b33..d6072fb82823 100644 --- a/benchmarks/io/gatherv/CMakeLists.txt +++ b/benchmarks/io/gatherv/CMakeLists.txt @@ -1,3 +1,5 @@ +set(MODULE_DIRECTORY ${esma_include}/benchmarks/io/gatherv) + ecbuild_add_executable ( TARGET gatherv.x SOURCES GathervKernel.F90 GathervSpec.F90 driver.F90 @@ -5,6 +7,7 @@ ecbuild_add_executable ( target_link_libraries (gatherv.x PRIVATE MAPL.shared MPI::MPI_Fortran FARGPARSE::fargparse) target_include_directories (gatherv.x PUBLIC $) +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") diff --git a/benchmarks/io/raw_bw/CMakeLists.txt b/benchmarks/io/raw_bw/CMakeLists.txt index 911a836a7ea5..7477ddf6e43f 100644 --- a/benchmarks/io/raw_bw/CMakeLists.txt +++ b/benchmarks/io/raw_bw/CMakeLists.txt @@ -1,3 +1,5 @@ +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 @@ -5,6 +7,7 @@ ecbuild_add_executable ( target_link_libraries (raw_bw.x PRIVATE MAPL.shared MPI::MPI_Fortran FARGPARSE::fargparse) target_include_directories (raw_bw.x PUBLIC $) +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")