Skip to content

Commit

Permalink
parallal any/all, parallel MOM_file_parser fix
Browse files Browse the repository at this point in the history
A fix to opening an existing file in MOM_file_parser was added.

If an open file is re-opened, then the root PE will detect this and
`return`, but the others will proceed into `populate_param_data` and get
stuck in a broadcast waiting for root.

We fix this by gathering the logical test result over PEs as a global
any() function.

Leading to change #2...

`any_across_PEs` and `all_across_PEs` have been added to MOM_coms as
any/all implementations over PEs (i.e. MPI ranks).  Since legacy FMS
does not support logical collectives, we convert to integers and use
min/max collectives as an equivalent test.
  • Loading branch information
marshallward committed Mar 31, 2022
1 parent c6be96d commit cd7ca24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/framework/MOM_file_parser.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module MOM_file_parser
use MOM_string_functions, only : left_int, left_ints, slasher
use MOM_string_functions, only : left_real, left_reals

! testing
use MOM_coms, only : any_across_PEs

implicit none ; private

! These are hard-coded limits that are used in the following code. They should be set
Expand Down
21 changes: 20 additions & 1 deletion src/framework/unit_tests/MOM_file_parser_tests.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module MOM_file_parser_tests
use MOM_error_handler, only : is_root_pe
use MOM_error_handler, only : disable_fatal_errors
use MOM_error_handler, only : enable_fatal_errors
use MOM_error_handler, only : assert
use MOM_jump, only : set_jump_point
use mpp_mod, only : mpp_sync

Expand Down Expand Up @@ -56,6 +57,7 @@ module MOM_file_parser_tests
! Constructor to support array initialization
interface string
module procedure init_string
module procedure init_string_int
end interface string

contains
Expand Down Expand Up @@ -223,14 +225,19 @@ subroutine test_read_param_int
type(param_file_type) :: param
integer :: sample
type(string) :: lines(1)
character(len=*), parameter :: sample_input = '123'
integer, parameter :: sample_result = 123

lines = string(sample_param_name // ' = 123')
lines = string(sample_param_name // ' = ' // sample_input)
call create_file(param_filename, lines)

call open_param_file(param_filename, param)
call read_param(param, sample_param_name, sample)
call close_param_file(param)

! TODO: Report the incorrect result
call assert(sample == sample_result, "Incorrect value")

call delete_file(param_filename)
end subroutine test_read_param_int

Expand Down Expand Up @@ -1680,6 +1687,18 @@ function init_string(c) result(str)
end function init_string


function init_string_int(n) result(str)
integer, intent(in) :: n
type(string) :: str
character(bit_size(n)/8*3+1) :: chr
! NOTE: Maximum number of characters required to write an integer
! https://stackoverflow.com/a/10536254/317172

write(chr, '(i0)') n
str = string(chr)
end function init_string_int


subroutine create_file(filename, lines, mode)
character(len=*), intent(in) :: filename
type(string), intent(in), optional :: lines(:)
Expand Down

0 comments on commit cd7ca24

Please sign in to comment.