Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Jan 16, 2024
1 parent d10715f commit c42b4cd
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef PHARE_CONCRERTE_LOAD_BALANCER_HYBRID_STRATEGY_HOMOGENEOUS_HPP
#define PHARE_CONCRERTE_LOAD_BALANCER_HYBRID_STRATEGY_HOMOGENEOUS_HPP

#include <SAMRAI/hier/PatchLevel.h>

#include <SAMRAI/pdat/CellData.h>
#include <string>

Expand All @@ -24,14 +24,16 @@ class ConcreteLoadBalancerHybridStrategyHomogeneous : public LoadBalancerHybridS
public:
using HybridModel = typename PHARE_T::HybridModel_t;
using gridlayout_type = typename HybridModel::gridlayout_type;
using amr_types = typename HybridModel::amr_types;
using level_t = typename amr_types::level_t;
using cell_data_t = SAMRAI::pdat::CellData<double>;

ConcreteLoadBalancerHybridStrategyHomogeneous(int const id)
: id_{id}
{
}

void compute(SAMRAI::hier::PatchLevel& level,
PHARE::solver::IPhysicalModel<SAMRAI_Types>& model) override;
void compute(level_t& level, PHARE::solver::IPhysicalModel<amr_types>& model) override;


private:
Expand All @@ -42,27 +44,25 @@ class ConcreteLoadBalancerHybridStrategyHomogeneous : public LoadBalancerHybridS

