Skip to content

Commit

Permalink
Merge 10d9b59 into a36239e
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Apr 23, 2021
2 parents a36239e + 10d9b59 commit fe61540
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 22 deletions.
35 changes: 35 additions & 0 deletions azure-pipelines.yml
Expand Up @@ -127,6 +127,21 @@ stages:
PYTHON2_CONSTRAINTS: " ^py-setuptools@44.1.0 ^py-pygments@2.4.2 "
CMAKE_VERSION: 3.14.2
BLT_CXX_STD: c++11

shared_py38_cmake20:
BUILD_SHARED_LIBS: ON
CMAKE_BUILD_TYPE: Debug
ENABLE_COVERAGE: OFF
ENABLE_MPI: ON
ENABLE_DOCS: ON
ENABLE_SILO: ON
ENABLE_ADIOS: OFF
ENABLE_PYTHON: ON
ENABLE_PYTHON2: OFF
PYTHON_VERSION: 3.8.9
CMAKE_VERSION: 3.20.1
BLT_CXX_STD: c++11

steps:
- checkout: self
clean: boolean
Expand Down Expand Up @@ -320,6 +335,26 @@ stages:
./conduit_example
displayName: 'Test vs Install (using-with-make)'
- script: |
################################
# using with cmake mpi example
###############################
pwd
ls -l
# find spack installed cmake
export ROOT_DIR=`pwd`
export CMAKE_BIN_DIR=`ls -d ${ROOT_DIR}/uberenv_libs/spack/opt/spack/*/*/cmake*/bin`
export PATH=${CMAKE_BIN_DIR}:$PATH
echo $PATH
which cmake
cd install/examples/conduit/using-with-cmake-mpi
mkdir _test_build
cd _test_build
cmake ../
make VERBOSE=1
mpiexec -n 1 ./conduit_mpi_example
displayName: 'Test vs Install (using-with-cmake-mpi)'
condition: eq(variables['ENABLE_MPI'], 'ON')
###############################################################################
# Ubuntu 18 build and test, using spack to build tpls
Expand Down
2 changes: 1 addition & 1 deletion hashes.txt
@@ -1 +1 @@
blt branch='develop' commit='68c98b7306e0b1f19cb383ac6af210d6f75627fc'
blt branch='develop' commit='aea5fbf046e122bd72888dad0a7f97a07b9ff08d'
24 changes: 24 additions & 0 deletions src/cmake/Setup3rdParty.cmake
Expand Up @@ -150,3 +150,27 @@ if(H5ZZFP_DIR)
message(FATAL_ERROR "H5ZZFP_DIR is set, but h5z-zfp wasn't found.")
endif()
endif()

##################################
# Export BLT Targets when needed
##################################

set(BLT_TPL_DEPS_EXPORTS)
# cmake < 3.15, we use BLT's mpi target and need to export
# it for use downstream
if( ${CMAKE_VERSION} VERSION_LESS "3.15.0" )
blt_list_append(TO BLT_TPL_DEPS_EXPORTS ELEMENTS mpi IF ENABLE_MPI)
endif()

foreach(dep ${BLT_TPL_DEPS_EXPORTS})
# If the target is EXPORTABLE, add it to the export set
get_target_property(_is_imported ${dep} IMPORTED)
if(NOT ${_is_imported})
install(TARGETS ${dep}
EXPORT conduit
DESTINATION lib)
# Namespace target to avoid conflicts
set_target_properties(${dep} PROPERTIES EXPORT_NAME conduit::blt_${dep})
endif()
endforeach()

29 changes: 21 additions & 8 deletions src/cmake/SetupBLT.cmake
Expand Up @@ -24,19 +24,32 @@ if(NOT ENABLE_FOLDERS)
endif()


################################################################
# if using newer CMake, prefer using MPI as imported targets
################################################################
if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.15.0" )
set(BLT_USE_FIND_MPI_TARGETS TRUE CACHE BOOL "")
endif()


