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
Access to FE* restriction and prolongation matrices is not thread-safe. #16169
Comments
I would be curious on the performance implications of this. Grasping at least a traditional mutex can be quite expensive, especially since we pay the cost also when not using threads. |
In practice, of course, the lock will rarely be contested. And the use of shared mutices will make the contested case even less likely. The question then is how expensive the situation really is. I don't have any experience with this -- do you know? My understanding was always that getting a non-contested mutex is actually quite cheap, but that may not actually be true. |
Wouldn't it be better to redesign the algorithm and use |
As for using a shared mutex: Out of curiosity I have adapted the following cppreference example and looked at the assembly:
The
And the function in question has to do at least one In contrast, this here:
reduces to a single call:
which looks significantly less scary (again - provided I was able to trace everything correctly):
|
Yes, Alternatively, we could decide that we want to build these objects unconditionally, every time. We could do that in the background, if we wanted, but these matrices are not cheap to build so I'm hesitant to do that because they are not used by all codes. |
@bangerth @kronbichler If this is of greater utility we could write a small wrapper class around
This has several advantages:
|
@masterleinad Please give me 24h to implement the little helper struct outlined above :-) |
@tamiko I don't think you need the |
@bangerth The |
On second look, it isn't just |
@bangerth I plan to clean this up by wrapping Lazy around the prolongation and restriction matrices in the FiniteElement base class. This will require to fix all other places at the same time. Incidentally, I will also make the logic whether we have prolongation matrices more explicit via |
Excellent! |
This is a duplicate of #331. Let's close this one given that it has accumulated a bunch of other things that are difficult to read through when just looking for the original issue. |
The two functions accessing these matrices look like this:
But a poorly timed access might read the initial
if
astrue
while the matrix in question isn't completely moved yet. We need to protect thereturn
statement outside theif
as well with the mutex. That is best achieved with a shared mutex as mentioned in #16168 .EDIT: On closer look, pretty much all of the FE classes have this same idiom. They all need to be fixed.
The text was updated successfully, but these errors were encountered: