Skip to content

Commit

Permalink
combine into one derived type
Browse files Browse the repository at this point in the history
  • Loading branch information
bena-nasa committed May 20, 2024
1 parent ef78c10 commit 517ade9
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 130 deletions.
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
13 changes: 8 additions & 5 deletions GeomIO/Grid_PFIO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module mapl3g_GridPFIO
use PFIO
use MAPL_BaseMod
use MAPL_FieldPointerUtilities
use mapl3g_pFIOServerBounds
use, intrinsic :: iso_c_binding, only: c_ptr
implicit none
private
Expand Down Expand Up @@ -40,6 +41,7 @@ subroutine stage_data_to_file(this, bundle, filename, time_index, rc)
integer, allocatable :: element_count(:), new_element_count(:)

type(ESMF_Grid) :: grid
type(pFIOServerBounds) :: server_bounds

collection_id = this%get_collection_id()
call ESMF_FieldBundleGet(bundle, fieldCount=num_fields, _RC)
Expand All @@ -51,14 +53,15 @@ subroutine stage_data_to_file(this, bundle, filename, time_index, rc)
element_count = FieldGetLocalElementCount(field, _RC)
call ESMF_FieldGet(field, grid=grid, typekind=tk, _RC)

global_start = create_global_start(grid, element_count, time_index=time_index, _RC)
global_count = create_global_count(grid, element_count, have_time=.true., _RC)
local_start = create_local_start(grid, element_count, have_time=.true., _RC)

call server_bounds%create_server_bounds(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 = create_file_shape(grid, element_count, _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)), &
Expand Down
118 changes: 0 additions & 118 deletions GeomIO/SharedIO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -15,127 +15,9 @@ module mapl3g_SharedIO
public create_time_variable
public bundle_to_metadata
public esmf_to_pfio_type
public create_local_start
public create_global_count
public create_global_start
public create_file_shape

contains

function create_file_shape(grid, field_shape, rc) result(file_shape)
integer, allocatable :: file_shape(:)
type(ESMF_Grid), intent(in) :: grid
integer, intent(in) :: field_shape(:)
integer, intent(out), optional :: rc

integer :: status, sz, ungr, tile_count
call ESMF_GridGet(grid, tileCount=tile_count, _RC)
sz = size(field_shape)
ungr = sz - 2
if (tile_count == 6) then
allocate(file_shape(sz+1))
file_shape(1:3) = [field_shape(1), field_shape(2), 1]
file_shape(4:4+ungr-1) = [field_shape(2+ungr:sz)]
else if (tile_count == 1) then
file_shape = field_shape
else
_FAIL("unsupported grid")
end if

_RETURN(_SUCCESS)
end function create_file_shape

function create_global_start(grid, field_shape, time_index, rc) result(global_start)
integer, allocatable :: global_start(:)
type(ESMF_Grid), intent(in) :: grid
integer, intent(in) :: field_shape(:)
integer, optional, intent(in) :: time_index
integer, intent(out), optional :: rc

integer :: status, sz, tile_count, tm
call ESMF_GridGet(grid, tileCount=tile_count, _RC)
sz = size(field_shape)

tm = 0
if (present(time_index)) tm=1
if (tile_count == 6) then
allocate(global_start(sz+1+tm))
global_start(1:sz+1) = 1
if (present(time_index)) global_start(sz+2) = time_index
else if (tile_count == 1) then
allocate(global_start(sz+tm))
global_start(1:sz) = 1
if (present(time_index)) global_start(sz+1) = time_index
else
_FAIL("unsupported grid")
end if

_RETURN(_SUCCESS)
end function create_global_start

function create_global_count(grid, field_shape, have_time, rc) result(global_count)
integer, allocatable :: global_count(:)
type(ESMF_Grid), intent(in) :: grid
integer, intent(in) :: field_shape(:)
logical, optional, intent(in) :: have_time
integer, intent(out), optional :: rc

integer :: status, sz, ungr, tile_count, global_dim(3), tm
if (present(have_time)) tm=1
call ESMF_GridGet(grid, tileCount=tile_count, _RC)
call MAPL_GridGet(grid, globalCellCountPerDim=global_dim, _RC)
sz = size(field_shape)
ungr = sz - 2

if (tile_count == 6) then
allocate(global_count(sz+1+tm))
global_count(1:3) =[global_dim(1),global_dim(1),6]
global_count(4:4+ungr-1) = field_shape(3:sz)
if (have_time) global_count(sz+2) = 1
else if (tile_count == 1) then
allocate(global_count(sz+tm))
global_count(1:2) =[global_dim(1),global_dim(2)]
global_count(3:3+ungr-1) = field_shape(3:sz)
if (have_time) global_count(sz+1) = 1
else
_FAIL("unsupported grid")
end if


