Skip to content

keep particle overallocation on restore state#897

Merged
PhilipDeegan merged 1 commit intoPHAREHUB:masterfrom
PhilipDeegan:alloc
Oct 3, 2024
Merged

keep particle overallocation on restore state#897
PhilipDeegan merged 1 commit intoPHAREHUB:masterfrom
PhilipDeegan:alloc

Conversation

@PhilipDeegan
Copy link
Member

@PhilipDeegan PhilipDeegan commented Oct 2, 2024

keep initial capacity during save/restore state in solver ppc

Summary by CodeRabbit

  • New Features

    • Introduced a method for efficiently adding particle data to maps, enhancing the management of particle states.
    • Improved handling of particle ranges during updates, optimizing transfers between ghost and domain arrays.
  • Bug Fixes

    • Refined logic for determining particles entering the domain from the ghost layer, improving overall efficiency.
  • Documentation

    • Updated comments for better clarity on operations related to domain and ghost particles.

@coderabbitai
Copy link

coderabbitai bot commented Oct 2, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce a new static method add_to in the SolverPPC class to facilitate adding ParticleArray objects to a map, enhancing the management of particle states during save operations. Additionally, modifications in the IonUpdater class improve the handling of particle ranges and optimize the transfer of particles between ghost and domain arrays. These updates include refining lambda functions and enhancing code comments for clarity, while maintaining the overall structure and functionality of the classes.

Changes

File Path Change Summary
src/amr/solvers/solver_ppc.hpp Added static method add_to(Map&, std::string const&, ParticleArray const&) in SolverPPC. Modified saveState_ to utilize add_to.
src/core/numerics/ion_updater/ion_updater.hpp Changed inDomainBox lambda parameter type from auto& to auto&&. Refined updateAndDepositAll_ method to improve particle transfer logic. Updated comments for clarity.

Sequence Diagram(s)

sequenceDiagram
    participant SolverPPC
    participant ParticleArray
    participant Map

    SolverPPC->>Map: add_to(key, ParticleArray)
    Map-->>SolverPPC: check if key exists
    alt Key does not exist
        Map->>Map: initialize entry with empty ParticleArray
    end
    Map->>Map: reserve capacity for new ParticleArray
    Map->>Map: replace contents with ParticleArray
    SolverPPC->>SolverPPC: saveState_ updates maps
Loading

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
src/amr/solvers/solver_ppc.hpp (2)

155-170: LGTM! Consider refining the overallocation strategy.

The new add_to method effectively preserves the overallocation of the source ParticleArray, which can be beneficial for performance. However, as the comment suggests, the optimal amount of overallocation should be assessed.

Consider implementing a more sophisticated overallocation strategy based on performance measurements. For example, you could use a factor of the original capacity:

v.reserve(static_cast<std::size_t>(ps.capacity() * 1.2)); // 20% overallocation

Alternatively, you could implement a custom growth strategy based on the specific needs of your application.


225-227: LGTM! Consider a minor optimization for key generation.

The use of the new add_to method improves code maintainability and reduces the risk of errors. Good job on this refactoring!

To potentially improve performance, consider pre-computing the base key string outside the loop:

std::string const baseKey = ss.str() + "_";
for (auto& pop : state.ions)
{
    std::string const key = baseKey + pop.name();
    add_to(tmpDomain, key, pop.domainParticles());
    add_to(patchGhost, key, pop.patchGhostParticles());
}

This avoids repeated string concatenation for each population.

src/core/numerics/ion_updater/ion_updater.hpp (1)

224-226: Prefer const auto& over auto&& in lambda parameter for clarity

In line 224, the lambda parameter in inDomainBox is declared as auto&& particleRange. Unless you need perfect forwarding or plan to accept both lvalues and rvalues, using const auto& enhances readability and ensures that particleRange is not modified within the lambda.

Apply the following change:

-        auto inDomainBox = [&domainBox](auto&& particleRange) //
+        auto inDomainBox = [&domainBox](const auto& particleRange) //
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ecef2fe and bf23dca.

📒 Files selected for processing (2)
  • src/amr/solvers/solver_ppc.hpp (2 hunks)
  • src/core/numerics/ion_updater/ion_updater.hpp (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/amr/solvers/solver_ppc.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/numerics/ion_updater/ion_updater.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
src/amr/solvers/solver_ppc.hpp (2)

155-170: LGTM! Consider adding a comment about overallocation strategy.

The add_to method effectively manages particle addition while preserving overallocation. This approach can potentially improve performance by reducing the frequency of reallocations.

Consider adding a comment explaining the rationale behind preserving overallocation and how the optimal amount of overallocation might be determined in the future. For example:

// Preserve overallocation to reduce reallocation frequency.
// TODO: Assess and optimize the overallocation strategy for best performance.

Line range hint 155-227: Overall improvement in particle management and potential performance.

The introduced changes, particularly the new add_to method and its usage in saveState_, align well with the PR objectives of limiting reallocations in the ion updater. These modifications potentially reduce MPI waits during the process of filling ion ghosts, which should enhance the efficiency of the ion updater.

The code maintains good C++ practices, improves expressiveness, and introduces a strategy for managing overallocation that can be further optimized in the future.

As the project evolves, consider the following:

  1. Implement benchmarks to measure the impact of the overallocation strategy on performance.
  2. Explore adaptive overallocation strategies that adjust based on runtime behavior.
  3. Document the overallocation approach in the project's performance optimization guide for future reference.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bf23dca and 6fca2f7.

📒 Files selected for processing (1)
  • src/amr/solvers/solver_ppc.hpp (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/amr/solvers/solver_ppc.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (1)
src/amr/solvers/solver_ppc.hpp (1)

225-227: Great refactoring! Improved code readability and potential performance.

The use of the new add_to method simplifies the saveState_ function and encapsulates the particle addition logic. This change not only improves code readability but also potentially enhances performance by leveraging the overallocation strategy.

@PhilipDeegan
Copy link
Member Author

fillIonghosts still under 2% since reverting to export particles

image

@PhilipDeegan PhilipDeegan merged commit 73a0a81 into PHAREHUB:master Oct 3, 2024
@PhilipDeegan PhilipDeegan deleted the alloc branch October 3, 2024 16:15
nicolasaunai pushed a commit to nicolasaunai/PHARE that referenced this pull request Oct 11, 2024
nicolasaunai pushed a commit to nicolasaunai/PHARE that referenced this pull request Oct 12, 2024
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Jan 6, 2025
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Jan 13, 2025
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

Successfully merging this pull request may close these issues.

2 participants