diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bc925b7dd1..67a8b32308 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,18 +13,20 @@ project(clm_tests Fortran C) include(CIME_utils) - # find needed external packages # NetCDF is required -- because PIO and NetCDF are required by the standard default ESMF libraries find_package(NetCDF 4.7.4 REQUIRED Fortran) # The following - for finding ESMF - is copied from the share CMakeLists.txt -if (DEFINED ENV{ESMF_ROOT}) +if(DEFINED ENV{ESMF_ROOT}) list(APPEND CMAKE_MODULE_PATH $ENV{ESMF_ROOT}/cmake) endif() + find_package(ESMF REQUIRED) + # This adds include directories needed for ESMF set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${ESMF_F90COMPILEPATHS} ") + # This (which is *not* done in the share CMakeLists.txt) adds all directories and # libraries needed when linking ESMF, including any dependencies of ESMF. (But note that # 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) add_subdirectory(${SRCROOT}/share/unit_test_stubs/util csm_share_stubs) # Add files needed from CMEPS -list ( APPEND drv_sources_needed +list(APPEND drv_sources_needed ${SRCROOT}/components/cmeps/cesm/nuopc_cap_share/glc_elevclass_mod.F90 ${SRCROOT}/components/cmeps/cesm/nuopc_cap_share/shr_dust_emis_mod.F90 ${SRCROOT}/components/cmeps/cesm/nuopc_cap_share/shr_expr_parser_mod.F90 ${SRCROOT}/components/cmeps/cesm/nuopc_cap_share/shr_fire_emis_mod.F90 - ) +) # Add CLM source directories add_subdirectory(${CLM_ROOT}/src/utils clm_utils) @@ -60,6 +62,18 @@ add_subdirectory(${CLM_ROOT}/src/main clm_main) add_subdirectory(${CLM_ROOT}/src/init_interp clm_init_interp) add_subdirectory(${CLM_ROOT}/src/self_tests clm_self_tests) +# Add FATES source directories +# Adding FATES directories is commented out -- because of the problem in: +# https://github.com/ESCOMP/CTSM/issues/3704 +# add_subdirectory(${CLM_ROOT}/src/fates/main fates_main) +# add_subdirectory(${CLM_ROOT}/src/fates/biogeochem fates_biogeochem) +# add_subdirectory(${CLM_ROOT}/src/fates/biogeophys fates_biogeophys) +# add_subdirectory(${CLM_ROOT}/src/fates/parteh fates_parteh) +# add_subdirectory(${CLM_ROOT}/src/fates/fire fates_fire) +# add_subdirectory(${CLM_ROOT}/src/fates/radiation fates_radiation) +# NOTE: Need to add the fates library and dependencies below +# ### End add of FATES directories + # Add general unit test directories (stubbed out files, etc.) add_subdirectory(unit_test_stubs) add_subdirectory(unit_test_shr) @@ -69,10 +83,11 @@ add_subdirectory(unit_test_shr) # TODO: this should be moved into a general-purpose function in Sourcelist_utils. # Then each removal could be replaced with a single call, like: # remove_source_file(${share_sources} "shr_mpi_mod.F90") -foreach (sourcefile ${share_sources}) +foreach(sourcefile ${share_sources}) # Remove shr_mpi_mod from share_sources. # This is needed because we want to use the mock shr_mpi_mod in place of the real one string(REGEX MATCH "shr_mpi_mod.F90" match_found ${sourcefile}) + if(match_found) list(REMOVE_ITEM share_sources ${sourcefile}) endif() @@ -83,6 +98,7 @@ foreach (sourcefile ${share_sources}) # error message, "Cannot open module file 'pio.mod'") on a Mac without a pre-built PIO # (where ESMF was built with its internal PIO). string(REGEX MATCH "shr_pio_mod.F90" match_found ${sourcefile}) + if(match_found) list(REMOVE_ITEM share_sources ${sourcefile}) endif() @@ -101,11 +117,11 @@ include_directories(${SRCROOT}/share/include) # Tell cmake to look for libraries & mod files here, because this is where we built libraries include_directories(${CMAKE_CURRENT_BINARY_DIR}) -include_directories (${NETCDF}/include) +include_directories(${NETCDF}/include) # Directories and libraries to include in the link step link_directories(${CMAKE_CURRENT_BINARY_DIR}) -link_libraries( netcdf esmf ) +link_libraries(netcdf esmf) # Add the test directories # 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) # Add driver unit test directories # (these should be moved to the appropriate submodule) add_subdirectory(${CLM_ROOT}/src/drv_test drv_test) - diff --git a/src/main/test/CMakeLists.txt b/src/main/test/CMakeLists.txt index bf8c164260..b10abdbcba 100644 --- a/src/main/test/CMakeLists.txt +++ b/src/main/test/CMakeLists.txt @@ -8,4 +8,5 @@ add_subdirectory(filter_test) add_subdirectory(initVertical_test) add_subdirectory(ncdio_utils_test) add_subdirectory(topo_test) +add_subdirectory(decomp_test) add_subdirectory(abortutils_test) diff --git a/src/main/test/decomp_test/CMakeLists.txt b/src/main/test/decomp_test/CMakeLists.txt new file mode 100644 index 0000000000..b8c6fea3cf --- /dev/null +++ b/src/main/test/decomp_test/CMakeLists.txt @@ -0,0 +1,8 @@ +set(pfunit_sources + test_decompMod.pf) + +add_pfunit_ctest(decomp + TEST_SOURCES "${pfunit_sources}" + LINK_LIBRARIES clm csm_share esmf + EXTRA_FINALIZE unittest_finalize_esmf + EXTRA_USE unittestInitializeAndFinalize) diff --git a/src/main/test/decomp_test/test_decompMod.pf b/src/main/test/decomp_test/test_decompMod.pf new file mode 100644 index 0000000000..8112e4c6ce --- /dev/null +++ b/src/main/test/decomp_test/test_decompMod.pf @@ -0,0 +1,106 @@ +module test_decompMod + + ! Tests of decompMod + + use funit + use decompMod + use shr_kind_mod , only : r8 => shr_kind_r8 + + implicit none + + @TestCase + type, extends(TestCase) :: TestDecompMod + contains + procedure :: setUp + procedure :: tearDown + procedure :: create_simpleSingleDecomp + end type TestDecompMod + + integer, parameter :: ni = 2 + integer, parameter :: nj = 2 + +contains + + ! ======================================================================== + ! Helper routines + ! ======================================================================== + + subroutine setUp(this) + class(TestDecompMod), intent(inout) :: this + + call this%create_simpleSingleDecomp() + end subroutine setUp + + subroutine tearDown(this) + class(TestDecompMod), intent(inout) :: this + + call decompmod_clean() + + end subroutine tearDown + + subroutine create_simpleSingleDecomp(this) + use spmdMod, only : iam + class(TestDecompMod), intent(inout) :: this + + integer :: clump_pproc + ! TODO: When decompMod has it's own allocate method that could be used here + nclumps = 1 + clump_pproc = nclumps + allocate(procinfo%cid(clump_pproc)) + allocate(clumps(nclumps)) + ! Set the procinfo and clumps values + ! TODO: Use initialization method when available (currently in decompInitMod) + procinfo%cid = 1 + procinfo%ncells = ni*nj + procinfo%begg = 1 + procinfo%endg = procinfo%ncells + procinfo%nclumps = nclumps + clumps(:)%owner = iam + clumps(:)%begg = 1 + clumps(:)%endg = procinfo%ncells + + end subroutine create_simpleSingleDecomp + ! ======================================================================== + ! Begin tests + ! ======================================================================== + + @Test + subroutine test_get_clump_bounds(this) + class(TestDecompMod), intent(inout) :: this + + type(bounds_type) :: bounds + integer :: n + + do n = 1, procinfo%nclumps + call get_clump_bounds(n, bounds) + @assertEqual(bounds%level, bounds_level_clump) + @assertEqual(bounds%clump_index, n) + end do + end subroutine test_get_clump_bounds + + @Test + subroutine test_get_proc_bounds(this) + class(TestDecompMod), intent(inout) :: this + + type(bounds_type) :: bounds + + ! Add optional argument, just to test that it can handle it + call get_proc_bounds(bounds, allow_call_from_threaded_region=.true.) + @assertEqual(bounds%level, bounds_level_proc) + @assertEqual(bounds%clump_index, -1) + end subroutine test_get_proc_bounds + + @Test + subroutine test_proc_clump_bounds_equal(this) + class(TestDecompMod), intent(inout) :: this + + type(bounds_type) :: bounds_clump, bounds_proc + + @assertTrue(procinfo%nclumps == 1) + call get_clump_bounds(1, bounds_clump) + call get_proc_bounds(bounds_proc) + @assertEqual(bounds_proc%begg, bounds_clump%begg) + @assertEqual(bounds_proc%endg, bounds_clump%endg) + end subroutine test_proc_clump_bounds_equal + +end module test_decompMod diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 04ad683517..9038b6dbca 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -22,6 +22,7 @@ list(APPEND clm_sources SparseMatrixMultiplyMod.F90 IssueFixedMetadataHandler.F90 NumericsMod.F90 + spmdMod.F90 ) sourcelist_to_parent(clm_sources)