PHAREHUB / PHARE

💫 Parallel Hybrid Particle In Cell code with Adaptive mesh REfinement
https://phare.readthedocs.io
GNU General Public License v3.0
71 stars 24 forks source link

minimize save/restore allocations #909

Open PhilipDeegan opened 1 month ago

PhilipDeegan commented 1 month ago

master 800**2 harris for 10 timesteps

perf stat mpirun -n 8 python3 -Ou harris.py

t =  0.01000  -  3.09741sec  - total   3.097sec
t =  0.02000  -  4.06846sec  - total   7.166sec
t =  0.03000  -  3.59235sec  - total   10.76sec
t =  0.04000  -  3.61215sec  - total   14.37sec
t =  0.05000  -  3.54478sec  - total   17.92sec
t =  0.06000  -  3.65917sec  - total   21.57sec
t =  0.07000  -  3.52980sec  - total    25.1sec
t =  0.08000  -  3.47992sec  - total   28.58sec
t =  0.09000  -  3.50010sec  - total   32.08sec
t =  0.10000  -  3.49883sec  - total   35.58sec
mean advance time = 3.558296871185303
total advance time = 0:00:35.582969

 Performance counter stats for 'mpirun -n 8 python3 -Ou ../master/harris.py':

        306,346.10 msec task-clock                       #    7.727 CPUs utilized             
            16,856      context-switches                 #   55.023 /sec                      
             1,358      cpu-migrations                   #    4.433 /sec                      
        13,233,048      page-faults                      #   43.196 K/sec                     
   477,533,241,846      cycles                           #    1.559 GHz                       
    64,904,175,940      stalled-cycles-frontend          #   13.59% frontend cycles idle      
   947,676,761,783      instructions                     #    1.98  insn per cycle            
                                                  #    0.07  stalled cycles per insn   
    71,270,615,978      branches                         #  232.647 M/sec                     
     2,456,773,652      branch-misses                    #    3.45% of all branches           

      39.645463201 seconds time elapsed

     252.248087000 seconds user
      50.480167000 seconds sys

vs this PR

t =  0.01000  -  2.64360sec  - total   2.644sec
t =  0.02000  -  3.08067sec  - total   5.724sec
t =  0.03000  -  3.15369sec  - total   8.878sec
t =  0.04000  -  3.11711sec  - total    12.0sec
t =  0.05000  -  3.12012sec  - total   15.12sec
t =  0.06000  -  3.06334sec  - total   18.18sec
t =  0.07000  -  3.08013sec  - total   21.26sec
t =  0.08000  -  3.48485sec  - total   24.74sec
t =  0.09000  -  3.90359sec  - total   28.65sec
t =  0.10000  -  3.10904sec  - total   31.76sec
mean advance time = 3.17561354637146
total advance time = 0:00:31.756135

 Performance counter stats for 'mpirun -n 8 python3 -Ou harris.py':

        276,932.89 msec task-clock                       #    7.702 CPUs utilized             
            18,070      context-switches                 #   65.250 /sec                      
             1,410      cpu-migrations                   #    5.091 /sec                      
         4,189,838      page-faults                      #   15.129 K/sec                     
   403,919,758,323      cycles                           #    1.459 GHz                       
    33,425,036,082      stalled-cycles-frontend          #    8.28% frontend cycles idle      
   839,432,838,228      instructions                     #    2.08  insn per cycle            
                                                  #    0.04  stalled cycles per insn   
    50,362,453,610      branches                         #  181.858 M/sec                     
     1,155,931,187      branch-misses                    #    2.30% of all branches           

      35.956348966 seconds time elapsed

     258.903196000 seconds user
      14.351512000 seconds sys

Summary by CodeRabbit

coderabbitai[bot] commented 1 month ago
📝 Walkthrough
📝 Walkthrough ## Walkthrough The pull request introduces several modifications across multiple files, primarily focusing on enhancing the `SolverPPC` and `ParticleArray` classes. Key changes include the addition of new structures and functions, updates to method signatures for improved const correctness, and the introduction of default parameters in constructors. Additionally, a new utility struct for managing vectors is added, along with new functions for usability checks in the `PHARE::core` namespace. ## Changes | File Path | Change Summary | |---------------------------------------------|----------------------------------------------------------------------------------------------------| | `src/amr/solvers/solver_ppc.hpp` | - Updated `saveState_` method signature to accept const references.
- Introduced `SaveState` struct.
- Refactored `saveState_` and `restoreState_` methods. | | `src/core/data/particles/particle_array.hpp` | - Updated `ParticleArray` constructor to have default parameters.
- Added `data()` methods for accessing particle data.
- Introduced overload for `replace_from` method. | | `src/core/def.hpp` | - Added `isUsable` and `isSettable` functions with `[[nodiscard]]` attribute. | | `src/core/utilities/cellmap.hpp` | - Updated `CellMap` constructor to have a default argument for `box`. | | `src/core/vector.hpp` | - Introduced `MinimizingVector` struct for managing dynamic vectors. | ## Possibly related PRs - **#897**: The changes in this PR involve modifications to the `SolverPPC` class, specifically updating the `saveState_` method, which is also a focus of the main PR. Both PRs are related through their alterations to the `saveState_` method and the management of particle states. ## Suggested reviewers - nicolasaunai - rochSmets

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
PhilipDeegan commented 1 month ago

experimental