Skip to content

Commit

Permalink
updates / clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Feb 6, 2024
1 parent b3ed357 commit 21cecd0
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 98 deletions.
5 changes: 2 additions & 3 deletions res/cmake/dep.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

include("${PHARE_PROJECT_DIR}/res/cmake/dep/cppdict.cmake")
add_subdirectory(subprojects/cppdict)

# SAMRAI build option
include("${PHARE_PROJECT_DIR}/res/cmake/dep/samrai.cmake")
Expand All @@ -15,6 +17,3 @@ include("${PHARE_PROJECT_DIR}/res/cmake/dep/pybind.cmake")

# HighFive
include("${PHARE_PROJECT_DIR}/res/cmake/dep/highfive.cmake")


add_subdirectory(subprojects/cppdict)
14 changes: 14 additions & 0 deletions res/cmake/dep/cppdict.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


set(CPPDICT_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/subprojects/cppdict)

if (NOT EXISTS ${CPPDICT_SRCDIR})
execute_process(
COMMAND ${Git} clone https://github.com/LaboratoryOfPlasmaPhysics/cppdict ${CPPDICT_SRCDIR} -b master --recursive --depth 10
)
else()
if(devMode)
message("downloading latest cppdict updates")
execute_process(COMMAND ${Git} pull origin master WORKING_DIRECTORY ${CPPDICT_SRCDIR})
endif(devMode)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@




namespace PHARE::amr
{
template<typename PHARE_T>
Expand Down Expand Up @@ -46,9 +45,6 @@ template<typename PHARE_T>
void ConcreteLoadBalancerHybridStrategyHomogeneous<PHARE_T>::compute(
level_t& level, PHARE::solver::IPhysicalModel<amr_types>& model)
{
auto static constexpr dimension = HybridModel::dimension;
bool static constexpr c_ordering = false;

auto& hybridModel = dynamic_cast<HybridModel&>(model);
auto& resourcesManager = hybridModel.resourcesManager;

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable resourcesManager is not used.
auto& ions = hybridModel.state.ions;

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable ions is not used.
Expand All @@ -58,8 +54,6 @@ void ConcreteLoadBalancerHybridStrategyHomogeneous<PHARE_T>::compute(
auto const& layout = layoutFromPatch<gridlayout_type>(*patch);
auto patch_data_lb = dynamic_cast<cell_data_t*>(patch->getPatchData(this->id_).get());
auto load_balancer_val = patch_data_lb->getPointer();
auto lb_view = core::make_array_view<c_ordering>(load_balancer_val, layout.nbrCells());
auto _ = resourcesManager->setOnPatch(*patch, ions);

// The view on "load_balancer_val" do not have any ghost cells, meaning that this patch
// data lies on a box defind by the nbr of cells in the physical domain
Expand All @@ -71,14 +65,7 @@ void ConcreteLoadBalancerHybridStrategyHomogeneous<PHARE_T>::compute(

// The lb_view is a CellData, meaning that it is dual as the index of an amr box

// todo replace below with std::fill/std::fill_n data, size = 1
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())}};

for (auto const& idx : local_box)
lb_view(idx) = 1;
std::fill(load_balancer_val, load_balancer_val + core::product(layout.nbrCells()), 1);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/amr/multiphysics_integrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namespace solver
int solverIndex = NOT_SET;
int resourcesManagerIndex = NOT_SET;
int taggerIndex = NOT_SET;
// int loadBalancerIndex = NOT_SET;
std::string messengerName;
};

Expand Down
15 changes: 7 additions & 8 deletions src/amr/wrappers/integrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,30 @@ class Integrator

bool static _rebalance_coarsest(initializer::PHAREDict const& dict)
{
return initializer::dict_get(dict, "simulation/advanced/integrator/rebalance_coarsest", 0)
> 0;
return cppdict::get_value(dict, "simulation/advanced/integrator/rebalance_coarsest", 0) > 0;
}

bool static _rebalance_coarsest_on_init(initializer::PHAREDict const& dict)
{
return initializer::dict_get(dict,
"simulation/advanced/integrator/rebalance_coarsest_on_init", 0)
return cppdict::get_value(dict, "simulation/advanced/integrator/rebalance_coarsest_on_init",
0)
> 0;
}

std::size_t static _rebalance_coarsest_every(initializer::PHAREDict const& dict)
{
auto in
= initializer::dict_get(dict, "simulation/advanced/integrator/rebalance_coarsest_every",
rebalance_coarsest_every_default);
= cppdict::get_value(dict, "simulation/advanced/integrator/rebalance_coarsest_every",
rebalance_coarsest_every_default);
if (in < 0)
throw std::runtime_error("rebalance_coarsest_every must be positive");
return static_cast<std::size_t>(in);
}