template<typename PHARE_T>
void ConcreteLoadBalancerHybridStrategyHomogeneous<PHARE_T>::compute(
SAMRAI::hier::PatchLevel& level, PHARE::solver::IPhysicalModel<SAMRAI_Types>& model)
level_t& level, PHARE::solver::IPhysicalModel<amr_types>& model)
{
static auto constexpr dimension = HybridModel::dimension;
auto& hybridModel = dynamic_cast<HybridModel&>(model);
auto& resourcesManager = hybridModel.resourcesManager;
auto& ions = hybridModel.state.ions;
auto static constexpr dimension = HybridModel::dimension;
bool static constexpr c_ordering = false;

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable c_ordering is not used.

bool constexpr c_ordering = false;
auto& hybridModel = dynamic_cast<HybridModel&>(model);
auto& resourcesManager = hybridModel.resourcesManager;
auto& ions = hybridModel.state.ions;

for (auto& patch : level)
{
auto const& layout = layoutFromPatch<gridlayout_type>(*patch);

auto patch_data_lb
= dynamic_cast<SAMRAI::pdat::CellData<double>*>(patch->getPatchData(this->id_).get());
auto patch_data_lb = dynamic_cast<cell_data_t*>(patch->getPatchData(this->id_).get());
auto load_balancer_val = patch_data_lb->getPointer();

const auto& box = patch->getBox();
auto const& box = patch->getBox();

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable box is not used.

auto lb_view = core::NdArrayView<dimension, double, double*, c_ordering>(load_balancer_val,
layout.nbrCells());
auto lb_view = core::make_array_view<c_ordering>(load_balancer_val, layout.nbrCells());

auto _ = resourcesManager->setOnPatch(*patch, ions);

Expand All @@ -73,64 +73,17 @@ void ConcreteLoadBalancerHybridStrategyHomogeneous<PHARE_T>::compute(
// to get the AMRLocatStart and AMRLocalEnd.
// Then, we build "by hand" the local index for the "lb_view" considering that the nbr
// of ghost cell for this patch data is null.
auto amr_box = layout.AMRBox();
auto const amr_box = layout.AMRBox();

// The lb_view is a CellData, meaning that it is dual as the index of an amr box
auto amr_start = amr_box.lower;
auto amr_end = amr_box.upper;

// nbr of cells in the physical domain
auto nbrCells = layout.nbrCells();




if constexpr (dimension == 1)
{
for (auto i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr)
{
auto amr_point{core::Point{i_amr}};
auto amr_index = amr_point.template toArray<int>();

lb_view(i_loc) = 1;
}
}



if constexpr (dimension == 2)
{
for (auto i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr)
{
for (auto j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr)
{
auto amr_point{core::Point{i_amr, j_amr}};
auto amr_index = amr_point.template toArray<int>();

lb_view(i_loc, j_loc) = 1;
std::cout << lb_view(i_loc, j_loc) << std::endl;
}
}
}


if constexpr (dimension == 3)
{
for (auto i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr)
{
for (auto j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr)
{
for (auto k_loc = 0, k_amr = amr_start[2]; k_loc < nbrCells[2];
++k_loc, ++k_amr)
{
auto amr_point{core::Point{i_amr, j_amr, k_amr}};
auto amr_index = amr_point.template toArray<int>();
core::Box<std::uint32_t, dimension> local_box{
core::Point{core::ConstArray<std::uint32_t, dimension>()},
core::Point{
core::generate([](auto const& nCell) { return nCell - 1; }, layout.nbrCells())}};

lb_view(i_loc, j_loc, k_loc) = 1;
}
}
}
}
for (auto const& idx : local_box)
lb_view(idx) = 1;
}
}

Expand Down
119 changes: 27 additions & 92 deletions src/amr/load_balancing/concrete_load_balancer_hybrid_strategy_nppc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

#include <string>

#include "core/logger.hpp"
#include "core/utilities/types.hpp"
#include "core/data/ndarray/ndarray_vector.hpp"

#include "amr/types/amr_types.hpp"
#include "amr/load_balancing/load_balancer_hybrid_strategy.hpp"
#include "amr/physical_models/physical_model.hpp"
#include "amr/types/amr_types.hpp"
#include "amr/resources_manager/amr_utils.hpp"
#include "core/data/ndarray/ndarray_vector.hpp"



Expand All @@ -25,14 +28,16 @@ class ConcreteLoadBalancerHybridStrategyNPPC : public LoadBalancerHybridStrategy
public:
using HybridModel = typename PHARE_T::HybridModel_t;
using gridlayout_type = typename HybridModel::gridlayout_type;
using amr_types = typename HybridModel::amr_types;
using level_t = typename amr_types::level_t;
using cell_data_t = SAMRAI::pdat::CellData<double>;

ConcreteLoadBalancerHybridStrategyNPPC(int const id)
: id_{id}
{
}

void compute(SAMRAI::hier::PatchLevel& level,
PHARE::solver::IPhysicalModel<SAMRAI_Types>& model) override;
void compute(level_t& level, PHARE::solver::IPhysicalModel<amr_types>& model) override;


private:
Expand All @@ -43,7 +48,7 @@ class ConcreteLoadBalancerHybridStrategyNPPC : public LoadBalancerHybridStrategy

template<typename PHARE_T>
void ConcreteLoadBalancerHybridStrategyNPPC<PHARE_T>::compute(
SAMRAI::hier::PatchLevel& level, PHARE::solver::IPhysicalModel<SAMRAI_Types>& model)
level_t& level, PHARE::solver::IPhysicalModel<amr_types>& model)
{
static auto constexpr dimension = HybridModel::dimension;
auto& hybridModel = dynamic_cast<HybridModel&>(model);
Expand All @@ -56,11 +61,10 @@ void ConcreteLoadBalancerHybridStrategyNPPC<PHARE_T>::compute(
{
auto const& layout = layoutFromPatch<gridlayout_type>(*patch);

auto patch_data_lb
= dynamic_cast<SAMRAI::pdat::CellData<double>*>(patch->getPatchData(this->id_).get());
auto patch_data_lb = dynamic_cast<cell_data_t*>(patch->getPatchData(this->id_).get());
auto load_balancer_val = patch_data_lb->getPointer();

const auto& box = patch->getBox();
auto const& box = patch->getBox();

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable box is not used.

auto lb_view = core::NdArrayView<dimension, double, double*, c_ordering>(load_balancer_val,
layout.nbrCells());
Expand All @@ -74,98 +78,29 @@ void ConcreteLoadBalancerHybridStrategyNPPC<PHARE_T>::compute(
// to get the AMRLocatStart and AMRLocalEnd.
// Then, we build "by hand" the local index for the "lb_view" considering that the nbr
// of ghost cell for this patch data is null.
auto amr_box = layout.AMRBox();
auto const amr_box = layout.AMRBox();

// The lb_view is a CellData, meaning that it is dual as the index of an amr box
auto amr_start = amr_box.lower;
auto amr_end = amr_box.upper;

// nbr of cells in the physical domain
auto nbrCells = layout.nbrCells();




if constexpr (dimension == 1)
{
for (std::uint32_t i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr)
{
auto amr_point{core::Point{i_amr}};
auto amr_index = amr_point.template toArray<int>();

std::size_t nbr = 0;

for (auto& pop : ions)
{
const auto& domainParticles = pop.domainParticles();

nbr += domainParticles.nbr_particles_in(amr_index);
}

lb_view(i_loc) = nbr;
}
}
core::Box<std::uint32_t, dimension> local_box{
core::Point{core::ConstArray<std::uint32_t, dimension>()},
core::Point{
core::generate([](auto const& nCell) { return nCell - 1; }, layout.nbrCells())}};

auto amr_iter = amr_box.begin();
auto lcl_iter = local_box.begin();


if constexpr (dimension == 2)
{
for (std::uint32_t i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr)
{
for (std::uint32_t j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr)
{
auto amr_point{core::Point{i_amr, j_amr}};
auto amr_index = amr_point.template toArray<int>();

std::size_t nbr = 0;

for (auto& pop : ions)
{
const auto& domainParticles = pop.domainParticles();

nbr += domainParticles.nbr_particles_in(amr_index);
}

lb_view(i_loc, j_loc) = nbr;
}
}
}


if constexpr (dimension == 3)
{
for (std::uint32_t i_loc = 0, i_amr = amr_start[0]; i_loc < nbrCells[0]; ++i_loc, ++i_amr)
{
for (std::uint32_t j_loc = 0, j_amr = amr_start[1]; j_loc < nbrCells[1]; ++j_loc, ++j_amr)
{
for (std::uint32_t k_loc = 0, k_amr = amr_start[2]; k_loc < nbrCells[2];
++k_loc, ++k_amr)
{
auto amr_point{core::Point{i_amr, j_amr, k_amr}};
auto amr_index = amr_point.template toArray<int>();

std::size_t nbr = 0;

for (auto& pop : ions)
{
const auto& domainParticles = pop.domainParticles();

nbr += domainParticles.nbr_particles_in(amr_index);
}

lb_view(i_loc, j_loc, k_loc) = nbr;
}
}
}
}
for (; lcl_iter != local_box.end(); ++amr_iter, ++lcl_iter)
lb_view(*lcl_iter) = core::sum_from(ions, [&](auto const& pop) {
return pop.domainParticles().nbr_particles_in((*amr_iter).toArray());
});
}

// TODO here, we have the lb_view value correctly set on all patches. we also know the id_
// so this is where we should call setWorkloadPatchDataIndex... which is a method of the CascadePartitioner
// lb_view is a local container containing the datz
// the loadbalancezrmanager knows the id, as well as the loadbalancerestimator
// and the loadbalancerestimator is a cascadpartotioner

// so this is where we should call setWorkloadPatchDataIndex... which is a method of the
// CascadePartitioner lb_view is a local container containing the datz the loadbalancezrmanager
// knows the id, as well as the loadbalancerestimator and the loadbalancerestimator is a
// cascadpartotioner
}

} // namespace PHARE::amr
Expand Down
2 changes: 1 addition & 1 deletion src/amr/load_balancing/load_balancer_estimator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LoadBalancerEstimator
virtual ~LoadBalancerEstimator() = default;

virtual void estimate(SAMRAI::hier::PatchLevel& level,
PHARE::solver::IPhysicalModel<PHARE::amr::SAMRAI_Types>& model)
solver::IPhysicalModel<amr::SAMRAI_Types>& model)
= 0;


Expand Down
Loading

0 comments on commit c42b4cd

Please sign in to comment.