Skip to content

Commit

Permalink
ADIOS1: Link Serial & Parallel Separately
Browse files Browse the repository at this point in the history
CMake draft to link the `_nompi` and MPI libs of ADIOS1
separately.
  • Loading branch information
ax3l committed Jun 15, 2018
1 parent dda06b5 commit 8618b33
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 18 deletions.
116 changes: 109 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ if(openPMD_HAVE_HDF5 AND HDF5_IS_PARALLEL AND NOT openPMD_HAVE_MPI)
"to disable HDF5 or provide a serial install of HDF5.")
endif()

# external library: ADIOS1 (optional)
# always search for a sequential lib first, so we can mock MPI
find_package(ADIOS 1.13.1 COMPONENTS sequential QUIET)
set(ADIOS_DEFINITIONS_SEQUENTIAL ${ADIOS_DEFINITIONS})
set(ADIOS_LIBRARIES_SEQUENTIAL ${ADIOS_LIBRARIES})
set(ADIOS_INCLUDE_DIRS_SEQUENTIAL ${ADIOS_INCLUDE_DIRS})
unset(ADIOS_FOUND CACHE)
unset(ADIOS_VERSION CACHE)

# regular logic
set(ADIOS1_PREFER_COMPONENTS)
if(NOT openPMD_HAVE_MPI)
set(ADIOS1_PREFER_COMPONENTS sequential)
Expand Down Expand Up @@ -147,6 +155,9 @@ if(NOT openPMD_HAVE_MPI AND openPMD_HAVE_ADIOS1 AND NOT ADIOS_HAVE_SEQUENTIAL)
"Set openPMD_USE_ADIOS1=OFF to disable ADIOS1.")
endif()

message(STATUS "++++ ADIOS SEQ: ${ADIOS_LIBRARIES_SEQUENTIAL}")
message(STATUS "++++ ADIOS PAR: ${ADIOS_LIBRARIES}")

# external library: ADIOS2 (optional)
if(openPMD_USE_ADIOS2 STREQUAL AUTO)
find_package(ADIOS2 2.1.0)
Expand Down Expand Up @@ -204,10 +215,12 @@ set(IO_SOURCE
src/IO/AbstractIOHandler.cpp
src/IO/AbstractIOHandlerImpl.cpp
src/IO/IOTask.cpp
src/IO/ADIOS/ADIOS1IOHandler.cpp
src/IO/ADIOS/ParallelADIOS1IOHandler.cpp
src/IO/HDF5/HDF5IOHandler.cpp
src/IO/HDF5/ParallelHDF5IOHandler.cpp)
set(IO_ADIOS1_SEQUENTIAL_SOURCE
src/IO/ADIOS/ADIOS1IOHandler.cpp)
set(IO_ADIOS1_SOURCE
src/IO/ADIOS/ParallelADIOS1IOHandler.cpp)

# library
add_library(openPMD ${CORE_SOURCE} ${IO_SOURCE})
Expand Down Expand Up @@ -276,15 +289,95 @@ else()
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_HDF5=0")
endif()

