Skip to content

Commit

Permalink
Merge branch 'cmake-smiol' into develop (PR #1254)
Browse files Browse the repository at this point in the history
This merge allows MPAS-Atmosphere, when compiled with CMake, to use SMIOL
rather than PIO. The use of SMIOL is activated by adding -DMPAS_USE_SMIOL=ON
to the cmake command-line. The PIO library remains the default I/O layer in
CMake-compiled MPAS-Atmosphere.

* cmake-smiol:
  Add support for using the SMIOL I/O library when building with cmake.
  • Loading branch information
mgduda committed Jan 16, 2025
2 parents 4ea6abb + 64d3d05 commit d035210
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ option(MPAS_DOUBLE_PRECISION "Use double precision 64-bit Floating point." TRUE)
option(MPAS_PROFILE "Enable GPTL profiling" OFF)
option(MPAS_OPENMP "Enable OpenMP" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(MPAS_USE_SMIOL "Build with smiol I/O library" OFF)

message(STATUS "[OPTION] MPAS_CORES: ${MPAS_CORES}")
message(STATUS "[OPTION] MPAS_DOUBLE_PRECISION: ${MPAS_DOUBLE_PRECISION}")
message(STATUS "[OPTION] MPAS_PROFILE: ${MPAS_PROFILE}")
message(STATUS "[OPTION] MPAS_OPENMP: ${MPAS_OPENMP}")
message(STATUS "[OPTION] BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
message(STATUS "[OPTION] MPAS_USE_SMIOL: ${MPAS_USE_SMIOL}")

# Build product output locations
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
Expand Down Expand Up @@ -59,7 +61,9 @@ find_package(OpenMP COMPONENTS Fortran)
find_package(MPI REQUIRED COMPONENTS Fortran)
find_package(NetCDF REQUIRED COMPONENTS Fortran C)
find_package(PnetCDF REQUIRED COMPONENTS Fortran)
find_package(PIO REQUIRED COMPONENTS Fortran C)
if(NOT MPAS_USE_SMIOL)
find_package(PIO REQUIRED COMPONENTS Fortran C)
endif()
if(MPAS_PROFILE)
find_package(GPTL REQUIRED)
endif()
Expand Down Expand Up @@ -88,6 +92,9 @@ set(MPAS_SUBDRIVER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/driver/mpas_subdriver.F)

## Create targets
add_subdirectory(src/external/ezxml) # Target: MPAS::external::ezxml
if(MPAS_USE_SMIOL)
add_subdirectory(src/external/SMIOL) # Target: MPAS::external::smiol
endif()
if(ESMF_FOUND)
message(STATUS "Configure MPAS for external ESMF")
add_definitions(-DMPAS_EXTERNAL_ESMF_LIB -DMPAS_NO_ESMF_INIT)
Expand Down
16 changes: 11 additions & 5 deletions cmake/Functions/MPAS_Functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ function(mpas_fortran_target target)

# Global Fortran configuration
set_target_properties(${target} PROPERTIES Fortran_FORMAT FREE)
set(MPAS_FORTRAN_TARGET_COMPILE_DEFINITIONS
_MPI=1
USE_PIO2=1
)
if(MPAS_USE_SMIOL)
set(MPAS_FORTRAN_TARGET_COMPILE_DEFINITIONS
MPAS_SMIOL_SUPPORT=1
)
else()
set(MPAS_FORTRAN_TARGET_COMPILE_DEFINITIONS
USE_PIO2=1
)
endif()
list(APPEND MPAS_FORTRAN_TARGET_COMPILE_DEFINITIONS _MPI=1)
# Enable OpenMP support
if(MPAS_OPENMP)
target_link_libraries(${target} PUBLIC OpenMP::OpenMP_Fortran)
Expand Down Expand Up @@ -244,4 +250,4 @@ function(set_MPAS_DEBUG_flag target)
if(CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(${target} PRIVATE MPAS_DEBUG)
endif()
endfunction()
endfunction()
32 changes: 32 additions & 0 deletions src/external/SMIOL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

find_package(MPI REQUIRED COMPONENTS C Fortran)
find_package(NetCDF REQUIRED COMPONENTS Fortran C)
find_package(PnetCDF REQUIRED COMPONENTS Fortran C)

# Specify the library source files
set(SMIOL_C_SOURCES smiol.c smiol_utils.c)
set(SMIOL_F_SOURCES smiolf.F90)

# Create the C library
add_library(smiol ${SMIOL_C_SOURCES})
add_library(${PROJECT_NAME}::external::smiol ALIAS smiol)
target_compile_definitions(smiol PRIVATE SMIOL_PNETCDF SINGLE_PRECISION)
target_include_directories(smiol PRIVATE ${MPI_INCLUDE_PATH})
target_link_libraries( smiol PRIVATE MPI::MPI_C PnetCDF::PnetCDF_C )

# Create the Fortran library
add_library(smiolf ${SMIOL_F_SOURCES})
enable_language(Fortran)
mpas_fortran_target(smiolf)
add_library(${PROJECT_NAME}::external::smiolf ALIAS smiolf)
target_compile_definitions(smiolf PRIVATE SMIOL_PNETCDF )
# fortran lib requires the c lib
target_link_libraries(smiolf PUBLIC smiol)
target_include_directories(smiol PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

install(TARGETS smiol EXPORT ${PROJECT_NAME}ExportsExternal
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS smiolf EXPORT ${PROJECT_NAME}ExportsExternal
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
19 changes: 13 additions & 6 deletions src/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ set(MPAS_FRAMEWORK_SOURCES
add_library(framework ${MPAS_FRAMEWORK_SOURCES})
set_MPAS_DEBUG_flag(framework)
set(FRAMEWORK_COMPILE_DEFINITIONS
USE_PIO2
MPAS_PIO_SUPPORT
mpas=1
MPAS_NATIVE_TIMERS)
mpas=1
MPAS_NATIVE_TIMERS)
if (MPAS_USE_SMIOL)
list(APPEND FRAMEWORK_COMPILE_DEFINITIONS MPAS_SMIOL_SUPPORT)
set(IO_LIBS
${PROJECT_NAME}::external::smiolf)
else()
list(APPEND FRAMEWORK_COMPILE_DEFINITIONS USE_PIO2 MPAS_PIO_SUPPORT)
set(IO_LIBS
PIO::PIO_Fortran
PIO::PIO_C)
endif()
target_compile_definitions(framework PRIVATE ${FRAMEWORK_COMPILE_DEFINITIONS})

mpas_fortran_target(framework)
Expand All @@ -53,8 +61,7 @@ set_target_properties(framework PROPERTIES OUTPUT_NAME mpas_framework)
set(FRAMEWORK_LINK_LIBRARIES
${PROJECT_NAME}::external::esmf
${PROJECT_NAME}::external::ezxml
PIO::PIO_Fortran
PIO::PIO_C
${IO_LIBS}
PnetCDF::PnetCDF_Fortran
NetCDF::NetCDF_Fortran
NetCDF::NetCDF_C
Expand Down

0 comments on commit d035210

Please sign in to comment.