_RETURN(_SUCCESS)
end function create_global_count

function create_local_start(grid, field_shape, have_time, rc) result(local_start)
integer, allocatable :: local_start(:)
type(ESMF_Grid), intent(in) :: grid
integer, intent(in) :: field_shape(:)
logical, optional, intent(in) :: have_time
integer, intent(out), optional :: rc

integer :: status, sz, ungr, tile_count, i1, in, j1, jn, tile, global_dim(3), tm
call ESMF_GridGet(grid, tileCount=tile_count, _RC)
call MAPL_GridGetInterior(grid, i1,in, j1, jn)
call MAPL_GridGet(grid, globalCellCountPerDim=global_dim, _RC)
tm=0
if (present(have_time)) tm=1
sz = size(field_shape)
ungr = sz - 2
if (tile_count == 6) then
tile = 1 + (j1-1)/global_dim(1)
allocate(local_start(sz+1+tm))
local_start=1
local_start(1:3) = [i1, j1-(tile-1)*global_dim(1),tile]
else if (tile_count == 1) then
allocate(local_start(sz+tm))
local_start=1
local_start(1:2) = [i1,j1]
else
_FAIL("unsupported grid")
end if

_RETURN(_SUCCESS)
end function create_local_start

function bundle_to_metadata(bundle, geom, rc) result(metadata)
type(FileMetaData) :: metadata
type(ESMF_FieldBundle), intent(in) :: bundle
Expand Down
120 changes: 120 additions & 0 deletions GeomIO/pFIOServerBounds.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#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 :: create_server_bounds
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 create_server_bounds(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, ungrid_dims, tm, global_dim(3)
integer :: i1, in, j1, jn, tile

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)
ungrid_dims = n_dims - grid_dims
tm = 0
if (present(time_index)) tm = 1

if (tile_count == 6) then
tile = 1 + (j1-1)/global_dim(1)
allocate(this%file_shape(n_dims+1))
allocate(this%global_start(n_dims+1+tm))
allocate(this%global_count(n_dims+1+tm))
allocate(this%local_start(n_dims+1+tm))

this%file_shape(1:grid_dims+1) = [field_shape(1), field_shape(2) ,1]
this%file_shape(grid_dims+2:grid_dims+ungrid_dims+1) = [field_shape(grid_dims+ungrid_dims:n_dims)]

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

this%global_count(1:grid_dims+1) =[global_dim(1), global_dim(1), tile_count]
this%global_count(grid_dims+2:grid_dims+ungrid_dims+1) = field_shape(grid_dims+1:n_dims)
if (present(time_index)) this%global_count(n_dims+2) = 1

this%local_start = 1
this%local_start(1:grid_dims+1) = [i1, j1-(tile-1)*global_dim(1), tile]


else if (tile_count == 1) then
allocate(this%global_start(n_dims+tm))
allocate(this%global_count(n_dims+tm))
allocate(this%local_start(n_dims+tm))

this%file_shape = field_shape

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

this%global_count(1:grid_dims) = [global_dim(1), global_dim(2)]
this%global_count(grid_dims+1:grid_dims+ungrid_dims) = field_shape(grid_dims:n_dims)
if (present(time_index)) this%global_count(n_dims+1) = 1

this%local_start = 1
this%local_start(1:grid_dims) = [i1,j1]

else
_FAIL("unsupported grid")
end if
_RETURN(_SUCCESS)

end subroutine create_server_bounds

end module mapl3g_pFIOServerBounds

14 changes: 7 additions & 7 deletions pfio/ArrayReference.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ module pFIO_ArrayReferenceMod
end type ArrayReference

interface ArrayReference
module procedure new_ArrayReference_from_param
module procedure new_ArrayReference_0d
module procedure new_ArrayReference_1d
module procedure new_ArrayReference_2d
module procedure new_ArrayReference_3d
module procedure new_ArrayReference_4d
module procedure new_ArrayReference_5d
procedure new_ArrayReference_from_param
procedure new_ArrayReference_0d
procedure new_ArrayReference_1d
procedure new_ArrayReference_2d
procedure new_ArrayReference_3d
procedure new_ArrayReference_4d
procedure new_ArrayReference_5d
end interface ArrayReference

contains
Expand Down

0 comments on commit 517ade9

Please sign in to comment.