################################################################
# init blt using BLT_SOURCE_DIR
################################################################
include(${BLT_SOURCE_DIR}/SetupBLT.cmake)

if(ENABLE_MPI)
# adjust MPI from BLT
if( ${CMAKE_VERSION} VERSION_LESS "3.15.0" )
# older cmake, we use BLT imported targets
# this is simply a target alias
blt_register_library(NAME conduit_blt_mpi_deps
LIBRARIES mpi)
else()
if(TARGET MPI::MPI_CXX)
message(STATUS "Using MPI CMake imported target: MPI::MPI_CXX")
# newer cmake we use find mpi targets directly,
# this is simply a target alias
blt_register_library(NAME conduit_blt_mpi_deps
LIBRARIES MPI::MPI_CXX)
else()
message(FATAL_ERROR "Cannot use CMake imported targets for MPI."
"(CMake > 3.15, ENABLE_MPI == ON, but "
"MPI::MPI_CXX CMake target is missing.)")
endif()
endif()
endif()

################################################################
# apply folders to a few ungrouped blt targets
Expand Down
2 changes: 1 addition & 1 deletion src/cmake/SetupTests.cmake
Expand Up @@ -64,7 +64,7 @@ function(add_cpp_mpi_test)
blt_add_executable( NAME ${args_TEST}
SOURCES ${args_TEST}.cpp ${args_SOURCES}
OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS_ON "${args_DEPENDS_ON}" gtest mpi)
DEPENDS_ON "${args_DEPENDS_ON}" gtest conduit_blt_mpi_deps)

