-
Notifications
You must be signed in to change notification settings - Fork 368
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
Fixed bug in parallelization in MPS simulator. #292
Conversation
…push_back. Need to use assignment instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Standard containers are no thread-safe for writing (they are for reading).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the later rush review. I'm a bit concern about the fact that our tests didn't catch this issue. Can you think of a test that would catch similar problems in the future?
Thanks!
#pragma omp parallel for | ||
#else | ||
#pragma omp parallel for collapse(2) | ||
#endif | ||
for(uint_t row = 0; row < num_rows; row++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to change the type of row
to int_t
due to incompatibilities with Windows OpenMP support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected both places as you pointed out.
It is a problem to catch failures that only happen non-deterministically. I can only suggest running the unittest a few times.
We also use another kind of testing here - we create random circuits and then compare results between the mps and the statevector. If you are interested, I can add these somewhere as well.
#pragma omp parallel for | ||
#else | ||
#pragma omp parallel for collapse(2) | ||
#endif | ||
for(uint_t row = 0; row < num_rows; row++) { | ||
for(uint_t col = 0; col < num_cols; col++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to chage this type too: uint_t col
=> int_t col
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is good to go.
Just need to add the PR number to the end of the CHANGELOG entry and I'll merge :)
CHANGELOG.md
Outdated
@@ -35,6 +35,7 @@ Removed | |||
|
|||
Fixed | |||
----- | |||
- Bug in handling parallelization in matrix_product_state.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add the number of the PR at the end of this line (see the other entries) :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right. done.
* Fixed bug in parallelization. It does not work correctly with vector push_back. Need to use assignment instead.
* Fixed bug in parallelization. It does not work correctly with vector push_back. Need to use assignment instead.
Summary
There was an "omp parallel" on a for loop that had a vector that was assigned values using push_back. That caused undeterministic behavior. Changed the push_back to assignment.
Details and comments