Skip to content

Commit 92a9125

Browse files
authored
Merge pull request #3699 from ekluzek/decompMod_unittest
Decomp mod unittest
2 parents 8b97e2a + 5ac060d commit 92a9125

File tree

5 files changed

+139
-8
lines changed

5 files changed

+139
-8
lines changed

src/CMakeLists.txt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ project(clm_tests Fortran C)
1313

1414
include(CIME_utils)
1515

16-
1716
# find needed external packages
1817
# NetCDF is required -- because PIO and NetCDF are required by the standard default ESMF libraries
1918
find_package(NetCDF 4.7.4 REQUIRED Fortran)
2019

2120
# The following - for finding ESMF - is copied from the share CMakeLists.txt
22-
if (DEFINED ENV{ESMF_ROOT})
21+
if(DEFINED ENV{ESMF_ROOT})
2322
list(APPEND CMAKE_MODULE_PATH $ENV{ESMF_ROOT}/cmake)
2423
endif()
24+
2525
find_package(ESMF REQUIRED)
26+
2627
# This adds include directories needed for ESMF
2728
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${ESMF_F90COMPILEPATHS} ")
29+
2830
# This (which is *not* done in the share CMakeLists.txt) adds all directories and
2931
# libraries needed when linking ESMF, including any dependencies of ESMF. (But note that
3032
# this does *not* include the "-lesmf" itself). In particular, note that this includes any
@@ -43,12 +45,12 @@ add_subdirectory(${SRCROOT}/share/src csm_share)
4345
add_subdirectory(${SRCROOT}/share/unit_test_stubs/util csm_share_stubs)
4446

4547
# Add files needed from CMEPS
46-
list ( APPEND drv_sources_needed
48+
list(APPEND drv_sources_needed
4749
${SRCROOT}/components/cmeps/cesm/nuopc_cap_share/glc_elevclass_mod.F90
4850
${SRCROOT}/components/cmeps/cesm/nuopc_cap_share/shr_dust_emis_mod.F90
4951
${SRCROOT}/components/cmeps/cesm/nuopc_cap_share/shr_expr_parser_mod.F90
5052
${SRCROOT}/components/cmeps/cesm/nuopc_cap_share/shr_fire_emis_mod.F90
51-
)
53+
)
5254

5355
# Add CLM source directories
5456
add_subdirectory(${CLM_ROOT}/src/utils clm_utils)
@@ -60,6 +62,18 @@ add_subdirectory(${CLM_ROOT}/src/main clm_main)
6062
add_subdirectory(${CLM_ROOT}/src/init_interp clm_init_interp)
6163
add_subdirectory(${CLM_ROOT}/src/self_tests clm_self_tests)
6264

65+
# Add FATES source directories
66+
# Adding FATES directories is commented out -- because of the problem in:
67+
# https://github.com/ESCOMP/CTSM/issues/3704
68+
# add_subdirectory(${CLM_ROOT}/src/fates/main fates_main)
69+
# add_subdirectory(${CLM_ROOT}/src/fates/biogeochem fates_biogeochem)
70+
# add_subdirectory(${CLM_ROOT}/src/fates/biogeophys fates_biogeophys)
71+
# add_subdirectory(${CLM_ROOT}/src/fates/parteh fates_parteh)
72+
# add_subdirectory(${CLM_ROOT}/src/fates/fire fates_fire)
73+
# add_subdirectory(${CLM_ROOT}/src/fates/radiation fates_radiation)
74+
# NOTE: Need to add the fates library and dependencies below
75+
# ### End add of FATES directories
76+
6377
# Add general unit test directories (stubbed out files, etc.)
6478
add_subdirectory(unit_test_stubs)
6579
add_subdirectory(unit_test_shr)
@@ -69,10 +83,11 @@ add_subdirectory(unit_test_shr)
6983
# TODO: this should be moved into a general-purpose function in Sourcelist_utils.
7084
# Then each removal could be replaced with a single call, like:
7185
# remove_source_file(${share_sources} "shr_mpi_mod.F90")
72-
foreach (sourcefile ${share_sources})
86+
foreach(sourcefile ${share_sources})
7387
# Remove shr_mpi_mod from share_sources.
7488
# This is needed because we want to use the mock shr_mpi_mod in place of the real one
7589
string(REGEX MATCH "shr_mpi_mod.F90" match_found ${sourcefile})
90+
7691
if(match_found)
7792
list(REMOVE_ITEM share_sources ${sourcefile})
7893
endif()
@@ -83,6 +98,7 @@ foreach (sourcefile ${share_sources})
8398
# error message, "Cannot open module file 'pio.mod'") on a Mac without a pre-built PIO
8499
# (where ESMF was built with its internal PIO).
85100
string(REGEX MATCH "shr_pio_mod.F90" match_found ${sourcefile})
101+
86102
if(match_found)
87103
list(REMOVE_ITEM share_sources ${sourcefile})
88104
endif()
@@ -101,11 +117,11 @@ include_directories(${SRCROOT}/share/include)
101117

102118
# Tell cmake to look for libraries & mod files here, because this is where we built libraries
103119
include_directories(${CMAKE_CURRENT_BINARY_DIR})
104-
include_directories (${NETCDF}/include)
120+
include_directories(${NETCDF}/include)
105121

