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

Multithreading safety #3

Open
Lestropie opened this issue Mar 19, 2024 · 0 comments
Open

Multithreading safety #3

Lestropie opened this issue Mar 19, 2024 · 0 comments

Comments

@Lestropie
Copy link

Hi @codeplea,

I made use of this function in the MRtrix3 software to deal with compilation on systems where our primary mathematics library dependency, Eigen, is missing the corresponding function. Its use is in converting t-values / F-values to Z-scores prior to statistical enhancement within a generalised statistical inference framework that operates on different forms of neuroimaging data.

This code was recently flagged by Thread Sanitiser. Our code generates a non-parametric null distribution by evaluating random permutations of the data across multiple threads. The issue is that std::lgamma() is not thread-safe. It evaluates the logarithm of the absolute value of the gamma function. In order to not lose information where the gamma function is negative, it stores the sign of the gamma function in a static external variable. There may be in some environments an alternative implementation lgamma_r(), which takes as a second input a pointer to an integer where that sign is instead written, which can therefore be used in a thread safe manner.

Can I suggest:

  • Explicitly test that both inputs a and b to the regularised incomplete beta function are positive (ie. I presume you're not handling analytic continuation)?
  • Add a note in the documentation about relevance of threading race conditions (ie. if I'm understanding correctly, these should be irrelevant since the inputs to std::lgamma() are always positive and therefore the sign of the gamma function is always positive)?

Cheers
Rob

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

1 participant