blt_add_test( NAME ${args_TEST}
COMMAND ${args_TEST}
Expand Down
1 change: 1 addition & 0 deletions src/examples/CMakeLists.txt
Expand Up @@ -12,6 +12,7 @@ add_subdirectory(staging)

# install using and python examples
install(DIRECTORY using-with-cmake
using-with-cmake-mpi
using-with-make
python
cpp_fort_and_py
Expand Down
106 changes: 106 additions & 0 deletions src/examples/using-with-cmake-mpi/CMakeLists.txt
@@ -0,0 +1,106 @@
# Copyright (c) Lawrence Livermore National Security, LLC and other Conduit
# Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
# other details. No copyright assignment is required to contribute to Conduit.
###############################################################################
#
# Example that shows how to use an installed instance of Conduit in another
# CMake-based build system.
#
# To build:
# mkdir build
# cd build
# cmake -DCONDUIT_DIR={conduit install path} ../
# make
# ./conduit_example
#
#
# If run in sub directory of a conduit install,
# CONDUIT_DIR will default to ../../..
#
# mkdir build
# cd build
# cmake ..
# make
# ./conduit_example
#
###############################################################################

cmake_minimum_required(VERSION 3.0)

project(using_with_cmake)


################################################################
# Option 1: import conduit using an explicit path (recommended)
################################################################

#
# Provide default CONDUIT_DIR that works in a conduit install
#
if(NOT CONDUIT_DIR)
set(CONDUIT_DIR "../../..")
endif()

#
# Check for valid conduit install
#

# if given relative path, resolve
get_filename_component(CONDUIT_DIR ${CONDUIT_DIR} ABSOLUTE)
# check for expected cmake exported target files
if(NOT EXISTS ${CONDUIT_DIR}/lib/cmake/conduit/ConduitConfig.cmake)
# also allow old style, but if neither case is found display error msg
if(NOT EXISTS ${CONDUIT_DIR}/lib/cmake/ConduitConfig.cmake)
MESSAGE(FATAL_ERROR "Could not find Conduit CMake include file (${CONDUIT_DIR}/lib/cmake/conduit/ConduitConfig.cmake)")
endif()
endif()

#
# Use CMake's find_package to import conduit's targets
# using explicit path
#
find_package(Conduit REQUIRED
NO_DEFAULT_PATH
PATHS ${CONDUIT_DIR}/lib/cmake/conduit)

# make sure we have mpi, since we are going to use
# conduits mpi features
if(NOT MPI_FOUND)
find_package(MPI COMPONENTS CXX)
endif()


################################################################
# Option 2: import conduit using find_package search
################################################################
##
## Add Conduit's install path to CMAKE_PREFIX_PATH
## and use following find_package call to import conduit's targets
##
#
# find_package(Conduit REQUIRED)
#


######
# If Conduit was built with c++11 support, make sure we enable it
######
if(CONDUIT_USE_CXX11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

#######################################################
# create our example
#######################################################
add_executable(conduit_mpi_example conduit_mpi_example.cpp)

# link to conduit targets
target_link_libraries(conduit_mpi_example conduit::conduit
conduit::conduit_mpi
MPI::MPI_CXX)

# if you are using conduit's python CAPI capsule interface
# target_link_libraries(conduit_example conduit::conduit_python)


44 changes: 44 additions & 0 deletions src/examples/using-with-cmake-mpi/conduit_mpi_example.cpp
@@ -0,0 +1,44 @@
// Copyright (c) Lawrence Livermore National Security, LLC and other Conduit
// Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
// other details. No copyright assignment is required to contribute to Conduit.

//-----------------------------------------------------------------------------
///
/// file: conduit_mpi_example.cpp
///
//-----------------------------------------------------------------------------

#include <iostream>

#include "conduit.hpp"
#include "conduit_relay.hpp"
#include "conduit_relay_mpi.hpp"
#include "conduit_relay_mpi_io.hpp"
#include "conduit_blueprint.hpp"
#include "conduit_blueprint_mpi.hpp"


int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);

//much ado about `about`

conduit::Node about;
conduit::about(about["conduit"]);
conduit::relay::about(about["conduit/relay"]);
conduit::relay::io::about(about["conduit/relay/io"]);
conduit::blueprint::about(about["conduit/blueprint"]);

conduit::Node about_mpi;
conduit::relay::mpi::about(about_mpi["conduit/relay/mpi"]);
conduit::relay::mpi::io::about(about_mpi["conduit/relay/mpi/io"],MPI_COMM_WORLD);
conduit::blueprint::mpi::about(about_mpi["conduit/blueprint/mpi"]);

std::cout << about.to_yaml() << std::endl;
std::cout << about_mpi.to_yaml() << std::endl;

MPI_Finalize();
}


3 changes: 3 additions & 0 deletions src/examples/using-with-cmake/CMakeLists.txt
Expand Up @@ -97,6 +97,9 @@ target_link_libraries(conduit_example conduit::conduit)


# if you are using conduit's mpi features
# if(IF NOT MPI_FOUND)
# find_package(MPI COMPONENTS CXX)
# endif()
# target_link_libraries(conduit_example conduit::conduit_mpi)


5 changes: 4 additions & 1 deletion src/libs/blueprint/CMakeLists.txt
Expand Up @@ -169,7 +169,10 @@ ${CMAKE_CURRENT_BINARY_DIR}/conduit_blueprint_exports.h)
#
# Specify blueprint mpi deps
#
set(conduit_blueprint_mpi_deps conduit conduit_blueprint mpi conduit_relay_mpi)
set(conduit_blueprint_mpi_deps conduit
conduit_blt_mpi_deps
conduit_blueprint
conduit_relay_mpi)

#
# setup conduit blueprint mpi lib
Expand Down
10 changes: 7 additions & 3 deletions src/libs/relay/CMakeLists.txt
Expand Up @@ -171,7 +171,7 @@ endif()
if(HDF5_FOUND)
list(APPEND conduit_relay_deps hdf5)
if(HDF5_IS_PARALLEL)
list(APPEND conduit_relay_deps mpi)
list(APPEND conduit_relay_deps conduit_blt_mpi_deps)
endif()
endif()

