lsvec Shared Memory Race Condition
#674
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patches another shared memory bug in
lsvec, this time a race condition. The bug is easiest explained by pointing at the relevant lines. Below is the implementation oflsvecforTimeIndependentMDCObjectiveFunction:The bug arises due to the interation of the positivity check
if _np.any(lsvec < 0)and later on the update oflsvecusing theraw_objfnsignslsvec[:self.nelements][raw_lsvec < 0] *= -1. Since the positivity check is happening on all ranks, but is with respect to shared memory, if a rank that is the shared memory leader hits and runs that sign update line before another rank looking at the same memory hits the positivity check this would raise an error.After staring at this code for a bit I couldn't see any reason why this positivity check (or anything else in this function) should be happening on anything other the shared memory leader, so the patch is to just add a corresponding if statement which enforces that.
Thanks to @juangmendoza19 for reporting this error.
God I hate shared memory sometimes...