Skip to content

Commit

Permalink
NetCDF fixes on ParFlow
Browse files Browse the repository at this point in the history
FindNetCDF.cmake
- `NETCDF_C_ROOT` still pointing to serial version of NetCDF. Changed
the logical structure such that `NETCDF_C_ROOT` will always point to the parallel-aware NetCDF if it is found.

BuildParFlow.cmake
- Removed `find_package(TCL)`. This is already done inside ParFlow.
  • Loading branch information
kvrigor committed Oct 30, 2024
1 parent 4389d6c commit dce8160
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 0 additions & 2 deletions cmake/BuildParFlow.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
find_package(NetCDF REQUIRED)
find_package(Hypre REQUIRED)
find_package(OpenMP REQUIRED)
find_package(TCL REQUIRED)

#
# Choose which CLM to enable
Expand Down Expand Up @@ -49,7 +48,6 @@ ExternalProject_Add(ParFlow
-DCMAKE_Fortran_FLAGS=${PF_FFLAGS}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DTCL_TCLSH=${TCL_TCLSH}
-DHYPRE_ROOT=${HYPRE_ROOT}
-DNETCDF_INCLUDE_DIR=${NetCDF_C_ROOT}/include
-DNETCDF_LIBRARY=${NetCDF_C_LIB_DIR}/libnetcdf.so # TODO: Fix this hardcoded library file!
Expand Down
15 changes: 9 additions & 6 deletions cmake/FindNetCDF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ include(FindPackageHandleStandardArgs)

find_package(NetCDF_C QUIET NAMES netCDF)
if(NetCDF_C_FOUND)
# Set default NetCDF C paths to the first found NetCDF C library.
set(NetCDF_C_LIB_DIR "${netCDF_LIB_DIR}")
set(NetCDF_C_ROOT "${netCDF_INSTALL_PREFIX}")

# However, if the default NetCDF C library doesn't have parallel support, try searching for another one.
if(NOT ${netCDF_HAS_PARALLEL})
if (netCDF_HAS_PARALLEL)
set(NetCDF_C_ROOT "${netCDF_INSTALL_PREFIX}")
set(NetCDF_C_LIB_DIR "${netCDF_LIB_DIR}")
else()
# If the default NetCDF C library doesn't have parallel support, try searching for another one.
# Option 1 (Ubuntu-specific): `sudo apt-get install libnetcdf-mpi-dev` provides NetCDF with parallel support.
pkg_check_modules(NetCDF_C_MPI QUIET netcdf-mpi)
if (NetCDF_C_MPI_FOUND)
pkg_get_variable(NetCDF_C_ROOT netcdf-mpi prefix)
set(NetCDF_C_LIB_DIR "${NetCDF_C_ROOT}/lib")
set(netCDF_HAS_PARALLEL "ON")
else()
# Set default NetCDF C paths to the first found NetCDF C library.
set(NetCDF_C_ROOT "${netCDF_INSTALL_PREFIX}")
set(NetCDF_C_LIB_DIR "${netCDF_LIB_DIR}")
endif()
endif()
endif()
Expand Down

0 comments on commit dce8160

Please sign in to comment.