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

(potential?) data-races #1255

Closed
KrisThielemans opened this issue Sep 17, 2023 · 3 comments
Closed

(potential?) data-races #1255

KrisThielemans opened this issue Sep 17, 2023 · 3 comments

Comments

@KrisThielemans
Copy link
Collaborator

KrisThielemans commented Sep 17, 2023

Running Intel Inspector (with the Intel compiler) gives me a few data-races. Of course, I'm not sure if these are false positives or not

when checking internal ProjDataInfo data-structures were initialised

#pragma omp atomic read
initialised = uncompressed_view_tangpos_to_det1det2_initialised;

conflicts with
uncompressed_view_tangpos_to_det1det2_initialised = true;

(and equivalent for Generic).

This implementation of the Double-Checked-Locking(DCL) pattern was suggested at http://stackoverflow.com/questions/27975737/how-to-handle-cached-data-structures-with-multi-threading-e-g-openmp.
I see that I didn't use the atomic write in the .cxx [Edit: this is now fixed by #1256], but adding that doesn't seem to make Intel Inspector happy.

I can make these disappear by initialising these tables in the constructor, i.e. commenting out lines like

//this->initialise_uncompressed_view_tangpos_to_det1det2();
//this->initialise_det1det2_to_uncompressed_view_tangpos();

However, that causes a slow-down as these tables take a while to construct. For example,

time ./run_test_simulate_and_recon.sh

before

real    0m23.021s
user    4m12.391s
sys     0m2.925s

after

real    0m33.966s
user    4m39.860s
sys     0m10.009s

detector position access in `DetectorCoordinateMap::get_coordinate_for_det_pos`

coord.x() += static_cast<float>(distribution(generator));
coord.y() += static_cast<float>(distribution(generator));
coord.z() += static_cast<float>(distribution(generator));

conflicts with some internal randoms stuff.

This will be because std random generators are not thread-safe.
I think we need one generator per thread (probably a vector of size get_max_num_threads(). @markus-jehl feel like looking at that one?

@KrisThielemans KrisThielemans changed the title (potential? data-races (potential?) data-races Sep 17, 2023
KrisThielemans added a commit to KrisThielemans/STIR-1 that referenced this issue Sep 17, 2023
Add missing `atomic write` statements. It might not resolve all problems
though, see UCL#1255.

Also add an optional compilation variable to guarantee thread-safe
operations, but it is slow.
@markus-jehl
Copy link
Contributor

sure, I'll put the second one on my list

@markus-jehl
Copy link
Contributor

@KrisThielemans : can this be closed?

@KrisThielemans
Copy link
Collaborator Author

I haven't re-run Intel inspector, but as we are not experiencing any problems, I agree we concluse this now.

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

No branches or pull requests

2 participants