From 6ff0caec66ecd3817a8cded0b82a53f165584942 Mon Sep 17 00:00:00 2001 From: Marshall Ward Date: Fri, 22 Oct 2021 14:58:18 -0400 Subject: [PATCH] Use FMS2 `file_exists`, remove domain args This patch uses the FMS2 `file_exists` function when using the FMS2 infra. Previously, the FMS1 version of this function was being used. This patch also removes the `mpp_domain` and `no_domain` arguments from the direct `file_exist` calls, which were not used by any known MOM6 configurations. (Nor would we expect them to be, since explicit references to FMS should not exist outside of the infra layer.) Since FMS2 does not use these arguments, their removal also creates a more meaningful interface between the two frameworks. Motivation: An issue with the FMS1 `file_exists` under the FMS2 infra was discovered in the UFS model on Hera. It was only reproducible in submitted jobs, and not for interactive jobs, and only with the GCC 9.2 compiler. (Other GCC versions were not tested.) One potential explanation is that it is related to the `save` attribute of the domain pointer, `d_ptr`. In the case above, `d_ptr` pointed to the MOM input domain for the failed cases. For the other working cases, `d_ptr` pointed to a `NULL()` value and behavior was normal. It is possible that `d_ptr` is inconsisently updated when FMS1 and FMS2 IO operations are used together, which should probably be considered undefined behavior. --- config_src/infra/FMS1/MOM_io_infra.F90 | 11 ++++------- config_src/infra/FMS2/MOM_io_infra.F90 | 12 +++++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/config_src/infra/FMS1/MOM_io_infra.F90 b/config_src/infra/FMS1/MOM_io_infra.F90 index 1501f3171b..f956f9fa51 100644 --- a/config_src/infra/FMS1/MOM_io_infra.F90 +++ b/config_src/infra/FMS1/MOM_io_infra.F90 @@ -137,15 +137,12 @@ logical function MOM_file_exists(filename, MOM_Domain) end function MOM_file_exists !> Returns true if the named file or its domain-decomposed variant exists. -logical function FMS_file_exists(filename, domain, no_domain) +logical function FMS_file_exists(filename) character(len=*), intent(in) :: filename !< The name of the file being inquired about - type(domain2d), optional, intent(in) :: domain !< The mpp domain2d that describes the decomposition - logical, optional, intent(in) :: no_domain !< This file does not use domain decomposition -! This function uses the fms_io function file_exist to determine whether -! a named file (or its decomposed variant) exists. - - FMS_file_exists = file_exist(filename, domain, no_domain) + ! This function uses the fms_io function file_exist to determine whether + ! a named file (or its decomposed variant) exists. + FMS_file_exists = file_exist(filename) end function FMS_file_exists !> indicates whether an I/O handle is attached to an open file diff --git a/config_src/infra/FMS2/MOM_io_infra.F90 b/config_src/infra/FMS2/MOM_io_infra.F90 index 0b8c19d836..62a43ab99b 100644 --- a/config_src/infra/FMS2/MOM_io_infra.F90 +++ b/config_src/infra/FMS2/MOM_io_infra.F90 @@ -17,6 +17,7 @@ module MOM_io_infra use fms2_io_mod, only : get_variable_dimension_names, is_dimension_registered, get_dimension_size use fms2_io_mod, only : is_dimension_unlimited, register_axis, unlimited use fms2_io_mod, only : get_global_io_domain_indices +use fms_io_utils_mod, only : fms2_file_exist => file_exists use fms_mod, only : write_version_number, open_namelist_file, check_nml_error use fms_io_mod, only : file_exist, field_exist, field_size, read_data @@ -170,15 +171,12 @@ logical function MOM_file_exists(filename, MOM_Domain) end function MOM_file_exists !> Returns true if the named file or its domain-decomposed variant exists. -logical function FMS_file_exists(filename, domain, no_domain) +logical function FMS_file_exists(filename) character(len=*), intent(in) :: filename !< The name of the file being inquired about - type(domain2d), optional, intent(in) :: domain !< The mpp domain2d that describes the decomposition - logical, optional, intent(in) :: no_domain !< This file does not use domain decomposition -! This function uses the fms_io function file_exist to determine whether -! a named file (or its decomposed variant) exists. - - FMS_file_exists = file_exist(filename, domain, no_domain) + ! This function uses the fms_io function file_exist to determine whether + ! a named file (or its decomposed variant) exists. + FMS_file_exists = fms2_file_exist(filename) end function FMS_file_exists !> indicates whether an I/O handle is attached to an open file