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

WIP add task_local for duplication things for multithreading #1070

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fredrikekre
Copy link
Member

No description provided.

Base automatically changed from fe/ohmythreads to master September 26, 2024 09:54
@KnutAM
Copy link
Member

KnutAM commented Sep 26, 2024

I don't have time to look in detail, but I really like to have this interface!

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.54%. Comparing base (5153307) to head (217bae0).

Files with missing lines Patch % Lines
src/multithreading.jl 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1070      +/-   ##
==========================================
- Coverage   93.57%   93.54%   -0.04%     
==========================================
  Files          39       40       +1     
  Lines        6071     6086      +15     
==========================================
+ Hits         5681     5693      +12     
- Misses        390      393       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@termi-official termi-official left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a sane way to unit test this?

@fredrikekre
Copy link
Member Author

Thoughts on the name? task_local is OK I guess, but then it sounds like it would return something like https://github.com/vchuravy/TaskLocalValues.jl, which it doesn't (but perhaps it should?). scratch_copy?

@KnutAM
Copy link
Member

KnutAM commented Nov 8, 2024

I think having task in the name makes sense. Some suggestions are
task_copy, task_scratch, or task_local_copy

Copy link
Member

@KnutAM KnutAM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Took a bit deeper look, looks good. Docs/changelog etc of course needed as well, but still just WIP AFAIU.

Should it also be added to InterfaceValues?

src/FEValues/FunctionValues.jl Show resolved Hide resolved
Comment on lines +323 to +321
# TODO: For typical use the quadrature rule is read-only, but seems safer to copy anyway?
# And might even be beneficial with e.g. NUMA?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think the cost of copying here would always be negligible, and there is a risk when using e.g. PointValues where the quadrature point is changed!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that task_local should always be safe and that the caller is responsible to not call task_local on immutable stuff, if he does not want the duplication.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, at least in the past, it was beneficial that the thread that used the data was the one allocating it so thats why I thought maybe it is better to duplicate this too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if that is also true for constant shared memory data. I suggest that we keep the rationale in a doc string here tho, so if we revisit this we have the exact arguments at hand (and also for users).

src/multithreading.jl Outdated Show resolved Hide resolved
src/multithreading.jl Outdated Show resolved Hide resolved
test/test_multithreading.jl Outdated Show resolved Hide resolved
src/FEValues/CellValues.jl Show resolved Hide resolved
Comment on lines +323 to +321
# TODO: For typical use the quadrature rule is read-only, but seems safer to copy anyway?
# And might even be beneficial with e.g. NUMA?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that task_local should always be safe and that the caller is responsible to not call task_local on immutable stuff, if he does not want the duplication.

src/multithreading.jl Show resolved Hide resolved
src/multithreading.jl Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some code paths are not covered yet (see CodeCov result).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still.

@KristofferC
Copy link
Collaborator

FWIW, I am not 100% sold on this. What was the issue with the previous way?

Also, calling it task_local when it basically seems to create a (somewhat selective) copy feels strange to me? What's task local about that?

src/Quadrature/quadrature.jl Outdated Show resolved Hide resolved
src/FEValues/FacetValues.jl Outdated Show resolved Hide resolved
@fredrikekre
Copy link
Member Author

What was the issue with the previous way?

The issue is basically that there isn't a previous way:

  • CellValues you can copy (so you don't have to thread the quadrature and interpolation all the way into the global assembly in order to call the CellValue constructor to obtain a copy)
  • CellCache is not a problem to call the constructor for each task because the input dh should be available
  • local matrix/vector is OK to recreate with zeros or whatever
  • To get a task local assembler you have to call start_assemble(K, f; fillzero = false)... what?

The point of this PR is to get something consistent I guess. I am not really fond of the name either, but since it is typically used when you set up a new task the name "looks good", i.e.

cv = task_local(cellvalues)
Threads.@spawn assemble!( cv...)

Would a name like scratch_copy or something be better?

@termi-official
Copy link
Member

Would a name like scratch_copy or something be better?

To get the ball rolling on this, in Thunderbolt I have implemented this exact concept some time ago decided for the name duplicate_for_parallel.

@KnutAM
Copy link
Member

KnutAM commented Nov 11, 2024

copy_for_task?

IMO scratch isn't so nice since we also pass information (e.g. DofHandler in CellCache)

(But I'm also good withtask_local or task_local_copy)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants