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

ADIOS1: Link Serial & Parallel Separately #254

Merged
merged 4 commits into from
Jun 22, 2018

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Jun 13, 2018

CMake draft to link the _nompi and MPI libs of ADIOS1 separately.

Close #252

Current Status 1

It's ugly, it's verbose, it's hard to maintain, it excludes compilers that can not hide symbols such as pgc++ when building with ADIOS1, the system must have shared library support, it requires static ADIOS1 libraries (at least that's the default), ... but it works :-D

Current Status 2

It's complex but doable.

To Do

  • inline comments, clean up
  • requires serial ADIOS library? (can't test: ADIOS 1.13.1 seems just to build to static...) -> reported in 1.13.1: --enable-shared ignored? ornladios/ADIOS#185
  • FindADIOS.cmake should honor QUIET in its message()s
  • add CMake option for SHARED adios intermediate libs (default: on == MPI/Serial safe)?
  • clean up serial interface: @C0nsultant heeelp please :) Remove MPI from serial ADIOS interface #258
  • very likely needs explicit symbol (un)hiding in ADIOS translation units
  • do the same symbol linker magic on OSX
  • Win has no ADIOS1 support
  • we can not inherit, because same symbols do not mean same implementation in the end
  • objcopy --strip-symbols?
  • maybe we need to either call MPI_Initialize() (if MPI context missing) if ADIOS is build with MPI even in serial mode... or load ADIOS via dlopen to avoid symbol clashes/mismatches, etc.

@ax3l ax3l added bug third party third party libraries that are shipped and/or linked backend: ADIOS1 labels Jun 13, 2018
@ax3l ax3l force-pushed the topic-adiosSepLinking branch 7 times, most recently from 07d5824 to 86b51cf Compare June 14, 2018 12:01
CMakeLists.txt Outdated
POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
LINK_FLAGS "-Wl,--exclude-libs,libadios_nompi.a"
Copy link
Member Author

Choose a reason for hiding this comment

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

or simply -Wl,--exclude-libs,ALL

@ax3l ax3l force-pushed the topic-adiosSepLinking branch from 86b51cf to c890f77 Compare June 14, 2018 23:17
@ax3l ax3l mentioned this pull request Jun 15, 2018
CMakeLists.txt Outdated
@@ -277,10 +296,99 @@ else()
endif()

if(openPMD_HAVE_ADIOS1)
target_link_libraries(openPMD PUBLIC ${ADIOS_LIBRARIES})
target_include_directories(openPMD SYSTEM PUBLIC ${ADIOS_INCLUDE_DIRS})
add_library(openPMD.ADIOS1.Serial SHARED ${IO_ADIOS1_SEQUENTIAL_SOURCE})
Copy link
Member Author

Choose a reason for hiding this comment

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

ha, have to link this always xD

@ax3l ax3l force-pushed the topic-adiosSepLinking branch 2 times, most recently from 8618b33 to 5347c1e Compare June 15, 2018 11:59
@ax3l
Copy link
Member Author

ax3l commented Jun 15, 2018

@C0nsultant lol, I made it. That's the worst hack to isolate an upstream issue I ever did. I feel ashamed and a bit used 🤕

@ax3l ax3l force-pushed the topic-adiosSepLinking branch 2 times, most recently from 24ff86a to 33685b1 Compare June 15, 2018 12:04
@@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

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

todo: the QUIET should be honored in FindADIOS.cmake

Copy link
Member Author

Choose a reason for hiding this comment

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

done

set(ADIOS_LIBRARIES_SEQUENTIAL ${ADIOS_LIBRARIES})
set(ADIOS_INCLUDE_DIRS_SEQUENTIAL ${ADIOS_INCLUDE_DIRS})
unset(ADIOS_FOUND CACHE)
unset(ADIOS_VERSION CACHE)
Copy link
Member Author

@ax3l ax3l Jun 15, 2018

Choose a reason for hiding this comment

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

we could use this and look for the parallel component with EXACT.
but actually it's not two, totally independent backends anyway.
nevertheless, same version makes life easier.

@C0nsultant
Copy link
Member

