-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
290 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
set (SRCS | ||
MAPL_GetHorzIJIndex_Mod.F90 | ||
driver_MAPL_GetHorzIJIndex.F90 | ||
GridComp.F90 | ||
driver.F90 | ||
) | ||
|
||
#set(dependencies MAPL GFTL_SHARED::gftl-shared esmf OpenMP::OpenMP_Fortran) | ||
|
||
ecbuild_add_executable ( | ||
TARGET driver_MAPL_GetHorzIJIndex.x | ||
TARGET GetHorzIJIndexDriver.x | ||
SOURCES ${SRCS} ) | ||
target_link_libraries(driver_MAPL_GetHorzIJIndex.x PRIVATE MAPL FARGPARSE::fargparse ESMF::ESMF OpenMP::OpenMP_Fortran) | ||
target_link_libraries(GetHorzIJIndexDriver.x PRIVATE MAPL FARGPARSE::fargparse ESMF::ESMF OpenMP::OpenMP_Fortran) | ||
|
||
# Detect if we are using Open MPI and add oversubscribe | ||
string(REPLACE " " ";" MPI_Fortran_LIBRARY_VERSION_LIST ${MPI_Fortran_LIBRARY_VERSION_STRING}) | ||
list(GET MPI_Fortran_LIBRARY_VERSION_LIST 0 MPI_Fortran_LIBRARY_VERSION_FIRSTWORD) | ||
if(MPI_Fortran_LIBRARY_VERSION_FIRSTWORD MATCHES "Open") | ||
list(APPEND MPIEXEC_PREFLAGS "-oversubscribe") | ||
endif() | ||
|
||
set (TEST_CASES | ||
NO_OMP | ||
OMP_1_thread | ||
OMP_4_thread | ||
) | ||
|
||
foreach(TEST_CASE ${TEST_CASES}) | ||
|
||
add_test( | ||
NAME "GetHorzIJIndex_${TEST_CASE}" | ||
COMMAND ${CMAKE_COMMAND} | ||
-DTEST_CASE=${TEST_CASE} | ||
-DMPIEXEC_EXECUTABLE=${MPIEXEC_EXECUTABLE} | ||
-DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} | ||
-DMY_BINARY_DIR=${CMAKE_BINARY_DIR}/bin | ||
-DMPIEXEC_PREFLAGS=${MPIEXEC_PREFLAGS} | ||
-P ${CMAKE_CURRENT_SOURCE_DIR}/run_gethorzijindex.cmake | ||
) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
#include "MAPL_Generic.h" | ||
#include "MAPL_Exceptions.h" | ||
|
||
|
||
module GridComp | ||
|
||
use ESMF | ||
use MAPL | ||
|
||
implicit none | ||
private | ||
|
||
public setservices | ||
|
||
contains | ||
|
||
subroutine setservices(gc,rc) | ||
|
||
type(ESMF_GridComp), intent(inout) :: gc | ||
integer, optional :: rc | ||
|
||
type (MAPL_MetaComp), pointer :: MAPL | ||
type (ESMF_Config) :: cf | ||
integer :: status | ||
logical :: use_threads | ||
integer :: num_threads | ||
|
||
call MAPL_GetObjectFromGC (gc, MAPL, _RC) | ||
call ESMF_GridCompGet(gc, config=cf, _RC) | ||
call ESMF_ConfigGetAttribute(cf, use_threads, label='use_threads:', default=.FALSE., _RC) | ||
call MAPL%set_use_threads(use_threads) | ||
|
||
call MAPL_GridCompSetEntryPoint ( gc, ESMF_METHOD_INITIALIZE, initialize, _RC) | ||
call MAPL_GridCompSetEntryPoint ( gc, ESMF_METHOD_RUN, run, _RC) | ||
call MAPL_GenericSetServices(gc, _RC) | ||
|
||
_RETURN(_SUCCESS) | ||
|
||
end subroutine setservices | ||
|
||
|
||
subroutine initialize(gc, import, export, clock, rc) | ||
type(ESMF_GridComp), intent(inout) :: gc | ||
type(ESMF_State), intent(inout) :: import | ||
type(ESMF_State), intent(inout) :: export | ||
type(ESMF_Clock), intent(inout) :: clock | ||
integer, intent(out), optional :: rc | ||
|
||
type (MAPL_MetaComp), pointer :: MAPL | ||
integer :: status | ||
|
||
call MAPL_GridCreate(gc, _RC) | ||
call MAPL_GetObjectFromGC (gc, MAPL, _RC) | ||
print *, 'Num threads = ', MAPL_get_num_threads(), ' for this run' | ||
call MAPL_GenericInitialize(gc, import, export, clock, _RC) | ||
|
||
_RETURN(_SUCCESS) | ||
|
||
end subroutine initialize | ||
|
||
subroutine check_dim(grid, rc) | ||
type(ESMF_Grid), intent(in) :: grid | ||
integer, intent(out), optional :: rc | ||
|
||
! locals | ||
integer :: status | ||
integer :: dims(3) | ||
|
||
call MAPL_GridGet(grid, globalCellCountPerDim=dims,_RC) | ||
|
||
_ASSERT(dims(1)*6 == dims(2), 'Mini grid should act as a cubed sphere grid for global extents') | ||
|
||
_RETURN(_SUCCESS) | ||
|
||
end subroutine check_dim | ||
|
||
subroutine check_expected_index(grid, rc) | ||
type(ESMF_Grid), intent(inout) :: grid | ||
integer, intent(out), optional :: rc | ||
|
||
! locals | ||
integer :: status, i, j, II(1), JJ(1) | ||
real, dimension(:,:), pointer :: lats, lons | ||
real :: lon(1), lat(1) | ||
|
||
|
||
call ESMFL_GridCoordGet( grid, LATS , & | ||
Name = "Latitude" , & | ||
Location = ESMF_STAGGERLOC_CENTER , & | ||
Units = MAPL_UnitsRadians , _RC) | ||
|
||
call ESMFL_GridCoordGet( grid, LONS , & | ||
Name = "Longitude" , & | ||
Location = ESMF_STAGGERLOC_CENTER , & | ||
Units = MAPL_UnitsRadians , _RC) | ||
_ASSERT(all(shape(LATS) == shape(LONS)), 'LATS and LONS must have the same shape') | ||
|
||
do j = 1, size(LATS,2) | ||
do i = 1, size(LATS, 1) | ||
lon = lons(i,j) | ||
lat = lats(i,j) | ||
call MAPL_GetHorzIJIndex(1, II, JJ, & | ||
grid=grid, lon=lon, lat=lat, _RC) | ||
_ASSERT(II(1) == i, 'I-index of cell center (i,j) should be i') | ||
_ASSERT(JJ(1) == j, 'J-index of cell center (i,j) should be j') | ||
end do | ||
end do | ||
|
||
_RETURN(_SUCCESS) | ||
|
||
end subroutine check_expected_index | ||
|
||
subroutine check_unexpected_index(grid, rc) | ||
type(ESMF_Grid), intent(inout) :: grid | ||
integer, intent(out), optional :: rc | ||
|
||
! locals | ||
integer :: status, i, j, II(1), JJ(1) | ||
real, dimension(:,:), pointer :: lats, lons | ||
real :: lon(1), lat(1) | ||
|
||
|
||
call ESMFL_GridCoordGet( grid, lats , & | ||
Name = "Latitude" , & | ||
Location = ESMF_STAGGERLOC_CENTER , & | ||
Units = MAPL_UnitsRadians , _RC) | ||
|
||
call ESMFL_GridCoordGet( grid, lons , & | ||
Name = "Longitude" , & | ||
Location = ESMF_STAGGERLOC_CENTER , & | ||
Units = MAPL_UnitsRadians , _RC) | ||
! centers of antipodal points | ||
lons = lons + MAPL_PI | ||
lats = -lats | ||
_ASSERT(all(shape(LATS) == shape(LONS)), 'LATS and LONS must have the same shape') | ||
|
||
do j = 1, size(lats,2) | ||
do i = 1, size(lats, 1) | ||
lon = lons(i,j) | ||
lat = lats(i,j) | ||
call MAPL_GetHorzIJIndex(1, II(1), JJ(1), & | ||
grid=grid, lon=lon, lat=lat, _RC) | ||
_ASSERT(II(1) == -1, 'Expected -1 for point outside of domain') | ||
_ASSERT(JJ(1) == -1, 'Expected -1 for point outside of domain') | ||
end do | ||
end do | ||
|
||
_RETURN(_SUCCESS) | ||
|
||
end subroutine check_unexpected_index | ||
|
||
subroutine run(gc, import, export, clock, rc) | ||
type(ESMF_GridComp), intent(inout) :: gc | ||
type(ESMF_State), intent(inout) :: import | ||
type(ESMF_State), intent(inout) :: export | ||
type(ESMF_Clock), intent(inout) :: clock | ||
integer, intent(out), optional :: rc | ||
|
||
! locals | ||
type (MAPL_MetaComp), pointer :: mapl | ||
type (ESMF_Grid) :: grid | ||
integer :: status | ||
|
||
call MAPL_GetObjectFromGC (gc, MAPL, _RC) | ||
call MAPL_Get (MAPL, grid=grid, _RC) | ||
call ESMF_GridValidate(grid,_RC) | ||
|
||
call check_dim(grid, _RC) | ||
call check_expected_index(grid, _RC) | ||
call check_unexpected_index(grid, _RC) | ||
|
||
_UNUSED_DUMMY(import) | ||
_UNUSED_DUMMY(export) | ||
_UNUSED_DUMMY(clock) | ||
|
||
_RETURN(_SUCCESS) | ||
|
||
end subroutine run | ||
|
||
end module GridComp |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.