add_library(openPMD.ADIOS1.Serial SHARED ${IO_ADIOS1_SEQUENTIAL_SOURCE})
add_library(openPMD.ADIOS1.Parallel SHARED ${IO_ADIOS1_SOURCE})
target_compile_features(openPMD.ADIOS1.Serial
PUBLIC cxx_std_11
)
target_compile_features(openPMD.ADIOS1.Parallel
PUBLIC cxx_std_11
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(openPMD.ADIOS1.Serial PUBLIC "/bigobj")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(openPMD.ADIOS1.Parallel PUBLIC "/bigobj")
endif()
if(openPMD_USE_INTERNAL_VARIANT)
target_include_directories(openPMD.ADIOS1.Serial SYSTEM PUBLIC
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/variant/include>)
else()
target_link_libraries(openPMD.ADIOS1.Serial PUBLIC mpark_variant)
endif()
if(openPMD_USE_INTERNAL_VARIANT)
target_include_directories(openPMD.ADIOS1.Parallel SYSTEM PUBLIC
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/variant/include>)
else()
target_link_libraries(openPMD.ADIOS1.Parallel PUBLIC mpark_variant)
endif()

target_include_directories(openPMD.ADIOS1.Serial SYSTEM PRIVATE
${openPMD_SOURCE_DIR}/include)
target_include_directories(openPMD.ADIOS1.Parallel SYSTEM PRIVATE
${openPMD_SOURCE_DIR}/include)

if(openPMD_HAVE_ADIOS1)
target_link_libraries(openPMD PUBLIC ${ADIOS_LIBRARIES})
target_include_directories(openPMD SYSTEM PUBLIC ${ADIOS_INCLUDE_DIRS})
set_target_properties(openPMD.ADIOS1.Serial PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
LINK_FLAGS "-Wl,--exclude-libs,ALL"
#XCODE_ATTRIBUTE_STRIP_STYLE "non-global"
#XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES"
#XCODE_ATTRIBUTE_SEPARATE_STRIP "YES"
)
foreach(adlib ${ADIOS_LIBRARIES_SEQUENTIAL})
message(STATUS "--- SEQ: ${adlib}")
target_link_libraries(openPMD.ADIOS1.Serial PRIVATE ${adlib})
endforeach()
target_include_directories(openPMD.ADIOS1.Serial SYSTEM PRIVATE ${ADIOS_INCLUDE_DIRS_SEQUENTIAL})
target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "${ADIOS_DEFINITIONS_SEQUENTIAL}")
target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "-DopenPMD_HAVE_ADIOS1=1")
#if(openPMD_HAVE_MPI)
# target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "-DopenPMD_HAVE_MPI=1")
#else()
target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "-DopenPMD_HAVE_MPI=0")
target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "-D_NOMPI=1")
#endif()

if(openPMD_HAVE_MPI)
set_target_properties(openPMD.ADIOS1.Parallel PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN 1
LINK_FLAGS "-Wl,--exclude-libs,ALL"
#XCODE_ATTRIBUTE_STRIP_STYLE "non-global"
#XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES"
#XCODE_ATTRIBUTE_SEPARATE_STRIP "YES"
)
foreach(adlib ${ADIOS_LIBRARIES})
message(STATUS "--- PAR: ${adlib}")
target_link_libraries(openPMD.ADIOS1.Parallel PRIVATE ${adlib})
endforeach()

target_include_directories(openPMD.ADIOS1.Parallel SYSTEM PRIVATE ${ADIOS_INCLUDE_DIRS})
target_compile_definitions(openPMD.ADIOS1.Parallel PRIVATE "${ADIOS_DEFINITIONS}")
target_compile_definitions(openPMD.ADIOS1.Parallel PRIVATE "-DopenPMD_HAVE_ADIOS1=1")
target_compile_definitions(openPMD.ADIOS1.Parallel PRIVATE "-DopenPMD_HAVE_MPI=1")
endif()

target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS1=1")
target_compile_definitions(openPMD PRIVATE "${ADIOS_DEFINITIONS}")
else()
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS1=0")
endif()

target_link_libraries(openPMD PRIVATE openPMD.ADIOS1.Serial)
target_link_libraries(openPMD PRIVATE openPMD.ADIOS1.Parallel)

