Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using the SMIOL I/O library when building with cmake. #1254

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to work. When I build with -DMPAS_USE_SMIOL=1 the cmake output still has:

-- Found PIO: /glade/work/epicufsrt/contrib/spack-stack/derecho/spack-stack-1.6.0/envs/unified-env/install/gcc/12.2.0/parallelio-2.5.10-ysh2ljm  found components: Fortran C 
-- FindPIO:
--   - PIO_PREFIX [/glade/work/epicufsrt/contrib/spack-stack/derecho/spack-stack-1.6.0/envs/unified-env/install/gcc/12.2.0/parallelio-2.5.10-ysh2ljm]
--   - PIO Components Found: Fortran;C;SHARED

as well as

-- The following REQUIRED packages have been found:
...
 * PIO

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()
31 changes: 31 additions & 0 deletions src/external/SMIOL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SMIOL_C_SOURCES and SMIOLF_SOURCES don't quite follow the same naming convention. Doesn't matter too much, but it might be nice to align the two. My understanding is SMIOLF_SOURCES is meant to be effectively, <TARGET_NAME>_SOURCES and follow the Makefile target name. SMIOL_SOURCES for the C sources follows that same convention, though it does look more ambiguous than the _C_ one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean change SMIOLF_SOURCES to SMIOL_F_SOURCES?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would also work, but in keeping with the <TARGET_NAME>_SOURCES I propose SMIOL_C_SOURCES => SMIOL_SOURCES. If that's too ambiguous of a variable name, then yes exactly what you said instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to leave the explicit C naame, esp as c sources are rare.

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})

# 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 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When compiling this branch on my local machine, the build fails because the smiol target cannot find mpi.h. I attached the build log for reference.
log.make.txt
The issue is resolved by adding target_include_directories(smiol PRIVATE ${MPI_INCLUDE_PATH}) after target_compile_definitions(smiol PRIVATE SMIOL_PNETCDF SINGLE_PRECISION).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing and finding this.

# 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