106122
# Directories and libraries to include in the link step
107123
link_directories(${CMAKE_CURRENT_BINARY_DIR})
108-
link_libraries( netcdf esmf )
124+
link_libraries(netcdf esmf)
109125

110126
# Add the test directories
111127
# Note: it's possible that these could be added by each source directory that
@@ -125,4 +141,3 @@ add_subdirectory(${CLM_ROOT}/src/self_tests/test clm_self_tests_test)
125141
# Add driver unit test directories
126142
# (these should be moved to the appropriate submodule)
127143
add_subdirectory(${CLM_ROOT}/src/drv_test drv_test)
128-

src/main/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ add_subdirectory(filter_test)
88
add_subdirectory(initVertical_test)
99
add_subdirectory(ncdio_utils_test)
1010
add_subdirectory(topo_test)
11+
add_subdirectory(decomp_test)
1112
add_subdirectory(abortutils_test)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(pfunit_sources
2+
test_decompMod.pf)
3+
4+
add_pfunit_ctest(decomp
5+
TEST_SOURCES "${pfunit_sources}"
6+
LINK_LIBRARIES clm csm_share esmf
7+
EXTRA_FINALIZE unittest_finalize_esmf
8+
EXTRA_USE unittestInitializeAndFinalize)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
module test_decompMod
2+
3+
! Tests of decompMod
4+
5+
use funit
6+
use decompMod
7+
use shr_kind_mod , only : r8 => shr_kind_r8
8+
9+
implicit none
10+
11+
@TestCase
12+
type, extends(TestCase) :: TestDecompMod
13+
contains
14+
procedure :: setUp
15+
procedure :: tearDown
16+
procedure :: create_simpleSingleDecomp
17+
end type TestDecompMod
18+
19+
integer, parameter :: ni = 2
20+
integer, parameter :: nj = 2
21+
22+
contains
23+
24+
! ========================================================================
25+
! Helper routines
26+
! ========================================================================
27+
28+
subroutine setUp(this)
29+
class(TestDecompMod), intent(inout) :: this
30+
31+
call this%create_simpleSingleDecomp()
32+
end subroutine setUp
33+
34+
subroutine tearDown(this)
35+
class(TestDecompMod), intent(inout) :: this
36+
37+
call decompmod_clean()
38+
39+
end subroutine tearDown
40+
41+
subroutine create_simpleSingleDecomp(this)
42+
use spmdMod, only : iam
43+
class(TestDecompMod), intent(inout) :: this
44+
45+
integer :: clump_pproc
46+
! TODO: When decompMod has it's own allocate method that could be used here
47+
nclumps = 1
48+
clump_pproc = nclumps
49+
allocate(procinfo%cid(clump_pproc))
50+
allocate(clumps(nclumps))
51+
! Set the procinfo and clumps values
52+
! TODO: Use initialization method when available (currently in decompInitMod)
53+
procinfo%cid = 1
54+
procinfo%ncells = ni*nj
55+
procinfo%begg = 1
56+
procinfo%endg = procinfo%ncells
57+
procinfo%nclumps = nclumps
58+
clumps(:)%owner = iam
59+
clumps(:)%begg = 1
60+
clumps(:)%endg = procinfo%ncells
61+
62+
end subroutine create_simpleSingleDecomp
63+
! ========================================================================
64+
! Begin tests
65+
! ========================================================================
66+
67+
@Test
68+
subroutine test_get_clump_bounds(this)
69+
class(TestDecompMod), intent(inout) :: this
70+
71+
type(bounds_type) :: bounds
72+
integer :: n
73+
74+
do n = 1, procinfo%nclumps
75+
call get_clump_bounds(n, bounds)
76+
@assertEqual(bounds%level, bounds_level_clump)
77+
@assertEqual(bounds%clump_index, n)
78+
end do
79+
end subroutine test_get_clump_bounds
80+
81+
@Test
82+
subroutine test_get_proc_bounds(this)
83+
class(TestDecompMod), intent(inout) :: this
84+
85+
type(bounds_type) :: bounds
86+
87+
! Add optional argument, just to test that it can handle it
88+
call get_proc_bounds(bounds, allow_call_from_threaded_region=.true.)
89+
@assertEqual(bounds%level, bounds_level_proc)
90+
@assertEqual(bounds%clump_index, -1)
91+
end subroutine test_get_proc_bounds
92+
93+
@Test
94+
subroutine test_proc_clump_bounds_equal(this)
95+
class(TestDecompMod), intent(inout) :: this
96+
97+
type(bounds_type) :: bounds_clump, bounds_proc
98+
99+
@assertTrue(procinfo%nclumps == 1)
100+
call get_clump_bounds(1, bounds_clump)
101+
call get_proc_bounds(bounds_proc)
102+
@assertEqual(bounds_proc%begg, bounds_clump%begg)
103+
@assertEqual(bounds_proc%endg, bounds_clump%endg)
104+
end subroutine test_proc_clump_bounds_equal
105+
106+
end module test_decompMod

src/utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ list(APPEND clm_sources
2222
SparseMatrixMultiplyMod.F90
2323
IssueFixedMetadataHandler.F90
2424
NumericsMod.F90
25+
spmdMod.F90
2526
)
2627

2728
sourcelist_to_parent(clm_sources)

0 commit comments

Comments
 (0)