-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load balancer python registerable object with defaults
- Loading branch information
1 parent
1a6366f
commit 4c1b83b
Showing
9 changed files
with
162 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# | ||
# | ||
|
||
from dataclasses import dataclass, field | ||
from . import global_vars as gv | ||
|
||
|
||
@dataclass | ||
class LoadBalancer: | ||
# whether or not load balancing is performed | ||
active: bool = field(default_factory=lambda: False) | ||
|
||
# which way load is assessed | ||
mode: str = field(default_factory=lambda: "nppc") | ||
|
||
# acceptable imbalance essentially | ||
tol: float = field(default_factory=lambda: 0.05) | ||
|
||
# if auto, other values are not used if active | ||
auto: bool = field(default_factory=lambda: True) | ||
|
||
# if !auto these values are used if active | ||
on_init: bool = field(default_factory=lambda: True) | ||
every: int = field(default_factory=lambda: 1) | ||
|
||
# internal, allows not registering object for default init | ||
_register: bool = field(default_factory=lambda: True) | ||
|
||
def __post_init__(self): | ||
allowed_modes = [ | ||
"nppc", # count particles per rank | ||
"homogeneous", # count cells per rank | ||
] | ||
|
||
if self.mode not in allowed_modes: | ||
raise RuntimeError(f"LoadBalancer mode '{self.mode}' is not valid") | ||
|
||
if self._register: | ||
if not gv.sim: | ||
raise RuntimeError( | ||
f"LoadBalancer cannot be registered as no simulation exists" | ||
) | ||
if gv.sim.load_balancer: | ||
raise RuntimeError(f"LoadBalancer is already registered to simulation") | ||
gv.sim.load_balancer = self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef PHARE_AMR_LOAD_BALANCER_LOAD_BALANCER_DETAILS_HPP | ||
#define PHARE_AMR_LOAD_BALANCER_LOAD_BALANCER_DETAILS_HPP | ||
|
||
#include <string> | ||
#include <cstdint> | ||
|
||
#include "core/logger.hpp" | ||
#include "initializer/data_provider.hpp" | ||
|
||
namespace PHARE::amr | ||
{ | ||
struct LoadBalancerDetails | ||
{ | ||
bool const active = false; | ||
bool const automatic = false; | ||
bool const on_init = false; | ||
|
||
std::size_t const every = 0; | ||
std::string const mode; | ||
|
||
double const tolerance = .05; | ||
|
||
LoadBalancerDetails static FROM(initializer::PHAREDict const& dict) | ||
{ | ||
return {cppdict::get_value(dict, "active", false), | ||
cppdict::get_value(dict, "auto", false), | ||
cppdict::get_value(dict, "on_init", false), | ||
cppdict::get_value(dict, "every", std::size_t{0}), | ||
cppdict::get_value(dict, "mode", std::string{"nppc"}), | ||
cppdict::get_value(dict, "tol", 0.05)}; | ||
} | ||
}; | ||
|
||
} // namespace PHARE::amr | ||
|
||
#endif /* PHARE_AMR_LOAD_BALANCER_LOAD_BALANCER_DETAILS_HPP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.