Expand Down Expand Up @@ -305,7 +305,8 @@ set(conduit_relay_mpi_sources conduit_relay_mpi.cpp)
#
# Specify the relay mpi deps
#
set(conduit_relay_mpi_deps conduit mpi)
set(conduit_relay_mpi_deps conduit
conduit_blt_mpi_deps)

#
# setup conduit relay mpi lib
Expand Down Expand Up @@ -341,7 +342,10 @@ set(conduit_relay_mpi_io_headers conduit_relay_mpi_io.hpp)
#
# Specify the relay mpi io deps
#
set(conduit_relay_mpi_io_deps conduit mpi conduit_relay_mpi conduit_relay)
set(conduit_relay_mpi_io_deps conduit
conduit_blt_mpi_deps
conduit_relay_mpi
conduit_relay)

#
# Specify relay mpi c headers
Expand Down
6 changes: 2 additions & 4 deletions src/tests/blueprint/CMakeLists.txt
Expand Up @@ -63,15 +63,13 @@ set(BLUEPRINT_RELAY_MPI_TESTS t_blueprint_mpi_mesh_relay)
if(MPI_FOUND)
message(STATUS "MPI enabled: Adding conduit_blueprint_mpi and conduit_relay_mpi unit tests")
foreach(TEST ${BLUEPRINT_MPI_TESTS})
add_cpp_mpi_test(TEST ${TEST} NUM_MPI_TASKS 2 DEPENDS_ON mpi
conduit
add_cpp_mpi_test(TEST ${TEST} NUM_MPI_TASKS 2 DEPENDS_ON conduit
conduit_blueprint_mpi)
endforeach()

message(STATUS "MPI enabled: Adding conduit_blueprint_mpi and conduit_relay_mpi unit tests")
foreach(TEST ${BLUEPRINT_RELAY_MPI_TESTS})
add_cpp_mpi_test(TEST ${TEST} NUM_MPI_TASKS 2 DEPENDS_ON mpi
conduit
add_cpp_mpi_test(TEST ${TEST} NUM_MPI_TASKS 2 DEPENDS_ON conduit
conduit_blueprint
conduit_blueprint_mpi
conduit_relay
Expand Down
6 changes: 3 additions & 3 deletions src/tests/thirdparty/CMakeLists.txt
Expand Up @@ -62,7 +62,7 @@ endif()
if(HDF5_FOUND)
message(STATUS "HDF5 enabled: Adding related unit tests")
if(HDF5_IS_PARALLEL)
set(HDF5_MPI_DEP mpi)
set(HDF5_MPI_DEP conduit_blt_mpi_deps)
endif()
add_cpp_test(TEST t_hdf5_smoke
DEPENDS_ON hdf5 ${HDF5_MPI_DEP}
Expand All @@ -74,7 +74,7 @@ endif()

if(SILO_FOUND)
if(HDF5_FOUND AND HDF5_IS_PARALLEL)
set(SILO_HDF5_MPI_DEP mpi)
set(SILO_HDF5_MPI_DEP conduit_blt_mpi_deps)
endif()
message(STATUS "Silo enabled: Adding related unit tests")
add_cpp_test(TEST t_silo_smoke
Expand Down Expand Up @@ -117,7 +117,7 @@ endif()
if(H5ZZFP_FOUND)
message(STATUS "h5z-zfp enabled: Adding related unit tests")
if(HDF5_IS_PARALLEL)
set(H5ZZFP_MPI_DEP mpi)
set(H5ZZFP_MPI_DEP conduit_blt_mpi_deps)
endif()
add_cpp_test(TEST t_h5z_zfp_smoke
DEPENDS_ON h5zzfp zfp hdf5 ${H5ZZFP_MPI_DEP}
Expand Down

0 comments on commit fe61540

Please sign in to comment.