33#ifndef MADNESS_MRA_IBDEUX_H__INCLUDED
34#define MADNESS_MRA_IBDEUX_H__INCLUDED
56 template<
typename T, std::
size_t NDIM>
59 template<
typename T, std::
size_t NDIM>
62 template <std::
size_t NDIM>
65 typedef std::pair<keyT,ProcessID>
pairT;
66 typedef std::map<keyT,ProcessID>
mapT;
72 for (
unsigned int i=0; i<
v.size(); ++i) {
80 while (key.
level() >= 0) {
82 if (it ==
map.end()) {
90 throw "LBDeuxPmap: lookup failed";
100 template <std::
size_t NDIM>
125 for (
int i=0; i<
nchild; ++i)
133 for (
int i=0; i<
nchild; ++i)
138 for (
int i=0; i<
nchild; ++i)
168 if (child.
level() > 1) {
199 int ind =
index(child);
203 for (
int i=0; i<
nchild; ++i) {
204 for (
int j=i+1; j<
nchild; ++j) {
213 for (
int i=0; i<
nchild; ++i) {
225 template <
typename Archive>
232 template <std::
size_t NDIM>
243 template <
typename T,
typename costT>
261 const keyT& key = it->first;
262 const nodeT& node = it->second;
280 static bool compare(
const std::pair<keyT,double>&
a,
const std::pair<keyT,double>&
b) {
281 return a.second <
b.second;
293 template <
typename T,
typename costT>
303 for (
int i=0; i<key.level(); ++i) std::cout <<
" ";
304 print(key, it->second.get_total_cost());
306 if (it->second.has_children()) {
328 std::ostream& os = std::cout) {
330 std::vector<double> cost(nproc, 0.0);
334 double c = it->second.get_total_cost();
335 if (
c < 0.0)
continue;
336 cost[pmap->owner(it->first)] +=
c;
344 double mn = std::numeric_limits<double>::max();
345 for (
double c : cost) {
350 const double avg = (nproc > 0) ?
total / nproc : 0.0;
356 os <<
"=== Load balance summary: " <<
label <<
" ===\n";
357 os << std::fixed << std::setprecision(2)
358 <<
" total=" <<
total
360 <<
" max/avg=" << (
avg > 0.0 ?
mx /
avg : 0.0);
361 if (
mn > 0.0) os <<
" max/min=" <<
mx /
mn;
363 for (
int p = 0;
p < nproc; ++
p) {
364 int n = (
mx > 0.0) ?
static_cast<int>(std::lround(
barwidth * cost[
p] /
mx)) : 0;
367 os <<
" rank " << std::setw(3) <<
p <<
" |"
368 << std::string(n,
'#')
370 <<
"| " << std::setw(10) << cost[
p]
371 <<
" (" << (
avg > 0.0 ? cost[
p] /
avg : 0.0) <<
"x avg)\n";
373 os <<
"================================" << std::endl;
405 std::vector< std::pair<keyT,double> > results;
408 if (it->second.get_total_cost() >= 0) {
409 results.push_back(std::make_pair(it->first,it->second.get_total_cost()));
415 std::vector< std::pair<keyT,ProcessID> > map;
419 std::sort(results.begin(), results.end(),
compare);
421 print(
"THESE ARE THE INITIAL SUBTREES");
422 for (
unsigned int i=0; i<results.size(); ++i)
print(i,results[i]);
426 map.reserve(results.size());
430 std::priority_queue<CostPerProc>
costs;
431 for (
unsigned int p=0;
p<nproc && !results.empty(); ++
p) {
432 const std::pair<keyT,double>&
f = results.back();
434 map.push_back(std::make_pair(
f.first,
p));
439 while (!results.empty()) {
440 const std::pair<keyT,double>&
f = results.back();
443 top.
cost +=
f.second;
445 map.push_back(std::make_pair(
f.first,top.
proc));
449 print(
"THIS IS THE MAP");
451 print(
"THESE ARE THE COSTS PER PROCESSOR");
452 while (!
costs.empty()) {
465 return std::shared_ptr< WorldDCPmapInterface<keyT> >(
new LBDeuxPmap<NDIM>(map));
An integer with atomic set, get, read+increment, read+decrement, and decrement+test operations.
Definition atomicint.h:126
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:100
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition funcimpl.h:136
bool has_children() const
Returns true if this node has children.
Definition funcimpl.h:217
A multiresolution adaptive numerical function.
Definition mra.h:144
A future is a possibly yet unevaluated value.
Definition future.h:370
Iterates in lexical order thru all children of a key.
Definition key.h:548
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:70
Level level() const
Definition key.h:169
Key parent(int generation=1) const
Returns the key of the parent.
Definition key.h:290
const Vector< Translation, NDIM > & translation() const
Definition key.h:174
ProcessID owner(const keyT &key) const
Maps key to processor.
Definition lbdeux.h:79
void print() const
Definition lbdeux.h:93
Key< NDIM > keyT
Definition lbdeux.h:64
mapT map
Definition lbdeux.h:67
std::map< keyT, ProcessID > mapT
Definition lbdeux.h:66
mapT::const_iterator iteratorT
Definition lbdeux.h:68
LBDeuxPmap(const std::vector< pairT > &v)
Definition lbdeux.h:71
std::pair< keyT, ProcessID > pairT
Definition lbdeux.h:65
void add(double cost, bool got_kids)
Accumulates cost into this node.
Definition lbdeux.h:157
double get_total_cost() const
Definition lbdeux.h:152
LBNodeDeux()
Definition lbdeux.h:122
void serialize(Archive &ar)
Definition lbdeux.h:226
Key< NDIM > keyT
Definition lbdeux.h:103
void partition(const treeT &tree, const keyT &key, double avg)
Descends tree deleting all except internal nodes and sub-tree parents.
Definition lbdeux.h:192
bool gotkids
Definition lbdeux.h:110
AtomicInt nsummed
Definition lbdeux.h:112
LBNodeDeux< NDIM > & operator=(const LBNodeDeux< NDIM > &other)
Definition lbdeux.h:137
double total_cost
Definition lbdeux.h:109
static const int nchild
Definition lbdeux.h:102
bool has_children() const
Definition lbdeux.h:148
WorldContainer< keyT, nodeT > treeT
Definition lbdeux.h:105
int index(const keyT &key)
Computes index of child key in this node using last bit of translations.
Definition lbdeux.h:115
LBNodeDeux(const LBNodeDeux< NDIM > &other)
Definition lbdeux.h:129
double my_cost
Definition lbdeux.h:108
double child_cost[nchild]
Definition lbdeux.h:107
LBNodeDeux< NDIM > nodeT
Definition lbdeux.h:104
void deleter(const treeT &tree, const keyT &key)
Logically deletes this node by setting cost to -1.
Definition lbdeux.h:181
void sum(const treeT &tree, const keyT &child, double value)
Accumulates cost up the tree from children.
Definition lbdeux.h:163
Key< NDIM > keyT
Definition lbdeux.h:234
World & world
Definition lbdeux.h:239
treeT::iterator iteratorT
Definition lbdeux.h:237
treeT tree
Definition lbdeux.h:240
LBNodeDeux< NDIM > nodeT
Definition lbdeux.h:235
std::shared_ptr< WorldDCPmapInterface< keyT > > load_balance(double fac=1.0, bool printstuff=false)
Actually does the partitioning of the tree.
Definition lbdeux.h:390
void print_tree(const keyT &key=keyT(0))
Printing for the curious.
Definition lbdeux.h:299
treeT::const_iterator const_iteratorT
Definition lbdeux.h:238
double sum()
Sums costs up the tree returning to everyone the total cost.
Definition lbdeux.h:257
static bool compare(const std::pair< keyT, double > &a, const std::pair< keyT, double > &b)
Used to sort results into descending order.
Definition lbdeux.h:280
void add_tree(const Function< T, NDIM > &f, const costT &costfn, bool fence=false)
Accumulates cost from a function.
Definition lbdeux.h:294
WorldContainer< keyT, nodeT > treeT
Definition lbdeux.h:236
LoadBalanceDeux(World &world)
Definition lbdeux.h:286
void print_cost_per_rank(const std::string &label, const std::shared_ptr< WorldDCPmapInterface< keyT > > &pmap, std::ostream &os=std::cout)
Definition lbdeux.h:326
Iterator for distributed container wraps the local iterator.
Definition worlddc.h:386
Makes a distributed container with specified attributes.
Definition worlddc.h:1127
bool find(accessor &acc, const keyT &key)
Write access to LOCAL value by key. Returns true if found, false otherwise (always false for remote).
Definition worlddc.h:1274
iterator begin()
Returns an iterator to the beginning of the local data (no communication)
Definition worlddc.h:1357
ProcessID owner(const keyT &key) const
Returns processor that logically owns key (no communication)
Definition worlddc.h:1321
iterator end()
Returns an iterator past the end of the local data (no communication)
Definition worlddc.h:1371
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const TaskAttributes &attr=TaskAttributes())
Adds task "resultT memfun()" in process owning item (non-blocking comm if remote)
Definition worlddc.h:1713
bool is_local(const keyT &key) const
Returns true if the key maps to the local processor (no communication)
Definition worlddc.h:1328
Future< MEMFUN_RETURNT(memfunT)> send(const keyT &key, memfunT memfun)
Sends message "resultT memfun()" to item (non-blocking comm if remote)
Definition worlddc.h:1470
Interface to be provided by any process map.
Definition worlddc.h:122
void broadcast_serializable(objT &obj, ProcessID root)
Broadcast a serializable object.
Definition worldgop.h:774
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:176
void broadcast(void *buf, size_t nbyte, ProcessID root, bool dowork=true, Tag bcast_tag=-1)
Broadcasts bytes from process root while still processing AM & tasks.
Definition worldgop.cc:188
std::vector< T > concat0(const std::vector< T > &v, size_t bufsz=1024 *1024)
Concatenate an STL vector of serializable stuff onto node 0.
Definition worldgop.h:973
void sum(T *buf, size_t nelem)
Inplace global sum while still processing AM & tasks.
Definition worldgop.h:890
A parallel world class.
Definition world.h:134
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:344
ProcessID size() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition world.h:354
WorldGopInterface & gop
Global operations.
Definition world.h:216
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
Provides FunctionDefaults and utilities for coordinate transformation.
archive_array< unsigned char > wrap_opaque(const T *, unsigned int)
Factory function to wrap a pointer to contiguous data as an opaque (uchar) archive_array.
Definition archive.h:926
static const double v
Definition hatom_sf_dirac.cc:20
Multidimension Key for MRA tree and associated iterators.
Macros and tools pertaining to the configuration of MADNESS.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:227
NDIM & f
Definition mra.h:2622
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
static const double b
Definition nonlinschro.cc:119
static const double d
Definition nonlinschro.cc:121
static const double a
Definition nonlinschro.cc:118
static const double c
Definition relops.cc:10
CostPerProc(double cost, int proc)
Definition lbdeux.h:383
int proc
Definition lbdeux.h:381
bool operator<(const CostPerProc &other) const
Definition lbdeux.h:384
double cost
Definition lbdeux.h:380
CostPerProc()
Definition lbdeux.h:382
void operator()(const keyT &key, const FunctionNode< T, NDIM > &node) const
Definition lbdeux.h:248
const costT & costfn
Definition lbdeux.h:246
LoadBalanceDeux * lb
Definition lbdeux.h:245
add_op(LoadBalanceDeux *lb, const costT &costfn)
Definition lbdeux.h:247
int task(int i)
Definition test_runtime.cpp:4
constexpr std::size_t NDIM
Definition testgconv.cc:54
Implements WorldContainer.
int ProcessID
Used to clearly identify process number/rank.
Definition worldtypes.h:43