C0nsultant commented Jun 15, 2018

@ax3l You survived the war. Undoubtedly you have witnessed the bad and the worse, but you made it to the other side. People are going to love you for it.

Great work!

CMakeLists.txt Outdated
@@ -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})
Copy link
Member

@C0nsultant C0nsultant Jun 15, 2018

Choose a reason for hiding this comment

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

Just for better understanding:
Are all 4 combinations

SER PAR
 N   N
 N   Y
 Y   N
 Y   Y

possible with this change?

Copy link
Member Author

@ax3l ax3l Jun 15, 2018

Choose a reason for hiding this comment

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

Yes indeed 💃

Even though an ADIOS install of the form

SER PAR
 N   Y

is not build by ADIOS (it always ships at least a serial lib with its lovely mock magic).

Copy link
Member

Choose a reason for hiding this comment

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

Impressive!
... and that only requires building two seperate library files by compiling with different options and linking them with tinkered symbols.

its lovely mock magic

😂

Copy link
Member Author

@ax3l ax3l Jun 15, 2018

Choose a reason for hiding this comment

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

Close: no symbol tinkering, just really aggressive symbols hiding for encapsulation 😈

And note the weird code sharing in the implementation files :-o

protected:
int64_t m_group;
std::string m_groupName;
ADIOS_READ_METHOD m_readMethod;
Copy link
Member

Choose a reason for hiding this comment

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

If we don't use that varaible for both backends anymore, we cna probably hard-code the ADIOS_READ_METHOD used in each one.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't fully get this but I guess we can do this in a follow-up as well.

Copy link
Member

Choose a reason for hiding this comment

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

The methods are initialized once per handler in init()

m_readMethod = ADIOS_READ_METHOD_BP;

/** @todo ADIOS_READ_METHOD_BP_AGGREGATE */
m_readMethod = ADIOS_READ_METHOD_BP;

With the hard separation of serial and parallel backend, we do not really need the variable any more.


#define ADIOS1IOHandlerImpl ParallelADIOS1IOHandlerImpl
#include "ADIOS1IOCommon.cpp"
#undef ADIOS1IOHandlerImpl
Copy link
Member

Choose a reason for hiding this comment

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

When you think you've seen all the ways of sharing code between classes...

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, that's my secret present for you.
did I mention it's the worst hack ever?

Copy link
Member Author

@ax3l ax3l Jun 15, 2018

Choose a reason for hiding this comment

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

Note that inheritance does not work since identical symbols do not mean identical implementation thanks to the MPI mock...

Copy link
Member Author

Choose a reason for hiding this comment

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

I could inherit from yet another baseclass though, that we then hide again in symbols and compile twice... ahhhh... it must stop.

Copy link
Member

Choose a reason for hiding this comment

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

The reason for the duplicated code is not too diffcult to understand. Just maybe replace ADIOS1IOHandlerImpl with CommonImpl in "ADIOS1IOCommon.cpp" and then do the #defines in both handlers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, thought so, too!

@ax3l ax3l mentioned this pull request Jun 15, 2018
@ax3l ax3l force-pushed the topic-adiosSepLinking branch 3 times, most recently from b336a9b to 9e13f5b Compare June 18, 2018 11:06
public:
#if openPMD_HAVE_MPI
ParallelADIOS1IOHandler(std::string const& path, AccessType, MPI_Comm);
#if openPMD_HAVE_ADIOS1 && openPMD_HAVE_MPI
Copy link
Member

Choose a reason for hiding this comment

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

This check is redundant with the # if openPMD_HAVE_MPI below.

@C0nsultant
Copy link
Member

Separating the two is probably a good thing.
Using the Impl is only the recommended way to use backends, not a constraint. I placed them in the same files up to this point since all backends implemented their own Impls.

@ax3l ax3l force-pushed the topic-adiosSepLinking branch 4 times, most recently from ba06b23 to 30ec032 Compare June 19, 2018 21:30
ax3l added 2 commits June 22, 2018 00:23
Enable serial ADIOS1 backend usage even if MPI is present.
CMake draft to link the `_nompi` and MPI libs of ADIOS1
separately.
@ax3l ax3l changed the title [WIP] ADIOS1: Link Serial & Parallel Separately ADIOS1: Link Serial & Parallel Separately Jun 21, 2018
@ax3l ax3l force-pushed the topic-adiosSepLinking branch from 30ec032 to 2e9dec8 Compare June 21, 2018 22:52
@ax3l
Copy link
Member Author

ax3l commented Jun 21, 2018

@C0nsultant I think we could merge this as well now. It's also hard to rebase if we keep this open for too long.

We can not inhertit, we need unique symbols.
@ax3l ax3l force-pushed the topic-adiosSepLinking branch from 2e9dec8 to e8c81d8 Compare June 21, 2018 22:57
CMakeLists.txt Outdated
src/IO/AbstractIOHandler.cpp
src/IO/AbstractIOHandlerImpl.cpp
src/auxiliary/Filesystem.cpp
# src/IO/IOTask.cpp
Copy link
Member

Choose a reason for hiding this comment

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

Remove if not required to build this library.

CMakeLists.txt Outdated
src/IO/AbstractIOHandler.cpp
src/IO/AbstractIOHandlerImpl.cpp
src/auxiliary/Filesystem.cpp
# src/IO/IOTask.cpp
Copy link
Member

Choose a reason for hiding this comment

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

Remove if not required to build this library.

CMakeLists.txt Outdated
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET "hidden"
Copy link
Member

@C0nsultant C0nsultant Jun 22, 2018

Choose a reason for hiding this comment

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

Is there a reasong why a string is used for CXX_VISIBILITY_PRESET here and a raw literal in openPMD.ADIOS1.Serial?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's unfortunately syntax in CMake to set -fvisibility-inlines-hidden (or equivalent)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, now I see. yes, we can skip the quotes. Updated.

@@ -107,7 +107,9 @@ if(ADIOS_FIND_COMPONENTS)
elseif(comp STREQUAL "sequential")
set(OPTLIST "${OPTLIST}s")
else()
message("ADIOS component ${COMP} is not supported. Please use fortran, readonly, or sequential")
if(NOT ADIOS_FIND_QUIETLY)
message("ADIOS component ${COMP} is not supported. Please use fortran, readonly, or sequential")
Copy link
Member

Choose a reason for hiding this comment

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

This is potentially a case where we could signal FATAL_ERROR.
The user is requesting a component we will never be able to provide.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, quite the contrary! We are inside a Find*.cmake script. The worst thing it is allowed to do is not find what is requested.

Fatal errors are controlled by setting REQUIRED in find_package or by handling the Package_FOUND variable manually.

So we are all set :-)

Copy link
Member

@C0nsultant C0nsultant left a comment

Choose a reason for hiding this comment

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

LGTM.

@ax3l ax3l force-pushed the topic-adiosSepLinking branch from e8c81d8 to e9e80a5 Compare June 22, 2018 06:18
Clean up debug messages and honor QUIET in
FindADIOS.cmake
@ax3l ax3l force-pushed the topic-adiosSepLinking branch from e9e80a5 to c54f6a1 Compare June 22, 2018 06:19
@ax3l ax3l merged commit b85a155 into openPMD:dev Jun 22, 2018
@ax3l ax3l deleted the topic-adiosSepLinking branch June 22, 2018 07:38
C0nsultant added a commit to C0nsultant/libopenPMD that referenced this pull request Aug 7, 2018
Do not flush Attribute value until termination of IOHandler. Variable
defines do not overwrite previous definitions. Only flush the very last
value as the definition.
Enable VERFIY macro for ADIOS backends (was disabled with openPMD#254).
C0nsultant added a commit to C0nsultant/libopenPMD that referenced this pull request Aug 14, 2018
Do not flush Attribute value until termination of IOHandler. Variable
defines do not overwrite previous definitions. Only flush the very last
value as the definition.
Enable VERFIY macro for ADIOS backends (was disabled with openPMD#254).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: ADIOS1 bug third party third party libraries that are shipped and/or linked
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants