33 #ifndef MADNESS_MRA_IBDEUX_H__INCLUDED
34 #define MADNESS_MRA_IBDEUX_H__INCLUDED
51 template<
typename T, std::
size_t NDIM>
54 template<
typename T, std::
size_t NDIM>
57 template <std::
size_t NDIM>
60 typedef std::pair<keyT,ProcessID>
pairT;
61 typedef std::map<keyT,ProcessID>
mapT;
67 for (
unsigned int i=0; i<
v.size(); ++i) {
75 while (key.
level() >= 0) {
77 if (it ==
map.end()) {
85 throw "LBDeuxPmap: lookup failed";
95 template <std::
size_t NDIM>
120 for (
int i=0; i<
nchild; ++i)
128 for (
int i=0; i<
nchild; ++i)
133 for (
int i=0; i<
nchild; ++i)
152 void add(
double cost,
bool got_kids) {
163 if (child.
level() > 1) {
180 const keyT child = kit.key();
193 const keyT child = kit.key();
194 int ind =
index(child);
198 for (
int i=0; i<
nchild; ++i) {
199 for (
int j=i+1; j<
nchild; ++j) {
200 if (vals[i] < vals[j]) {
208 for (
int i=0; i<
nchild; ++i) {
220 template <
typename Archive>
227 template <std::
size_t NDIM>
238 template <
typename T,
typename costT>
256 const keyT& key = it->first;
257 const nodeT& node = it->second;
266 total =
tree.
find(key0).get()->second.get_total_cost();
275 static bool compare(
const std::pair<keyT,double>&
a,
const std::pair<keyT,double>&
b) {
276 return a.second <
b.second;
288 template <
typename T,
typename costT>
298 for (
int i=0; i<key.level(); ++i) std::cout <<
" ";
299 print(key, it->second.get_total_cost());
301 if (it->second.has_children()) {
320 std::shared_ptr< WorldDCPmapInterface<keyT> >
load_balance(
double fac = 1.0,
bool printstuff=
false) {
335 std::vector< std::pair<keyT,double> > results;
338 if (it->second.get_total_cost() >= 0) {
339 results.push_back(std::make_pair(it->first,it->second.get_total_cost()));
345 std::vector< std::pair<keyT,ProcessID> > map;
349 std::sort(results.begin(), results.end(),
compare);
351 print(
"THESE ARE THE INITIAL SUBTREES");
352 for (
unsigned int i=0; i<results.size(); ++i)
print(i,results[i]);
356 map.reserve(results.size());
360 std::priority_queue<CostPerProc> costs;
361 for (
unsigned int p=0;
p<nproc && !results.empty(); ++
p) {
362 const std::pair<keyT,double>&
f = results.back();
364 map.push_back(std::make_pair(
f.first,
p));
369 while (!results.empty()) {
370 const std::pair<keyT,double>&
f = results.back();
373 top.
cost +=
f.second;
375 map.push_back(std::make_pair(
f.first,top.
proc));
379 print(
"THIS IS THE MAP");
381 print(
"THESE ARE THE COSTS PER PROCESSOR");
382 while (!costs.empty()) {
383 print(costs.top().proc,costs.top().cost);
395 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:204
FunctionNode holds the coefficients, etc., at each node of the 2^NDIM-tree.
Definition: funcimpl.h:124
bool has_children() const
Returns true if this node has children.
Definition: funcimpl.h:203
A multiresolution adaptive numerical function.
Definition: mra.h:122
A future is a possibly yet unevaluated value.
Definition: future.h:373
T & get(bool dowork=true) &
Gets the value, waiting if necessary.
Definition: future.h:574
Iterates in lexical order thru all children of a key.
Definition: key.h:374
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:66
Level level() const
Definition: key.h:159
const Vector< Translation, NDIM > & translation() const
Definition: key.h:164
Key parent(int generation=1) const
Returns the key of the parent.
Definition: key.h:187
ProcessID owner(const keyT &key) const
Maps key to processor.
Definition: lbdeux.h:74
void print() const
Definition: lbdeux.h:88
Key< NDIM > keyT
Definition: lbdeux.h:59
mapT map
Definition: lbdeux.h:62
std::map< keyT, ProcessID > mapT
Definition: lbdeux.h:61
mapT::const_iterator iteratorT
Definition: lbdeux.h:63
LBDeuxPmap(const std::vector< pairT > &v)
Definition: lbdeux.h:66
std::pair< keyT, ProcessID > pairT
Definition: lbdeux.h:60
void add(double cost, bool got_kids)
Accumulates cost into this node.
Definition: lbdeux.h:152
LBNodeDeux< NDIM > & operator=(const LBNodeDeux< NDIM > &other)
Definition: lbdeux.h:132
double get_total_cost() const
Definition: lbdeux.h:147
LBNodeDeux()
Definition: lbdeux.h:117
void serialize(Archive &ar)
Definition: lbdeux.h:221
Key< NDIM > keyT
Definition: lbdeux.h:98
void partition(const treeT &tree, const keyT &key, double avg)
Descends tree deleting all except internal nodes and sub-tree parents.
Definition: lbdeux.h:187
bool gotkids
Definition: lbdeux.h:105
AtomicInt nsummed
Definition: lbdeux.h:107
double total_cost
Definition: lbdeux.h:104
static const int nchild
Definition: lbdeux.h:97
bool has_children() const
Definition: lbdeux.h:143
WorldContainer< keyT, nodeT > treeT
Definition: lbdeux.h:100
int index(const keyT &key)
Computes index of child key in this node using last bit of translations.
Definition: lbdeux.h:110
LBNodeDeux(const LBNodeDeux< NDIM > &other)
Definition: lbdeux.h:124
double my_cost
Definition: lbdeux.h:103
double child_cost[nchild]
Definition: lbdeux.h:102
LBNodeDeux< NDIM > nodeT
Definition: lbdeux.h:99
void deleter(const treeT &tree, const keyT &key)
Logically deletes this node by setting cost to -1.
Definition: lbdeux.h:176
void sum(const treeT &tree, const keyT &child, double value)
Accumulates cost up the tree from children.
Definition: lbdeux.h:158
Key< NDIM > keyT
Definition: lbdeux.h:229
std::shared_ptr< WorldDCPmapInterface< keyT > > load_balance(double fac=1.0, bool printstuff=false)
Actually does the partitioning of the tree.
Definition: lbdeux.h:320
World & world
Definition: lbdeux.h:234
treeT::iterator iteratorT
Definition: lbdeux.h:232
treeT tree
Definition: lbdeux.h:235
LBNodeDeux< NDIM > nodeT
Definition: lbdeux.h:230
void print_tree(const keyT &key=keyT(0))
Printing for the curious.
Definition: lbdeux.h:294
treeT::const_iterator const_iteratorT
Definition: lbdeux.h:233
double sum()
Sums costs up the tree returning to everyone the total cost.
Definition: lbdeux.h:252
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:275
void add_tree(const Function< T, NDIM > &f, const costT &costfn, bool fence=false)
Accumulates cost from a function.
Definition: lbdeux.h:289
WorldContainer< keyT, nodeT > treeT
Definition: lbdeux.h:231
LoadBalanceDeux(World &world)
Definition: lbdeux.h:281
Iterator for distributed container wraps the local iterator.
Definition: worlddc.h:244
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:987
iterator begin()
Returns an iterator to the beginning of the local data (no communication)
Definition: worlddc.h:1070
ProcessID owner(const keyT &key) const
Returns processor that logically owns key (no communication)
Definition: worlddc.h:1034
iterator end()
Returns an iterator past the end of the local data (no communication)
Definition: worlddc.h:1084
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:1426
bool is_local(const keyT &key) const
Returns true if the key maps to the local processor (no communication)
Definition: worlddc.h:1041
Future< MEMFUN_RETURNT(memfunT)> send(const keyT &key, memfunT memfun)
Sends message "resultT memfun()" to item (non-blocking comm if remote)
Definition: worlddc.h:1183
Interface to be provided by any process map.
Definition: worlddc.h:82
void broadcast_serializable(objT &obj, ProcessID root)
Broadcast a serializable object.
Definition: worldgop.h:754
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition: worldgop.cc:161
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:173
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:953
A parallel world class.
Definition: world.h:132
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition: world.h:318
ProcessID size() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition: world.h:328
WorldGopInterface & gop
Global operations.
Definition: world.h:205
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:925
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.
File holds all helper structures necessary for the CC_Operator and CC2 class.
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:225
NDIM & f
Definition: mra.h:2416
void swap(Vector< T, N > &l, Vector< T, N > &r)
Swap the contents of two Vectors.
Definition: vector.h:497
static const double b
Definition: nonlinschro.cc:119
static const double a
Definition: nonlinschro.cc:118
CostPerProc(double cost, int proc)
Definition: lbdeux.h:313
int proc
Definition: lbdeux.h:311
bool operator<(const CostPerProc &other) const
Definition: lbdeux.h:314
double cost
Definition: lbdeux.h:310
CostPerProc()
Definition: lbdeux.h:312
void operator()(const keyT &key, const FunctionNode< T, NDIM > &node) const
Definition: lbdeux.h:243
const costT & costfn
Definition: lbdeux.h:241
LoadBalanceDeux * lb
Definition: lbdeux.h:240
add_op(LoadBalanceDeux *lb, const costT &costfn)
Definition: lbdeux.h:242
int task(int i)
Definition: test_runtime.cpp:4
void d()
Definition: test_sig.cc:79
static const std::size_t NDIM
Definition: testpdiff.cc:42
Implements WorldContainer.
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:43