if(openPMD_HAVE_ADIOS2)
target_link_libraries(openPMD PUBLIC ADIOS2::ADIOS2)
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS2=1")
Expand Down Expand Up @@ -486,7 +579,16 @@ write_basic_package_version_file("openPMDConfigVersion.cmake"
# Installs ####################################################################
#
# headers, libraries and exectuables
install(TARGETS openPMD EXPORT openPMDTargets
# TODO weird, clean up openPMD.ADIOS1.*
set(openPMD_lib_targets openPMD)
if(openPMD_HAVE_ADIOS1)
set(openPMD_lib_targets openPMD.ADIOS1.Serial)
if(openPMD_HAVE_MPI)
set(openPMD_lib_targets openPMD.ADIOS1.Parallel)
endif()
endif()

install(TARGETS ${openPMD_lib_targets} EXPORT openPMDTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
16 changes: 11 additions & 5 deletions include/openPMD/IO/ADIOS/ADIOS1IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@
# include <unordered_set>
#endif

#if _MSC_VER
# define EXPORT __declspec( dllexport )
#else
# define EXPORT __attribute__((visibility("default")))
#endif


namespace openPMD
{
#if openPMD_HAVE_ADIOS1
class ADIOS1IOHandler;
class EXPORT ADIOS1IOHandler;

class ADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
class EXPORT ADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
{
public:
ADIOS1IOHandlerImpl(AbstractIOHandler*);
Expand Down Expand Up @@ -86,7 +92,7 @@ class ADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
std::unordered_map< ADIOS_FILE*, std::vector< ADIOS_SELECTION* > > m_scheduledReads;
}; //ADIOS1IOHandlerImpl

class ADIOS1IOHandler : public AbstractIOHandler
class EXPORT ADIOS1IOHandler : public AbstractIOHandler
{
friend class ADIOS1IOHandlerImpl;

Expand All @@ -103,10 +109,10 @@ class ADIOS1IOHandler : public AbstractIOHandler
std::unique_ptr< ADIOS1IOHandlerImpl > m_impl;
}; //ADIOS1IOHandler
#else
class ADIOS1IOHandlerImpl
class EXPORT ADIOS1IOHandlerImpl
{ };

class ADIOS1IOHandler : public AbstractIOHandler
class EXPORT ADIOS1IOHandler : public AbstractIOHandler
{
friend class ADIOS1IOHandlerImpl;

Expand Down
16 changes: 11 additions & 5 deletions include/openPMD/IO/ADIOS/ParallelADIOS1IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@
#include <memory>
#include <string>

#if _MSC_VER
# define EXPORT __declspec( dllexport )
#else
# define EXPORT __attribute__((visibility("default")))
#endif


namespace openPMD
{
#if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI
class ParallelADIOS1IOHandler;
class EXPORT ParallelADIOS1IOHandler;

class ParallelADIOS1IOHandlerImpl : public ADIOS1IOHandlerImpl
class EXPORT ParallelADIOS1IOHandlerImpl : public ADIOS1IOHandlerImpl
{
public:
ParallelADIOS1IOHandlerImpl(AbstractIOHandler*, MPI_Comm);
Expand All @@ -54,7 +60,7 @@ class ParallelADIOS1IOHandlerImpl : public ADIOS1IOHandlerImpl
MPI_Info m_mpiInfo;
}; //ParallelADIOS1IOHandlerImpl

class ParallelADIOS1IOHandler : public AbstractIOHandler
class EXPORT ParallelADIOS1IOHandler : public AbstractIOHandler
{
friend class ParallelADIOS1IOHandlerImpl;

Expand All @@ -75,10 +81,10 @@ class ParallelADIOS1IOHandler : public AbstractIOHandler
std::unique_ptr< ParallelADIOS1IOHandlerImpl > m_impl;
}; //ParallelADIOS1IOHandler
#else
class ParallelADIOS1IOHandlerImpl
class EXPORT ParallelADIOS1IOHandlerImpl
{ };

class ParallelADIOS1IOHandler : public AbstractIOHandler
class EXPORT ParallelADIOS1IOHandler : public AbstractIOHandler
{
friend class ParallelADIOS1IOHandlerImpl;

Expand Down
2 changes: 1 addition & 1 deletion test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ TEST_CASE( "no_serial_hdf5", "[serial][hdf5]" )
REQUIRE(true);
}
#endif
#if openPMD_HAVE_ADIOS1 && !openPMD_HAVE_MPI
#if openPMD_HAVE_ADIOS1
TEST_CASE( "adios1_dtype_test", "[serial][adios1]" )
{
{
Expand Down

0 comments on commit 8618b33

Please sign in to comment.