Skip to content

Commit

Permalink
attempt to remove excessive allocations in updater (#736)
Browse files Browse the repository at this point in the history
updater less allocations
  • Loading branch information
PhilipDeegan authored Dec 7, 2023
1 parent dab5a77 commit 2e9c825
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/amr/multiphysics_integrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ namespace solver
{
messenger.registerLevel(hierarchy, ilvl);
}
solver.onRegrid();
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/amr/solvers/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace solver



virtual void onRegrid() {} // do what you need to do on regrid


virtual ~ISolver() = default;

Expand Down
1 change: 1 addition & 0 deletions src/amr/solvers/solver_ppc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class SolverPPC : public ISolver<AMR_Types>
double const currentTime, double const newTime) override;


void onRegrid() override { ionUpdater_.reset(); }

private:
using Messenger = amr::HybridMessenger<HybridModel>;
Expand Down
15 changes: 14 additions & 1 deletion src/core/data/particles/particle_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class ParticleArray
}

template<typename Predicate>
void export_particles(This& dest, Predicate&& pred) const
void export_particles(ParticleArray& dest, Predicate&& pred) const
{
PHARE_LOG_SCOPE("ParticleArray::export_particles (Fn,vector)");
cellMap_.export_if(particles_.data(), dest, std::forward<Predicate>(pred));
Expand Down Expand Up @@ -233,6 +233,19 @@ class ParticleArray

auto& box() const { return box_; }


auto& replace_from(ParticleArray const& that)
{
if (this == &that) // just in case
return *this;
this->resize(that.size());
std::copy(that.begin(), that.end(), this->begin());
this->box_ = that.box_;
this->cellMap_ = that.cellMap_;
return *this;
}


private:
Vector particles_;
box_t box_;
Expand Down
14 changes: 12 additions & 2 deletions src/core/numerics/ion_updater/ion_updater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,21 @@ class IonUpdater
void updateIons(Ions& ions, GridLayout const& layout);


void reset()
{
// clear memory
tmp_particles_ = std::move(ParticleArray{Box{}});
}


private:
void updateAndDepositDomain_(Ions& ions, Electromag const& em, GridLayout const& layout);

void updateAndDepositAll_(Ions& ions, Electromag const& em, GridLayout const& layout);


// dealloced on regridding/load balancing coarsest
ParticleArray tmp_particles_{Box{}}; //{std::make_unique<ParticleArray>(Box{})};
};


Expand Down Expand Up @@ -162,8 +173,7 @@ void IonUpdater<Ions, Electromag, GridLayout>::updateAndDepositDomain_(Ions& ion
// deposit moments on those which leave to go inDomainBox

auto pushAndAccumulateGhosts = [&](auto& inputArray, bool copyInDomain = false) {
auto outputArray{inputArray}; // TODO : dynamic allocation can we get rid of that
// eventually?
auto& outputArray = tmp_particles_.replace_from(inputArray);

inRange = makeIndexRange(inputArray);
outRange = makeIndexRange(outputArray);
Expand Down
6 changes: 2 additions & 4 deletions src/core/utilities/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ namespace core
return std::string{val};
return std::nullopt;
}
NO_DISCARD inline std::optional<std::string> get_env(std::string&& key)
{
return get_env(key);
}


} // namespace core
} // namespace PHARE
Expand Down Expand Up @@ -339,6 +336,7 @@ NO_DISCARD auto any(Container const& container, Fn fn = to_bool)
return std::any_of(container.begin(), container.end(), fn);
}


template<typename Container, typename Fn = decltype(to_bool)>
NO_DISCARD auto none(Container const& container, Fn fn = to_bool)
{
Expand Down

0 comments on commit 2e9c825

Please sign in to comment.