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

Find max value in parallel safely #953

Merged
merged 8 commits into from
Mar 3, 2025
Merged

Conversation

jhdark
Copy link
Collaborator

@jhdark jhdark commented Feb 26, 2025

Proposed changes

fix for #900

use MPI to find max value

Types of changes

What types of changes does your code introduce to FESTIM?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactoring
  • Documentation Update (if none of the other choices apply)
  • New tests

Checklist

  • Black formatted
  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.14%. Comparing base (01ab7f9) to head (582c304).
Report is 48 commits behind head on fenicsx.

Additional details and impacted files
@@             Coverage Diff             @@
##           fenicsx     #953      +/-   ##
===========================================
+ Coverage    96.02%   96.14%   +0.12%     
===========================================
  Files           45       46       +1     
  Lines         2490     2571      +81     
===========================================
+ Hits          2391     2472      +81     
  Misses          99       99              

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

@RemDelaporteMathurin RemDelaporteMathurin added the enhancement New feature or request label Feb 27, 2025
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

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

I guess we'll need this for maxinum surface, minimum surface, and minimum volume too

Comment on lines 30 to 31
max_value = max(self.field.solution.x.array[indices])
MPI.COMM_WORLD.barrier()
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. I believe we still want to use numpy.max instead of native max here for performance purposes, no?
  2. what does barrier() do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. Yes sorry, I had just copied an example I had found. Now just using numpy within the `allreduce' function instead

  2. It seems the barrier function forces all processes to reach the barrier before any of them can continue execution, however for this case it may not be necessary as all the processors will be following the same logical flow. Do you have any thoughts on this @jorgensd ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Plus shouldn't it be solution.function_space.mesh.comm.barrier() instead of comm world?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess so

@RemDelaporteMathurin RemDelaporteMathurin added the fenicsx Issue that is related to the fenicsx support label Feb 27, 2025
Copy link
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

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

LGTM, @jorgensd do you know if the barrier call is required?

@jorgensd
Copy link
Collaborator

jorgensd commented Mar 3, 2025

LGTM, @jorgensd do you know if the barrier call is required?

You do not need the barrier as you are using all reduce.

a barrier would be necessary if say only one process does something (or a subset), and the others have to wait for them to finish. I almost exclusively use this whenever I create meshes with gmsh, but not very often otherwise.
It can at times be useful when profiling code as well, to ensure that timings are started in a synchronized fashion

@jhdark jhdark merged commit cb4d84d into festim-dev:fenicsx Mar 3, 2025
9 checks passed
@jhdark jhdark deleted the np-max_update branch March 3, 2025 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fenicsx Issue that is related to the fenicsx support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants