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

bindings: Help C++11 clients avoid calling serial constructor with MPI_Comm #2434

Merged
merged 2 commits into from
Aug 18, 2020

Conversation

bradking
Copy link
Collaborator

Client code that does not enable ADIOS2_USE_MPI may accidentally try to pass a MPI_Comm instance to our constructor. If the type the MPI library uses to implement MPI_Comm happens to be convertible to one of the types offered by our serial constructors (e.g. bool), the invocation will appear to succeed but will ignore the communicator passed. Add explicitly deleted constructors that have better conversions for common MPI_Comm types.

With this, an attempt in client code to call the adios2::ADIOS constructor with a MPI_Comm object will fail to compile with an error such as:

error: use of deleted function 'adios2::ADIOS::ADIOS(void*)'
    adios2::ADIOS adios(comm);
...note: declared here
    ADIOS(void *define_ADIOS2_USE_MPI_to_use_MPI_constructor) = delete;
    ^~~~~

…I_Comm

Client code that does not enable `ADIOS2_USE_MPI` may accidentally try to pass
a `MPI_Comm` instance to our constructor.  If the type the MPI library uses to
implement MPI_Comm happens to be convertible to one of the types offered by our
serial constructors (e.g. `bool`), the invocation will appear to succeed but
will ignore the communicator passed.  Add explicitly deleted constructors that
have better conversions for common `MPI_Comm` types.

With this, an attempt in client code to call the `adios2::ADIOS` constructor
with a `MPI_Comm` object will fail to compile with an error such as:

    error: use of deleted function 'adios2::ADIOS::ADIOS(void*)'
        adios2::ADIOS adios(comm);
    ...note: declared here
        ADIOS(void *define_ADIOS2_USE_MPI_to_use_MPI_constructor) = delete;
        ^~~~~
@bradking
Copy link
Collaborator Author

For reference, this came up in #2420 (comment).

Copy link
Contributor

@chuckatkins chuckatkins left a comment

Choose a reason for hiding this comment

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

I support this; it's very helpful to have to avoid user errors I think. Can you also add it to the open call in bindings/CXX11/adios2/cxx11/IO.h thugh?

Copy link
Contributor

@williamfgc williamfgc left a comment

Choose a reason for hiding this comment

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

@bradking would a explicit constructor be more effective than deleting implicit constructors?

@bradking
Copy link
Collaborator Author

It's not needed for IO::Open because there are no serial overloads that will be selected by passing a MPI_Comm incorrectly. When passed, the communicator is always the third argument, so it should already be a compile error if -DADIOS2_USE_MPI is not enabled.

@bradking
Copy link
Collaborator Author

would a explicit constructor be more effective than deleting implicit constructors?

No. An explicit constructor only prevents implicit calls to that constructor. In this case the call sites are already calling the constructor explicitly. The undesired conversion is taking place in the overload selection of that explicit call.

@williamfgc
Copy link
Contributor

@bradking I see, makes sense. Thanks for the explanation. A minor thing, should this be put in the core:: namespace? That way it propagates to the Python bindings, but I'm not sure if we'd see something similar with Python. Otherwise, it looks good. Thanks! The main issue is that this was failing silently.

@williamfgc
Copy link
Contributor

Just pickin' your brains @bradking and @chuckatkins , is non-target legacy CMake going to have its Python 2 moment?

@bradking
Copy link
Collaborator Author

should this be put in the core:: namespace?

The core::ADIOS constructors are agnostic and take only the helper::Comm abstraction, so this problem cannot occur internally. #2238 already took care of a similar public-facing case for the Python bindings.

@chuckatkins chuckatkins merged commit 3ee00ea into ornladios:master Aug 18, 2020
@bradking bradking deleted the mpi-constructor-delete branch August 18, 2020 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants