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

mpi: use mpi get_accumulate as proxy for atomic add #100

Closed
wants to merge 1 commit into from

Conversation

vmiheer
Copy link
Contributor

@vmiheer vmiheer commented May 7, 2024

Partly fixes #99.
I think for other functions ideally the imples for atomic should be deleted giving compile time error message to the user of krs/mpi. But atleast it should print warnings saying the library is using non-atomic operations for now.

Get_accumulate might be slightly inefficient than just Accumulate but c++ opeartor += should return the updated value, maybe it could return "optional" value, the access to which would error out.

type &value, type &retVal, int offset, int pe, const MPI_Win &win) { \
assert(win != MPI_WIN_NULL); \
int _typesize; \
MPI_Type_size(mpi_type, &_typesize); \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not sizeof(type)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mpi_type_p(tmp, offset, pe, *win);
// forward the pinky promise of not updating "val" of mpi.
mpi_type_atomic_add(const_cast<non_const_value_type &>(val), tmp, offset,
pe, *win);
return tmp;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The value of tmp is undefined because there is no flush here. For single value operations MPI provides MPI_Fetch_and_op and it should be followed by MPI_Win_flush_local.

More generally, there is no way to hide the network latency for operators that return a result of an atomic op.

Also, you cannot guarantee that val will stay valid. If I write a += 1 then val will almost certainly break the "pinky promise" and go out of scope/get changed.

And why only implement this for operator+= and not operator*=?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay according to https://www.mpi-forum.org/docs/mpi-4.1/mpi41-report.pdf Page 577, line 47, MPI_FETCH_AND_OP is faster than GET_ACCUMULATE. I should use fetch_and_add where possible.

@vmiheer vmiheer force-pushed the vmiheer/mpi-get-accumulate branch from 56c3f9c to f385ad7 Compare May 23, 2024 05:32
@janciesko janciesko requested a review from devreal May 28, 2024 20:34
@janciesko
Copy link
Contributor

Superseded by #103

@vmiheer
Copy link
Contributor Author

vmiheer commented Jun 4, 2024

Closing.

@vmiheer vmiheer closed this Jun 4, 2024
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.

MPISpace: element operators with atomic trait aren't atomic
3 participants