Skip to content

Commit

Permalink
Merge branch 'release/MAPL-v3' into feature/wdboggs/get_history_colle…
Browse files Browse the repository at this point in the history
…ction_output_info
  • Loading branch information
darianboggs committed May 22, 2024
2 parents cb1dd8d + 9f92718 commit 56632cd
Show file tree
Hide file tree
Showing 31 changed files with 632 additions and 249 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- If file path length exceeds ESMF_MAXSTR, add _FAIL in subroutine fglob
- Add GNU UFS-like CI test

### Changed

- pFIO Clients don't send "Done" message when there is no request
- Update `components.yaml`
- ESMA_cmake v3.45.1
- Fix bug in meson detection
- Updated `checkpoint_simulator` to not create and close file if not writing

### Fixed
Expand All @@ -87,9 +92,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Update `FindESMF.cmake` to match that in ESMF 8.6.1

### Changed

- Add timer to the sampler code
- Set required version of ESMF to 8.6.1
- Update `components.yaml`
- ESMA_cmake v3.45.0
Expand Down
1 change: 1 addition & 0 deletions GeomIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(srcs
Geom_PFIO.F90
Grid_PFIO.F90
GeomCatagorizer.F90
pFIOServerBounds.F90
)

esma_add_library(${this}
Expand Down
36 changes: 24 additions & 12 deletions GeomIO/Grid_PFIO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
module mapl3g_GridPFIO
use mapl_ErrorHandling
use mapl3g_GeomPFIO
use mapl3g_SharedIO
use ESMF
use PFIO
use MAPL_BaseMod
use MAPL_FieldPointerUtilities
use mapl3g_pFIOServerBounds
use, intrinsic :: iso_c_binding, only: c_ptr
implicit none
private

Expand All @@ -30,28 +34,36 @@ subroutine stage_data_to_file(this, bundle, filename, time_index, rc)
character(len=ESMF_MAXSTR), allocatable :: field_names(:)
type(ESMF_Field) :: field
type(ArrayReference) :: ref
real, pointer :: ptr2d(:,:)
integer, allocatable :: local_start(:), global_start(:), global_count(:)
type(c_ptr) :: address
integer :: type_kind
type(ESMF_TypeKind_Flag) :: tk
integer, allocatable :: element_count(:), new_element_count(:)

type(ESMF_Grid) :: grid
integer :: global_dim(3), i1, j1, in, jn
type(pFIOServerBounds) :: server_bounds

collection_id = this%get_collection_id()
call ESMF_FieldBundleGet(bundle, fieldCount=num_fields, _RC)
allocate(field_names(num_fields))
call ESMF_FieldBundleGet(bundle, fieldNameList=field_names, _RC)
do i=1,num_fields
call ESMF_FieldBundleGet(bundle, field_names(i), field=field, _RC)
! all this logic needs to be generalized
call ESMF_FieldGet(field, farrayPtr=ptr2d, _RC)
allocate(global_start, source=[1,1,time_index])
call ESMF_FieldGet(field, grid=grid, _RC)
call MAPL_GridGet(grid, globalCellCountPerDim=global_dim, _RC)
allocate(global_count, source=[global_dim(1),global_dim(2),1])
call MAPL_GridGetInterior(grid, i1, in, j1, jn)
allocate(local_start, source=[i1, j1,1])
ref = ArrayReference(ptr2d)
! end generalization

element_count = FieldGetLocalElementCount(field, _RC)
call ESMF_FieldGet(field, grid=grid, typekind=tk, _RC)

call server_bounds%initialize(grid, element_count, time_index=time_index, _RC)
global_start = server_bounds%get_global_start()
global_count = server_bounds%get_global_count()
local_start = server_bounds%get_local_start()

! generate array reference
call FieldGetCptr(field, address, _RC)
type_kind = esmf_to_pfio_type(tk, _RC)
new_element_count = server_bounds%get_file_shape()
ref = ArrayReference(address, type_kind, new_element_count)

call o_clients%collective_stage_data(collection_id,filename, trim(field_names(i)), &
ref, start=local_start, global_start=global_start, global_count=global_count)
enddo
Expand Down
3 changes: 2 additions & 1 deletion GeomIO/SharedIO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module mapl3g_SharedIO
use pfio
use gFTL2_StringVector
use mapl3g_geom_mgr
use MAPL_BaseMod

implicit none

Expand All @@ -13,6 +14,7 @@ module mapl3g_SharedIO
public get_mapl_geom
public create_time_variable
public bundle_to_metadata
public esmf_to_pfio_type

contains

Expand Down Expand Up @@ -86,7 +88,6 @@ subroutine add_variable(metadata, field, rc)
mapl_geom => get_mapl_geom(esmfgeom, _RC)
grid_variables = mapl_geom%get_gridded_dims()
dims = string_vec_to_comma_sep(grid_variables)
dims = 'lon,lat'
call ESMF_FieldGet(field, name=fname, typekind = typekind, _RC)
! add vertical dimension

Expand Down
118 changes: 118 additions & 0 deletions GeomIO/pFIOServerBounds.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include "MAPL_Generic.h"
module mapl3g_pFIOServerBounds
use mapl_ErrorHandlingMod
use esmf
use pfio
use gFTL2_StringVector
use MAPL_BaseMod

implicit none
private

public :: pFIOServerBounds

integer, parameter :: grid_dims = 2

type :: pFIOServerBounds
private
integer, allocatable :: local_start(:)
integer, allocatable :: global_start(:)
integer, allocatable :: global_count(:)
integer, allocatable :: file_shape(:)
contains
procedure :: initialize
procedure :: get_local_start
procedure :: get_global_start
procedure :: get_global_count
procedure :: get_file_shape
end type pFIOServerBounds

contains

function get_local_start(this) result(local_start)
integer, allocatable :: local_start(:)
class(pFIOServerBounds), intent(in) :: this
local_start =this%local_start
end function get_local_start

function get_global_start(this) result(global_start)
integer, allocatable :: global_start(:)
class(pFIOServerBounds), intent(in) :: this
global_start =this%global_start
end function get_global_start

function get_global_count(this) result(global_count)
integer, allocatable :: global_count(:)
class(pFIOServerBounds), intent(in) :: this
global_count =this%global_count
end function get_global_count

function get_file_shape(this) result(file_shape)
integer, allocatable :: file_shape(:)
class(pFIOServerBounds), intent(in) :: this
file_shape =this%file_shape
end function get_file_shape

subroutine initialize(this, grid, field_shape, time_index, rc)
class(pFIOServerBounds), intent(inout) :: this
type(ESMF_Grid), intent(in) :: grid
integer, intent(in) :: field_shape(:)
integer, intent(in), optional :: time_index
integer, intent(out), optional :: rc

integer :: status, tile_count, n_dims, tm, global_dim(3)
integer :: i1, in, j1, jn, tile, extra_file_dim, file_dims, new_grid_dims

call ESMF_GridGet(grid, tileCount=tile_count, _RC)
call MAPL_GridGetInterior(grid, i1,in, j1, jn)
call MAPL_GridGet(grid, globalCellCountPerDim=global_dim, _RC)
n_dims = size(field_shape)

tm = 0
if (present(time_index)) tm = 1

extra_file_dim = 0
if (tile_count == 6) extra_file_dim = 1

new_grid_dims = grid_dims + extra_file_dim
file_dims = n_dims + extra_file_dim

allocate(this%file_shape(file_dims))
allocate(this%global_start(file_dims+tm))
allocate(this%global_count(file_dims+tm))
allocate(this%local_start(file_dims+tm))

this%file_shape(new_grid_dims+1:file_dims) = field_shape(grid_dims+1:n_dims)

this%global_start(1:file_dims) = 1
if(present(time_index)) this%global_start(file_dims+1) = time_index

this%global_count(new_grid_dims+1:file_dims) = field_shape(grid_dims+1:n_dims)
if (present(time_index)) this%global_count(file_dims+1) = 1

this%local_start = 1

select case (tile_count)
case (6) ! Assume cubed-sphere

tile = 1 + (j1-1)/global_dim(1)
this%file_shape(1:new_grid_dims) = [field_shape(1), field_shape(2) ,1]
this%global_count(1:new_grid_dims) =[global_dim(1), global_dim(1), tile_count]
this%local_start(1:new_grid_dims) = [i1, j1-(tile-1)*global_dim(1), tile]

case (1)

this%file_shape(1:new_grid_dims) = [field_shape(1), field_shape(2)]
this%global_count(1:new_grid_dims) = [global_dim(1), global_dim(2)]
this%local_start(1:new_grid_dims) = [i1,j1]

case default
_FAIL("unsupported grid")
end select

_RETURN(_SUCCESS)

end subroutine initialize

end module mapl3g_pFIOServerBounds

7 changes: 6 additions & 1 deletion base/MAPL_ObsUtil.F90
Original file line number Diff line number Diff line change
Expand Up @@ -941,11 +941,16 @@ subroutine fglob(search_name, filename, rc) ! give the last name

character(kind=C_CHAR, len=:), allocatable :: c_search_name
character(kind=C_CHAR, len=512) :: c_filename
integer slen
integer :: slen, lenmax

c_search_name = trim(search_name)//C_NULL_CHAR
rc = f_call_c_glob(c_search_name, c_filename, slen)
filename=""
lenmax = len(filename)
if (lenmax < slen) then
if (MAPL_AM_I_ROOT()) write(6,*) 'pathlen vs filename_max_char_len: ', slen, lenmax
_FAIL ('PATHLEN is greater than filename_max_char_len')
end if
if (slen>0) filename(1:slen)=c_filename(1:slen)

return
Expand Down
2 changes: 1 addition & 1 deletion generic3g/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ set(srcs
ComponentDriver.F90
ComponentDriverVector.F90
GriddedComponentDriver.F90
GriddedComponentDriver_smod.F90
GriddedComponentDriverMap.F90

MultiState.F90
Expand Down Expand Up @@ -66,6 +65,7 @@ add_subdirectory(actions)
add_subdirectory(couplers)
add_subdirectory(ComponentSpecParser)
add_subdirectory(ESMF_HConfigUtilities)
add_subdirectory(GriddedComponentDriver)

target_include_directories (${this} PUBLIC
$<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>)
Expand Down
70 changes: 25 additions & 45 deletions generic3g/GriddedComponentDriver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -103,55 +103,35 @@ module subroutine clock_advance(this, rc)
integer, optional, intent(out) :: rc
end subroutine clock_advance

end interface

contains

function new_GriddedComponentDriver(gridcomp, clock, states) result(child)
type(GriddedComponentDriver) :: child
type(ESMF_GridComp), intent(in) :: gridcomp
type(ESMF_Clock), intent(in) :: clock
type(MultiState), intent(in) :: states

child%gridcomp = gridcomp
child%clock = clock
child%states = states

end function new_GriddedComponentDriver


function get_gridcomp(this) result(gridcomp)
use esmf, only: ESMF_GridComp
type(ESMF_GridComp) :: gridcomp
class(GriddedComponentDriver), intent(in) :: this
gridcomp = this%gridcomp
end function get_gridcomp

function get_name(this, rc) result(name)
character(:), allocatable :: name
class(GriddedComponentDriver), intent(in) :: this
integer, optional, intent(out) :: rc

integer :: status
character(len=ESMF_MAXSTR) :: buffer
module function new_GriddedComponentDriver(gridcomp, clock, states) result(child)
type(GriddedComponentDriver) :: child
type(ESMF_GridComp), intent(in) :: gridcomp
type(ESMF_Clock), intent(in) :: clock
type(MultiState), intent(in) :: states
end function new_GriddedComponentDriver

call ESMF_GridCompGet(this%gridcomp, name=buffer, _RC)
name = trim(buffer)
module function get_gridcomp(this) result(gridcomp)
use esmf, only: ESMF_GridComp
type(ESMF_GridComp) :: gridcomp
class(GriddedComponentDriver), intent(in) :: this
end function get_gridcomp

_RETURN(ESMF_SUCCESS)
end function get_name
module function get_name(this, rc) result(name)
character(:), allocatable :: name
class(GriddedComponentDriver), intent(in) :: this
integer, optional, intent(out) :: rc
end function get_name

subroutine add_export_coupler(this, driver)
class(GriddedComponentDriver), intent(inout) :: this
type(GriddedComponentDriver), intent(in) :: driver
call this%export_couplers%push_back(driver)
end subroutine add_export_coupler
module subroutine add_export_coupler(this, driver)
class(GriddedComponentDriver), intent(inout) :: this
type(GriddedComponentDriver), intent(in) :: driver
end subroutine add_export_coupler

subroutine add_import_coupler(this, driver)
class(GriddedComponentDriver), intent(inout) :: this
type(GriddedComponentDriver), intent(in) :: driver
call this%import_couplers%push_back(driver)
end subroutine add_import_coupler
module subroutine add_import_coupler(this, driver)
class(GriddedComponentDriver), intent(inout) :: this
type(GriddedComponentDriver), intent(in) :: driver
end subroutine add_import_coupler

end interface

end module mapl3g_GriddedComponentDriver
18 changes: 18 additions & 0 deletions generic3g/GriddedComponentDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
target_sources(MAPL.generic3g PRIVATE

initialize.F90
run.F90
finalize.F90
get_states.F90
get_clock.F90
set_clock.F90
run_export_couplers.F90
run_import_couplers.F90
clock_advance.F90
new_GriddedComponentDriver.F90
get_gridcomp.F90
get_name.F90
add_export_coupler.F90
add_import_coupler.F90

)
14 changes: 14 additions & 0 deletions generic3g/GriddedComponentDriver/add_export_coupler.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "MAPL_Generic.h"

submodule (mapl3g_GriddedComponentDriver) add_export_coupler_smod
implicit none

contains

module subroutine add_export_coupler(this, driver)
class(GriddedComponentDriver), intent(inout) :: this
type(GriddedComponentDriver), intent(in) :: driver
call this%export_couplers%push_back(driver)
end subroutine add_export_coupler

end submodule add_export_coupler_smod
Loading

0 comments on commit 56632cd

Please sign in to comment.