bool static _is_tagging_refinement(initializer::PHAREDict const& dict)
{
return initializer::dict_get(dict, "simulation/AMR/refinement/tagging/method",
std::string{"none"})
return cppdict::get_value(dict, "simulation/AMR/refinement/tagging/method",
std::string{"none"})
== std::string{"auto"};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ namespace core

auto charge = dict["charge"].template to<double>();

auto nbrPartPerCell = initializer::dict_get(dict, "nbr_part_per_cell", int{0});
auto nbrPartPerCell = cppdict::get_value(dict, "nbr_part_per_cell", int{0});
FunctionType nbrPartPerCellFn
= initializer::dict_get(dict, "nbr_part_per_cell_fn", FunctionType{nullptr});
= cppdict::get_value(dict, "nbr_part_per_cell_fn", FunctionType{nullptr});
if (not nbrPartPerCellFn and nbrPartPerCell == 0)
{
throw std::runtime_error("PPC cannot be 0");
Expand Down
48 changes: 0 additions & 48 deletions src/initializer/data_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,53 +92,5 @@ namespace initializer
} // namespace initializer
} // namespace PHARE

namespace PHARE::initializer
{

template<typename Dict, typename Paths>
std::optional<Dict> _traverse_to_node(Dict const& dict, Paths const& paths, std::size_t idx = 0)
{
if (dict.contains(paths[idx]))
{
auto const& next = dict[paths[idx]];
if (idx == paths.size() - 1)
return next;
return _traverse_to_node(next, paths, ++idx);
}
return std::nullopt;
}

template<typename Dict>
std::optional<PHAREDict> traverse_to_node(Dict const& dict, std::string const& path)
{
char delimiter = '/';
std::string tmp = "";
std::vector<std::string> paths;
std::istringstream iss(path);
while (std::getline(iss, tmp, delimiter))
paths.push_back(tmp);
return _traverse_to_node(dict, paths);
}

template<typename T, typename Dict>
T const& dict_get(Dict const& dict, std::string const& path)
{
// error if not found
auto leaf = traverse_to_node(dict, path);
if (leaf)
return leaf->template to<T>();
throw std::runtime_error("Dict contains no path " + path);
}

template<typename T, typename Dict>
T dict_get(Dict const& dict, std::string const& path, T const default_value)
{
auto leaf = traverse_to_node(dict, path);
if (leaf)
return leaf->template to<T>();
return default_value;
}

} // namespace PHARE::initializer

#endif // DATA_PROVIDER_HPP
2 changes: 1 addition & 1 deletion src/simulator/simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void Simulator<dim, _interp, nbRefinedPart>::hybrid_init(initializer::PHAREDict

auto loadBalancer_db = std::make_shared<SAMRAI::tbox::MemoryDatabase>("LoadBalancerDB");
double flexible_load_tolerance
= initializer::dict_get(dict, "simulation/advanced/integrator/flexible_load_tolerance", .5);
= cppdict::get_value(dict, "simulation/advanced/integrator/flexible_load_tolerance", .5);

loadBalancer_db->putDouble("flexible_load_tolerance", flexible_load_tolerance);
auto loadBalancer = std::make_shared<SAMRAI::mesh::CascadePartitioner>(
Expand Down
1 change: 0 additions & 1 deletion subprojects/cppdict
Submodule cppdict deleted from 6b0275
36 changes: 16 additions & 20 deletions tests/simulator/test_load_balancing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env python3


import unittest
import pyphare.pharein as ph
from pyphare.simulator.simulator import Simulator, startMPI
from tests.simulator import SimulatorTest

import numpy as np
import matplotlib as mpl
Expand Down Expand Up @@ -166,30 +169,23 @@ def _parse_rank(patch_id):
return per_rank


def assert_has_balanced(sim):
t0 = time_info(sim)
tend = time_info(sim, timestamps[-1])

t0_sdev = np.std(list(t0.values()))
tend_sdev = np.std(list(tend.values()))

print("init sdev", t0_sdev)
print("end sdev", tend_sdev)
assert tend_sdev < t0_sdev * 0.1 # empirical

class LoadBalancingTest(SimulatorTest):
def test_has_balanced(self):
if mpi_size == 1: # doesn't make sense
return

def main():
if mpi_size == 1:
return # doesn't make sense
sim = config()
self.register_diag_dir_for_cleanup(diag_outputs)
Simulator(sim).run()

sim = config()
Simulator(sim).run()
if cpp.mpi_rank() > 0:
return

if cpp.mpi_rank() > 0:
return
t0_sdev = np.std(list(time_info(sim).values()))
tend_sdev = np.std(list(time_info(sim, timestamps[-1]).values()))

assert_has_balanced(sim)
assert tend_sdev < t0_sdev * 0.1 # empirical


if __name__ == "__main__":
main()
unittest.main()

0 comments on commit 21cecd0

Please sign in to comment.