32#ifndef MADNESS_WORLD_WORLDDC_H__INCLUDED
33#define MADNESS_WORLD_WORLDDC_H__INCLUDED
48#include <unordered_set>
60 template <
typename keyT,
typename valueT,
typename hashfunT>
63 template <
typename keyT,
typename valueT,
typename hashfunT>
64 class WorldContainerImpl;
66 template <
typename keyT,
typename valueT,
typename hashfunT>
67 void swap(WorldContainer<keyT, valueT, hashfunT> &, WorldContainer<keyT, valueT, hashfunT> &);
69 template <
typename keyT>
70 class WorldDCPmapInterface;
72 template <
typename keyT>
76 virtual std::size_t
size()
const = 0;
91 template<
typename T=
long>
99 template<
typename T=
long>
101 std::stringstream ss; ss <<
type;
105 template<
typename T=
long>
108 std::transform(
type.begin(),
type.end(),
type.begin(), [](
unsigned char c){ return std::tolower(c); });
112 std::string msg=
"unknown distribution type:"+
type;
123 template <
typename keyT>
184 for (
typename std::set<ptrT>::iterator iter =
ptrs.begin();
188 (*iter)->redistribute_phase1(newpmap);
191 for (
typename std::set<ptrT>::iterator iter =
ptrs.begin();
195 (*iter)->redistribute_phase2();
196 newpmap->register_callback(*iter);
199 for (
typename std::set<ptrT>::iterator iter =
ptrs.begin();
203 (*iter)->redistribute_phase3();
207 newpmap->print_data_sizes(world,
"after redistributing");
226 for (
typename std::set<ptrT>::iterator iter =
ptrs.begin(); iter !=
ptrs.end(); ++iter)
228 sum += (*iter)->size();
240 std::vector<std::size_t> sizes(world.
size());
243 if (world.
rank() == 0)
247 std::cout <<
" procs: ";
248 for (
int i = 0; i < world.
size(); i++)
249 std::cout << sizes[i] <<
" ";
250 std::cout << std::endl;
259 template <
typename keyT,
typename hashfunT = Hash<keyT>>
283 template <
typename keyT,
typename hashfunT = Hash<keyT>>
307 template <
typename keyT>
322 template <
typename keyT,
typename hashfunT = Hash<keyT>>
346 template <
typename dcT>
350 World& world=dc.get_world();
351 auto result= dc.get_pmap()->distribution_type();
353 auto local_size=dc.
size();
354 auto global_size=local_size;
355 world.
gop.
sum(global_size);
357 auto number_of_duplicates = [](
const std::vector<hashT>&
v) {
358 std::unordered_map<hashT, size_t> counts;
359 size_t duplicates = 0;
360 for (
const auto& elem :
v) {
361 if (++counts[elem] > 1) duplicates++;
367 std::vector<hashT> all_hashes(local_size);
368 const auto& hashfun=dc.get_hash();
370 for (
auto it=dc.begin();it!=dc.end();++it,++i) all_hashes[i]=hashfun(it->first);
372 std::size_t ndup=number_of_duplicates(all_hashes);
383 std::size_t nrank=world.
size();
393 print(
"primary_rank_per_host",primary_ranks);
395 std::size_t nnodes=primary_ranks.size();
396 bool is_primary=(std::find(primary_ranks.begin(),primary_ranks.end(),world.
rank())!=primary_ranks.end());
399 MADNESS_CHECK_THROW(global_size==(nnodes*local_size),
"WorldDC inconsistent - global size");
412 template <
class internal_iteratorT>
417 typedef typename std::iterator_traits<internal_iteratorT>::value_type
value_type;
418 typedef typename std::iterator_traits<internal_iteratorT>::difference_type
difference_type;
419 typedef typename std::iterator_traits<internal_iteratorT>::pointer
pointer;
420 typedef typename std::iterator_traits<internal_iteratorT>::reference
reference;
423 internal_iteratorT
it;
449 template <
class iteratorT>
478 return !(*
this == other);
520 return value !=
nullptr;
523 template <
typename Archive>
530 template <
class iteratorT>
533 template <
class iteratorT>
536 if (
static_cast<const void *
>(
this) !=
static_cast<const void *
>(&other))
542 it = internal_iteratorT();
556 template <
typename keyT,
typename valueT,
typename hashfunT>
558 :
public WorldObject<WorldContainerImpl<keyT, valueT, hashfunT>>,
560#ifndef MADNESS_DISABLE_SHARED_FROM_THIS
562 public std::enable_shared_from_this<WorldContainerImpl<keyT, valueT, hashfunT>>
566 typedef typename std::pair<const keyT, valueT>
pairT;
597 std::shared_ptr<WorldDCPmapInterface<keyT>>
pmap;
610 this->
send(requestor, &implT::find_failure_handler, ref);
615 this->
send(requestor, &implT::find_success_handler, ref, *r);
645 pmap->register_callback(
this);
650 pmap->deregister_callback(
this);
653 const std::shared_ptr<WorldDCPmapInterface<keyT>> &
get_pmap()
const
658 std::shared_ptr<WorldDCPmapInterface<keyT>> &
get_pmap()
665 pmap->deregister_callback(
this);
667 pmap->register_callback(
this);
674 pmap->deregister_callback(
this);
676 pmap->register_callback(
this);
718 pmap->deregister_callback(
this);
720 pmap->register_callback(
this);
725 pmap->deregister_callback(
this);
727 pmap->register_callback(
this);
733 std::vector<int> secondary_ranks;
735 if (std::find(primary_ranks.begin(),primary_ranks.end(),r)==primary_ranks.end())
736 secondary_ranks.push_back(r);
746 for (
auto it =
begin(); it !=
end(); ++it) {
747 keyT key = it->first;
748 valueT value = it->second;
749 this->
send(myowner,&implT::insert,
pairT(key,value));
764 pmap->deregister_callback(
this);
766 pmap->register_callback(
this);
769 bool i_am_in_primary_list=
world.
rank()==myowner;
770 if (i_am_in_primary_list) {
778 World world_primary(comm_primary);
805 std::size_t sz =
size();
808 for (
auto it =
begin(); it !=
end(); ++it)
810 keyT key = it->first;
811 valueT value = it->second;
820 for (
size_t i = 0; i < sz; i++)
841 return pmap->owner(key);
866 [[maybe_unused]]
auto inserted =
local.
insert(acc, datum.first);
867 acc->second = datum.second;
872 this->
send(dest, &implT::insert, datum);
894 for (
const pairT &kv : boxes)
897 [[maybe_unused]]
auto inserted =
local.
insert(acc, kv.first);
898 acc->second = kv.second;
917 void (
implT::*eraser)(
const keyT &) = &implT::erase;
918 this->
send(dest, eraser, key);
922 template <
typename InIter>
930 template <
typename InIter>
931 void erase(InIter first, InIter last)
939 }
while (first != last);
983 this->
send(dest, &implT::find_handler,
me, key, result.
remote_ref(this->get_world()));
1003 template <
typename memfunT>
1009 [[maybe_unused]]
auto inserted =
local.
insert(acc, key);
1010 return (acc->second.*memfun)();
1014 template <
typename memfunT,
typename arg1T>
1020 [[maybe_unused]]
auto inserted =
local.
insert(acc, key);
1021 return (acc->second.*memfun)(arg1);
1025 template <
typename memfunT,
typename arg1T,
typename arg2T>
1027 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2)
1031 [[maybe_unused]]
auto inserted =
local.
insert(acc, key);
1032 return (acc->second.*memfun)(arg1, arg2);
1036 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
1038 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3)
1042 [[maybe_unused]]
auto inserted =
local.
insert(acc, key);
1043 return (acc->second.*memfun)(arg1, arg2, arg3);
1047 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
1049 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4)
1053 [[maybe_unused]]
auto inserted =
local.
insert(acc, key);
1054 return (acc->second.*memfun)(arg1, arg2, arg3, arg4);
1058 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
1060 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5)
1064 [[maybe_unused]]
auto inserted =
local.
insert(acc, key);
1065 return (acc->second.*memfun)(arg1, arg2, arg3, arg4, arg5);
1069 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
1071 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6)
1075 [[maybe_unused]]
auto inserted =
local.
insert(acc, key);
1076 return (acc->second.*memfun)(arg1, arg2, arg3, arg4, arg5, arg6);
1080 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
1082 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3,
1083 const arg4T &arg4, const arg5T &arg5, const arg6T &arg6, const arg7T &arg7)
1087 [[maybe_unused]]
auto inserted =
local.
insert(acc, key);
1088 return (acc->second.*memfun)(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1117 impl->local.erase(iter);
1152 pmap->deregister_callback(
this);
1154 pmap->register_callback(
this);
1169 if (cap_boxes == 0) cap_boxes = 1;
1170 std::vector<ProcessID> dsts;
1175 std::stable_partition(dsts.begin(), dsts.end(),
1180 std::vector<pairT> batch;
1181 batch.reserve(std::min(cap_boxes, keys.size()));
1182 for (std::size_t i = 0; i < keys.size(); ++i)
1187 batch.push_back(
pairT(keys[i], iter->second));
1190 if (batch.size() >= cap_boxes || i + 1 == keys.size())
1194 this->
task(d, &implT::insert_batch, batch);
1229 template <
typename keyT,
typename valueT,
typename hashfunT = Hash<keyT>>
1246 std::shared_ptr<implT>
p;
1277 p->process_pending();
1289 bool do_pending =
true,
1290 const hashfunT &hf = hashfunT())
1291 :
p(new
implT(world, pmap, hf))
1294 p->process_pending();
1324 return p->get_pmap()->distribution_type();
1343 return p->get_world();
1346 std::shared_ptr<WorldDCPmapInterface<keyT>> &
get_impl()
1355 p->replicate(fence);
1361 p->replicate_on_hosts(fence);
1369 p->redistribute_coalesced_phase1(newpmap);
1378 p->redistribute_coalesced_phase2(cap_boxes, rotate);
1398 return p->find(acc, key);
1405 return p->find(acc, key);
1412 return p->insert_acc(acc, key);
1419 return p->insert_acc(acc, key);
1423 template <
typename input_iterator>
1427 using std::placeholders::_1;
1435 return p->probe(key);
1445 return p->owner(key);
1452 return p->is_local(key);
1463 return p->find(key);
1474 return const_cast<const implT *
>(
p.get())->
find(key);
1488 return const_cast<const implT *
>(
p.get())->
begin();
1502 return const_cast<const implT *
>(
p.get())->
end();
1530 p->erase(start, finish);
1550 inline const std::shared_ptr<WorldDCPmapInterface<keyT>> &
get_pmap()
const
1553 return p->get_pmap();
1559 p->reset_pmap_to_local();
1566 return p->get_hash();
1577 p->process_pending();
1589 template <
typename memfunT>
1595 (
implT::*itemfun)(
const keyT &, memfunT) = &implT::template itemfun<memfunT>;
1596 return p->send(
owner(key), itemfun, key, memfun);
1608 template <
typename memfunT,
typename arg1T>
1610 send(
const keyT &key,
const memfunT &memfun,
const arg1T &arg1)
1615 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &) = &implT::template itemfun<memfunT, arg1T>;
1616 return p->send(
owner(key), itemfun, key, memfun, arg1);
1631 template <
typename memfunT,
typename arg1T,
typename arg2T>
1633 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2)
1638 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &) = &implT::template itemfun<memfunT, arg1T, arg2T>;
1639 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2);
1653 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
1655 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3)
1659 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &,
const arg3T &) = &implT::template itemfun<memfunT, arg1T, arg2T, arg3T>;
1660 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3);
1672 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
1674 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4)
1678 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &,
const arg3T &,
const arg4T &) = &implT::template itemfun<memfunT, arg1T, arg2T, arg3T, arg4T>;
1679 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4);
1691 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
1693 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5)
1697 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &,
const arg3T &,
const arg4T &,
const arg5T &) = &implT::template itemfun<memfunT, arg1T, arg2T, arg3T, arg4T, arg5T>;
1698 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5);
1710 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
1712 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6)
1716 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &,
const arg3T &,
const arg4T &,
const arg5T &,
const arg6T &) = &implT::template itemfun<memfunT, arg1T, arg2T, arg3T, arg4T, arg5T, arg6T>;
1717 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, arg6);
1729 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
1731 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
1732 const arg5T &arg5,
const arg6T &arg6,
const arg7T &arg7)
1736 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &,
const arg3T &,
const arg4T &,
const arg5T &,
const arg6T &,
const arg7T &) = &implT::template itemfun<memfunT, arg1T, arg2T, arg3T, arg4T, arg5T, arg6T, arg7T>;
1737 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1743 template <
typename memfunT>
1753 template <
typename memfunT,
typename arg1T>
1755 send(
const keyT &key, memfunT memfun,
const arg1T &arg1)
const
1763 template <
typename memfunT,
typename arg1T,
typename arg2T>
1765 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2)
const
1767 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2);
1773 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
1775 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3)
const
1777 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3);
1783 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
1785 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4)
const
1787 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3, arg4);
1793 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
1795 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5)
const
1797 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3, arg4, arg5);
1803 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
1805 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
1806 const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6)
const
1808 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3, arg4, arg5, arg6);
1814 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
1816 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
1817 const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6,
const arg7T &arg7)
const
1819 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1832 template <
typename memfunT>
1838 (
implT::*itemfun)(
const keyT &, memfunT) = &implT::template itemfun<memfunT>;
1839 return p->task(
owner(key), itemfun, key, memfun, attr);
1852 template <
typename memfunT,
typename arg1T>
1859 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &) = &implT::template itemfun<memfunT, a1T>;
1860 return p->task(
owner(key), itemfun, key, memfun, arg1, attr);
1873 template <
typename memfunT,
typename arg1T,
typename arg2T>
1881 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &) = &implT::template itemfun<memfunT, a1T, a2T>;
1882 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, attr);
1895 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
1904 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &,
const a3T &) = &implT::template itemfun<memfunT, a1T, a2T, a3T>;
1905 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, attr);
1918 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
1928 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &,
const a3T &,
const a4T &) = &implT::template itemfun<memfunT, a1T, a2T, a3T, a4T>;
1929 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, attr);
1942 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
1953 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &,
const a3T &,
const a4T &,
const a5T &) = &implT::template itemfun<memfunT, a1T, a2T, a3T, a4T, a5T>;
1954 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, attr);
1967 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
1969 task(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6,
const TaskAttributes &attr =
TaskAttributes())
1979 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &,
const a3T &,
const a4T &,
const a5T &,
const a6T &) = &implT::template itemfun<memfunT, a1T, a2T, a3T, a4T, a5T, a6T>;
1980 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, attr);
1993 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
1995 task(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6,
const arg7T &arg7,
const TaskAttributes &attr =
TaskAttributes())
2006 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &,
const a3T &,
const a4T &,
const a5T &,
const a6T &,
const a7T &) = &implT::template itemfun<memfunT, a1T, a2T, a3T, a4T, a5T, a6T, a7T>;
2007 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, arg7, attr);
2013 template <
typename memfunT>
2023 template <
typename memfunT,
typename arg1T>
2027 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, attr);
2033 template <
typename memfunT,
typename arg1T,
typename arg2T>
2037 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, attr);
2043 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
2047 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, attr);
2053 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
2057 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, arg4, attr);
2063 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
2067 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, arg4, arg5, attr);
2073 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
2075 task(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6,
const TaskAttributes &attr =
TaskAttributes())
const
2077 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, attr);
2083 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
2085 task(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6,
const arg7T &arg7,
const TaskAttributes &attr =
TaskAttributes())
const
2087 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, arg7, attr);
2093 template <
typename Archive>
2100 const long magic = 5881828;
2101 unsigned long count = 0;
2104 if (Archive::is_output_archive)
2146#ifdef MADNESS_DISABLE_SHARED_FROM_THIS
2147 p.reset(
static_cast<implT *
>(ptr), [](
implT *p_) ->
void{});
2149 p =
static_cast<implT *
>(ptr)->shared_from_this();
2172 template <
typename keyT,
typename valueT,
typename hashfunT>
2175 std::swap(dc0.
p, dc1.
p);
2187 template <
class keyT,
class valueT>
2193 const long magic = -5881828;
2195 using const_iterator =
typename dcT::const_iterator;
2196 int count = t.
size();
2210 const_iterator start, end;
2214 op_inspector(const_iterator start, const_iterator end,
size_t &size)
2215 : start(start), end(end), size(size) {}
2217 using TaskInterface::run;
2222 for (const_iterator it = start; it != end; ++it)
2230 const_iterator start, end;
2235 op_executor(const_iterator start, const_iterator end,
unsigned char *buf,
size_t size)
2236 : start(start), end(end), buf(buf), size(size) {}
2238 using TaskInterface::run;
2243 for (const_iterator it = start; it != end; ++it)
2253 const size_t ntasks = std::min(
size_t(count), std::max(
size_t(1),
ThreadPool::size()));
2254 size_t local_size = 0;
2255 double wall1 = wall0;
2256 unsigned char* buf = 0;
2259 const size_t max_items_per_task = (std::max(1, count) - 1) / ntasks + 1;
2261 std::vector<const_iterator> starts(ntasks), ends(ntasks);
2262 std::vector<size_t> local_sizes(ntasks);
2263 const_iterator start = t.
begin();
2264 size_t nleft = count;
2265 for (
size_t taskid = 0; taskid < ntasks; taskid++)
2267 const_iterator end = start;
2268 if (taskid == (ntasks - 1))
2274 size_t nitems = std::min(max_items_per_task, nleft);
2278 starts[taskid] = start;
2280 world->
taskq.
add(
new op_inspector(start, end, local_sizes[taskid]));
2290 for (
size_t taskid = 0; taskid < ntasks; taskid++)
2292 local_size += local_sizes[taskid];
2297 buf =
new unsigned char[local_size];
2301 for (
size_t taskid = 0; taskid < ntasks; taskid++)
2303 world->
taskq.
add(
new op_executor(starts[taskid], ends[taskid], buf +
offset, local_sizes[taskid]));
2304 offset += local_sizes[taskid];
2325 const int size = local_size;
2326 std::vector<int> sizes(world->
size());
2332 std::vector<int> offsets(world->
size());
2334 for (
int i = 1; i < world->
size(); ++i)
2335 offsets[i] = offsets[i - 1] + sizes[i - 1];
2336 size_t total_size = offsets.back() + sizes.back();
2342 unsigned char *all_data = 0;
2343 if (world->
rank() == 0)
2345 all_data =
new unsigned char[total_size];
2357 if (world->
rank() == 0)
2360 localar & magic & 1;
2363 localar & -magic &(
unsigned long)(count);
2364 localar.store(all_data, total_size);
2394 template <
class keyT,
class valueT,
class localarchiveT>
2399 const long magic = -5881828;
2402 typedef typename dcT::pairT pairT;
2423 unsigned long count = 0ul;
2428 localar & cookie & count;
2454 template <
class keyT,
class valueT,
class localarchiveT>
2468 const long magic = -5881828;
2480 localar & cookie & nclient;
Group Incl(int n, const int *ranks) const
Definition safempi.h:437
Wrapper around MPI_Comm. Has a shallow copy constructor; use Create(Get_group()) for deep copy.
Definition safempi.h:497
Intracomm Create(Group group) const
Definition safempi.h:616
MPI_Comm & Get_mpi_comm() const
Definition safempi.h:716
int unique_tag()
Returns a unique tag for temporary use (1023<tag<4095)
Definition safempi.h:837
Group Get_group() const
Definition safempi.h:709
Definition worldhashmap.h:396
size_t size() const
Definition worldhashmap.h:560
iterator begin()
Definition worldhashmap.h:571
void erase(const iterator &it)
Definition worldhashmap.h:507
std::pair< iterator, bool > insert(const datumT &datum)
Definition worldhashmap.h:468
const hashfunT & get_hash() const
Definition worldhashmap.h:595
bool try_erase(const keyT &key)
Definition worldhashmap.h:502
iterator end()
Definition worldhashmap.h:583
iterator find(const keyT &key)
Definition worldhashmap.h:524
void clear()
Definition worldhashmap.h:556
Implements the functionality of futures.
Definition future.h:75
T & get(bool dowork=true)
Gets/forces the value, waiting if necessary.
Definition future.h:289
A future is a possibly yet unevaluated value.
Definition future.h:370
remote_refT remote_ref(World &world) const
Returns a structure used to pass references to another process.
Definition future.h:672
Definition worldhashmap.h:330
iterator for hash
Definition worldhashmap.h:188
Range, vaguely a la Intel TBB, to encapsulate a random-access, STL-like start and end iterator with c...
Definition range.h:64
Simple structure used to manage references/pointers to remote instances.
Definition worldref.h:395
Contains attributes of a task.
Definition thread.h:329
All world tasks must be derived from this public interface.
Definition taskfn.h:69
static std::size_t size()
Returns the number of threads in the pool.
Definition thread.h:1419
Internal implementation of distributed container to facilitate shallow copy.
Definition worlddc.h:564
void erase(const keyT &key)
Definition worlddc.h:907
WorldContainerIterator< internal_iteratorT > iterator
Definition worlddc.h:579
const hashfunT & get_hash() const
Definition worlddc.h:832
bool find(const_accessor &acc, const keyT &key) const
Definition worlddc.h:995
internal_containerT::accessor accessor
Definition worlddc.h:576
void find_handler(ProcessID requestor, const keyT &key, const RemoteReference< FutureImpl< iterator > > &ref)
Handles find request.
Definition worlddc.h:604
bool probe(const keyT &key) const
Definition worlddc.h:844
void find_success_handler(const RemoteReference< FutureImpl< iterator > > &ref, const pairT &datum)
Handles successful find response.
Definition worlddc.h:620
std::pair< const keyT, valueT > pairT
Definition worlddc.h:566
bool insert_const_acc(const_accessor &acc, const keyT &key)
Definition worlddc.h:882
void redistribute_coalesced_phase1(const std::shared_ptr< WorldDCPmapInterface< keyT > > &newpmap)
Definition worlddc.h:1150
WorldContainerIterator< internal_const_iteratorT > const_iteratorT
Definition worlddc.h:580
bool find(accessor &acc, const keyT &key)
Definition worlddc.h:988
void redistribute_phase2()
Definition worlddc.h:1123
void insert(const pairT &datum)
Definition worlddc.h:858
WorldContainerIterator< internal_iteratorT > iteratorT
Definition worlddc.h:578
void clear()
Definition worlddc.h:902
bool insert_acc(accessor &acc, const keyT &key)
Definition worlddc.h:876
Future< iterator > find(const keyT &key)
Definition worlddc.h:973
WorldContainerImpl(World &world, const std::shared_ptr< WorldDCPmapInterface< keyT > > &pm, const hashfunT &hf)
Definition worlddc.h:640
void redistribute_coalesced_phase2(std::size_t cap_boxes, bool rotate)
Definition worlddc.h:1167
void reset_pmap_to_local()
Definition worlddc.h:663
itemfun(const keyT &key, memfunT memfun)
Definition worlddc.h:1005
const pairT const_pairT
Definition worlddc.h:567
std::vector< keyT > * move_list
Tempoary used to record data that needs redistributing.
Definition worlddc.h:600
internal_containerT::iterator internal_iteratorT
Definition worlddc.h:574
WorldContainerImpl< keyT, valueT, hashfunT > implT
Definition worlddc.h:568
std::size_t size() const
Definition worlddc.h:853
void redistribute_phase1(const std::shared_ptr< WorldDCPmapInterface< keyT > > &newpmap)
Definition worlddc.h:1092
internal_containerT::const_iterator internal_const_iteratorT
Definition worlddc.h:575
std::shared_ptr< WorldDCPmapInterface< keyT > > pmap
Function/class to map from keys to owning process.
Definition worlddc.h:597
virtual ~WorldContainerImpl()
Definition worlddc.h:648
void do_replicate(World &world)
Definition worlddc.h:800
std::shared_ptr< WorldDCPmapInterface< keyT > > & get_pmap()
Definition worlddc.h:658
internal_containerT local
Locally owned data.
Definition worlddc.h:599
ConcurrentHashMap< keyT, valueT, hashfunT > internal_containerT
Definition worlddc.h:570
void insert_batch(const std::vector< pairT > &boxes)
Definition worlddc.h:892
const_iterator begin() const
Definition worlddc.h:947
void erase(InIter it)
Definition worlddc.h:923
void replicate(bool fence)
Definition worlddc.h:672
const_iterator end() const
Definition worlddc.h:957
bool is_local(const keyT &key) const
Definition worlddc.h:834
void redistribute_phase3()
Definition worlddc.h:1137
void find_failure_handler(const RemoteReference< FutureImpl< iterator > > &ref)
Handles unsuccessful find response.
Definition worlddc.h:630
ProcessID owner(const keyT &key) const
Definition worlddc.h:839
void erase(InIter first, InIter last)
Definition worlddc.h:931
void replicate_on_hosts(bool fence)
Definition worlddc.h:685
const std::shared_ptr< WorldDCPmapInterface< keyT > > & get_pmap() const
Definition worlddc.h:653
iterator begin()
Definition worlddc.h:942
Future< const_iterator > find(const keyT &key) const
Definition worlddc.h:962
const ProcessID me
My MPI rank.
Definition worlddc.h:598
iterator end()
Definition worlddc.h:952
std::map< ProcessID, std::vector< keyT > > coalesced_move_
Temporary: keys to move, bucketed by destination (coalesced redistribute)
Definition worlddc.h:601
WorldContainerIterator< internal_const_iteratorT > const_iterator
Definition worlddc.h:581
internal_containerT::const_accessor const_accessor
Definition worlddc.h:577
Iterator for distributed container wraps the local iterator.
Definition worlddc.h:414
WorldContainerIterator(const WorldContainerIterator &other)
Definition worlddc.h:443
WorldContainerIterator(const internal_iteratorT &it)
Initializes from a local iterator.
Definition worlddc.h:433
WorldContainerIterator & operator++()
Pre-increment of an iterator (i.e., ++it) — local iterators only.
Definition worlddc.h:484
std::iterator_traits< internal_iteratorT >::iterator_category iterator_category
Definition worlddc.h:416
void copy(const WorldContainerIterator< iteratorT > &other)
Definition worlddc.h:534
std::iterator_traits< internal_iteratorT >::pointer pointer
Definition worlddc.h:419
bool operator==(const WorldContainerIterator &other) const
Determines if two iterators are identical.
Definition worlddc.h:469
const internal_iteratorT & get_internal_iterator() const
Private: (or should be) Returns iterator of internal container.
Definition worlddc.h:512
WorldContainerIterator & operator=(const WorldContainerIterator &other)
Assignment.
Definition worlddc.h:462
value_type * value
holds the remote values
Definition worlddc.h:425
bool is_cached() const
Returns true if this is non-local or cached value.
Definition worlddc.h:518
WorldContainerIterator operator++(int)
Definition worlddc.h:491
WorldContainerIterator(const value_type &v)
Initializes to cache a remote value.
Definition worlddc.h:437
pointer operator->() const
Iterators dereference to std::pair<const keyT,valueT>
Definition worlddc.h:500
std::iterator_traits< internal_iteratorT >::reference reference
Definition worlddc.h:420
void serialize(const Archive &)
Definition worlddc.h:524
std::iterator_traits< internal_iteratorT >::value_type value_type
Definition worlddc.h:417
WorldContainerIterator(const WorldContainerIterator< iteratorT > &other)
Definition worlddc.h:450
WorldContainerIterator()
Default constructor makes a local uninitialized value.
Definition worlddc.h:429
internal_iteratorT it
Iterator from local container.
Definition worlddc.h:423
reference operator*() const
Iterators dereference to std::pair<const keyT,valueT>
Definition worlddc.h:506
std::iterator_traits< internal_iteratorT >::difference_type difference_type
Definition worlddc.h:418
bool operator!=(const WorldContainerIterator &other) const
Determines if two iterators are different.
Definition worlddc.h:476
~WorldContainerIterator()
Definition worlddc.h:456
Makes a distributed container with specified attributes.
Definition worlddc.h:1231
void process_pending()
Process pending messages.
Definition worlddc.h:1574
WorldContainer(World &world, bool do_pending=true, const hashfunT &hf=hashfunT())
Makes an initialized, empty container with default data distribution (no communication)
Definition worlddc.h:1271
const hashfunT & get_hash() const
Returns a reference to the hashing functor.
Definition worlddc.h:1563
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:1395
bool probe(const keyT &key) const
Returns true if local data is immediately available (no communication)
Definition worlddc.h:1432
void redistribute_coalesced_phase2(std::size_t cap_boxes, bool rotate=true)
Definition worlddc.h:1375
const_iterator begin() const
Returns an iterator to the beginning of the local data (no communication)
Definition worlddc.h:1485
void replace(const keyT &key, const valueT &value)
Inserts/replaces key+value pair (non-blocking communication if key not local)
Definition worlddc.h:1389
bool insert(const_accessor &acc, const keyT &key)
Read access to LOCAL value by key. Returns true if inserted, false if already exists (throws if remot...
Definition worlddc.h:1416
iterator begin()
Returns an iterator to the beginning of the local data (no communication)
Definition worlddc.h:1478
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const TaskAttributes &attr=TaskAttributes()) const
Adds task "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T) const" in process owning item (non-blocking ...
Definition worlddc.h:2065
WorldContainer(World &world, const std::shared_ptr< WorldDCPmapInterface< keyT > > &pmap, bool do_pending=true, const hashfunT &hf=hashfunT())
Makes an initialized, empty container (no communication)
Definition worlddc.h:1287
Future< iterator > find(const keyT &key)
Returns a future iterator (non-blocking communication if key not local)
Definition worlddc.h:1460
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6) const
Sends message "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T,arg6T) const" to item (non-blocking comm ...
Definition worlddc.h:1805
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6, const arg7T &arg7) const
Sends message "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T,arg6T,arg7T) const" to item (non-blocking...
Definition worlddc.h:1816
Future< const_iterator > const_futureT
Definition worlddc.h:1243
bool is_replicated() const
Definition worlddc.h:1331
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const TaskAttributes &attr=TaskAttributes())
Adds task "resultT memfun(arg1T)" in process owning item (non-blocking comm if remote)
Definition worlddc.h:1854
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5) const
Sends message "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T) const" to item (non-blocking comm if rem...
Definition worlddc.h:1795
ProcessID owner(const keyT &key) const
Returns processor that logically owns key (no communication)
Definition worlddc.h:1442
implT::const_iterator const_iterator
Definition worlddc.h:1239
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const TaskAttributes &attr=TaskAttributes()) const
Adds task "resultT memfun(arg1T,arg2T) const" in process owning item (non-blocking comm if remote)
Definition worlddc.h:2035
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const TaskAttributes &attr=TaskAttributes()) const
Adds task "resultT memfun() const" in process owning item (non-blocking comm if remote)
Definition worlddc.h:2015
WorldContainer()
Makes an uninitialized container (no communication)
Definition worlddc.h:1259
void serialize(const archive::BufferOutputArchive &ar)
(de)Serialize — !! ONLY for purpose of interprocess communication
Definition worlddc.h:2131
keyT key_type
Definition worlddc.h:1234
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3)
Sends message "resultT memfun(arg1T,arg2T,arg3T)" to item (non-blocking comm if remote)
Definition worlddc.h:1655
void replicate(bool fence=true)
replicates this WorldContainer on all ProcessIDs
Definition worlddc.h:1353
virtual ~WorldContainer()
Destructor passes ownership of implementation to world for deferred cleanup.
Definition worlddc.h:2161
void erase(const keyT &key)
Erases entry from container (non-blocking comm if remote)
Definition worlddc.h:1513
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5)
Sends message "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T)" to item (non-blocking comm if remote)
Definition worlddc.h:1693
void reset_pmap_to_local()
Returns shared pointer to the process mapping.
Definition worlddc.h:1557
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, const memfunT &memfun, const arg1T &arg1)
Sends message "resultT memfun(arg1T)" to item (non-blocking comm if remote)
Definition worlddc.h:1610
const uniqueidT & id() const
Returns the associated unique id ... must be initialized.
Definition worlddc.h:2154
void redistribute_coalesced_phase1(const std::shared_ptr< WorldDCPmapInterface< keyT > > &newpmap)
Definition worlddc.h:1366
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6, const arg7T &arg7, const TaskAttributes &attr=TaskAttributes())
Adds task "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T,arg6T,arg7T)" in process owning item (non-blo...
Definition worlddc.h:1995
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const TaskAttributes &attr=TaskAttributes())
Adds task "resultT memfun(arg1T,arg2T)" in process owning item (non-blocking comm if remote)
Definition worlddc.h:1875
WorldContainerImpl< keyT, valueT, hashfunT > implT
Definition worlddc.h:1236
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2) const
Sends message "resultT memfun(arg1T,arg2T) const" to item (non-blocking comm if remote)
Definition worlddc.h:1765
void replace(const pairT &datum)
Inserts/replaces key+value pair (non-blocking communication if key not local)
Definition worlddc.h:1382
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const TaskAttributes &attr=TaskAttributes()) const
Adds task "resultT memfun(arg1T,arg2T,arg3T) const" in process owning item (non-blocking comm if remo...
Definition worlddc.h:2045
iterator end()
Returns an iterator past the end of the local data (no communication)
Definition worlddc.h:1492
const std::shared_ptr< WorldDCPmapInterface< keyT > > & get_pmap() const
Returns shared pointer to the process mapping.
Definition worlddc.h:1550
std::shared_ptr< WorldDCPmapInterface< keyT > > & get_impl()
Definition worlddc.h:1346
void replace(input_iterator &start, input_iterator &end)
Inserts pairs (non-blocking communication if key(s) not local)
Definition worlddc.h:1424
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const TaskAttributes &attr=TaskAttributes()) const
Adds task "resultT memfun(arg1T) const" in process owning item (non-blocking comm if remote)
Definition worlddc.h:2025
bool insert(accessor &acc, const keyT &key)
Write access to LOCAL value by key. Returns true if inserted, false if already exists (throws if remo...
Definition worlddc.h:1409
Future< iterator > futureT
Definition worlddc.h:1242
void erase(const iterator &it)
Erases entry corresponding to local iterator (no communication)
Definition worlddc.h:1520
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const TaskAttributes &attr=TaskAttributes()) const
Adds task "resultT memfun(arg1T,arg2T,arg3T, arg4T) const" in process owning item (non-blocking comm ...
Definition worlddc.h:2055
void erase(const iterator &start, const iterator &finish)
Erases range defined by local iterators (no communication)
Definition worlddc.h:1527
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4) const
Sends message "resultT memfun(arg1T,arg2T,arg3T,arg4T) const" to item (non-blocking comm if remote)
Definition worlddc.h:1785
bool is_distributed() const
Definition worlddc.h:1327
WorldContainer(const WorldContainer &other)
Copy constructor is shallow (no communication)
Definition worlddc.h:1301
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6, const TaskAttributes &attr=TaskAttributes())
Adds task "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T,arg6T)" in process owning item (non-blocking ...
Definition worlddc.h:1969
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6, const arg7T &arg7)
Sends message "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T,arg6T,arg7T)" to item (non-blocking comm ...
Definition worlddc.h:1731
World & get_world() const
Returns the world associated with this container.
Definition worlddc.h:1340
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun) const
Sends message "resultT memfun() const" to item (non-blocking comm if remote)
Definition worlddc.h:1745
implT::iterator iterator
Definition worlddc.h:1238
DistributionType get_distribution_type() const
return the way data is distributed
Definition worlddc.h:1322
implT::pairT pairT
Definition worlddc.h:1237
std::size_t size() const
Returns the number of local entries (no communication)
Definition worlddc.h:1543
containerT & operator=(const containerT &other)
Assignment is shallow (no communication)
Definition worlddc.h:1311
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const TaskAttributes &attr=TaskAttributes())
Adds task "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T)" in process owning item (non-blocking comm i...
Definition worlddc.h:1944
bool find(const_accessor &acc, const keyT &key) const
Read access to LOCAL value by key. Returns true if found, false otherwise (always false for remote).
Definition worlddc.h:1402
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const TaskAttributes &attr=TaskAttributes())
Adds task "resultT memfun(arg1T,arg2T,arg3T)" in process owning item (non-blocking comm if remote)
Definition worlddc.h:1897
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4)
Sends message "resultT memfun(arg1T,arg2T,arg3T,arg4T)" to item (non-blocking comm if remote)
Definition worlddc.h:1674
void serialize(const archive::BufferInputArchive &ar)
(de)Serialize — !! ONLY for purpose of interprocess communication
Definition worlddc.h:2140
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:1834
bool is_local(const keyT &key) const
Returns true if the key maps to the local processor (no communication)
Definition worlddc.h:1449
const_iterator end() const
Returns an iterator past the end of the local data (no communication)
Definition worlddc.h:1499
void serialize(const Archive &ar)
(de)Serialize — Local data only to/from anything except Buffer*Archive and Parallel*Archive
Definition worlddc.h:2094
bool is_host_replicated() const
Definition worlddc.h:1335
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6, const TaskAttributes &attr=TaskAttributes()) const
Adds task "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T,arg6T) const" in process owning item (non-blo...
Definition worlddc.h:2075
void clear()
Clears all local data (no communication)
Definition worlddc.h:1536
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const TaskAttributes &attr=TaskAttributes())
Adds task "resultT memfun(arg1T,arg2T,arg3T,arg4T)" in process owning item (non-blocking comm if remo...
Definition worlddc.h:1920
Future< MEMFUN_RETURNT(memfunT)> send(const keyT &key, memfunT memfun)
Sends message "resultT memfun()" to item (non-blocking comm if remote)
Definition worlddc.h:1591
implT::const_accessor const_accessor
Definition worlddc.h:1241
std::shared_ptr< implT > p
Definition worlddc.h:1246
Future< const_iterator > find(const keyT &key) const
Returns a future iterator (non-blocking communication if key not local)
Definition worlddc.h:1471
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3) const
Sends message "resultT memfun(arg1T,arg2T,arg3T) const" to item (non-blocking comm if remote)
Definition worlddc.h:1775
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6)
Sends message "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T,arg6T)" to item (non-blocking comm if rem...
Definition worlddc.h:1712
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2)
Sends message "resultT memfun(arg1T,arg2T)" to item (non-blocking comm if remote)
Definition worlddc.h:1633
void replicate_on_hosts(bool fence=true)
replicates this WorldContainer on all hosts (one PID per host)
Definition worlddc.h:1359
void check_initialized() const
Definition worlddc.h:1248
WorldContainer< keyT, valueT, hashfunT > containerT
Definition worlddc.h:1235
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> task(const keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6, const arg7T &arg7, const TaskAttributes &attr=TaskAttributes()) const
Adds task "resultT memfun(arg1T,arg2T,arg3T,arg4T,arg5T,arg6T,arg7T) const" in process owning item (n...
Definition worlddc.h:2085
Future< REMFUTURE(MEMFUN_RETURNT(memfunT))> send(const keyT &key, memfunT memfun, const arg1T &arg1) const
Sends message "resultT memfun(arg1T) const" to item (non-blocking comm if remote)
Definition worlddc.h:1755
implT::accessor accessor
Definition worlddc.h:1240
Default process map is "random" using madness::hash(key)
Definition worlddc.h:261
ProcessID owner(const keyT &key) const
Maps key to processor.
Definition worlddc.h:272
WorldDCDefaultPmap(World &world, const hashfunT &hf=hashfunT())
Definition worlddc.h:267
const int nproc
Definition worlddc.h:263
hashfunT hashfun
Definition worlddc.h:264
Local process map will always return the current process as owner.
Definition worlddc.h:285
ProcessID owner(const keyT &key) const override
Maps key to processor.
Definition worlddc.h:291
WorldDCLocalPmap(World &world)
Definition worlddc.h:290
ProcessID me
Definition worlddc.h:287
DistributionType distribution_type() const override
by default the map is distributed
Definition worlddc.h:296
DistributionType distribution_type() const override
by default the map is distributed
Definition worlddc.h:339
WorldDCNodeReplicatedPmap(World &world, const std::map< std::string, std::vector< long > > ranks_per_host)
Definition worlddc.h:330
ProcessID myowner
Definition worlddc.h:324
ProcessID owner(const keyT &key) const override
owner is the lowest rank on the node, same for all keys
Definition worlddc.h:335
Interface to be provided by any process map.
Definition worlddc.h:125
void redistribute(World &world, const std::shared_ptr< WorldDCPmapInterface< keyT > > &newpmap)
Invoking this switches all registered objects from this process map to the new one.
Definition worlddc.h:180
virtual DistributionType distribution_type() const
by default the map is distributed
Definition worlddc.h:145
virtual ProcessID single_owner() const
Definition worlddc.h:153
void print_data_sizes(World &world, const std::string msg="") const
Prints size info to std::cout.
Definition worlddc.h:236
std::size_t global_size(World &world) const
Counts global number of entries in all containers associated with this process map.
Definition worlddc.h:213
virtual ProcessID owner(const keyT &key) const =0
Maps key to processor.
void deregister_callback(ptrT ptr)
Deregisters object for receipt of redistribute callbacks.
Definition worlddc.h:169
void register_callback(ptrT ptr)
Registers object for receipt of redistribute callbacks.
Definition worlddc.h:161
virtual void print() const
Definition worlddc.h:142
std::size_t local_size() const
Counts local number of entries in all containers associated with this process map.
Definition worlddc.h:223
std::set< ptrT > ptrs
Definition worlddc.h:131
virtual ~WorldDCPmapInterface()
Definition worlddc.h:140
WorldDCRedistributeInterface< keyT > * ptrT
Definition worlddc.h:127
virtual void redistribute_phase3()=0
virtual std::size_t size() const =0
virtual void redistribute_phase2()=0
virtual void redistribute_phase1(const std::shared_ptr< WorldDCPmapInterface< keyT > > &newmap)=0
virtual ~WorldDCRedistributeInterface()
Definition worlddc.h:80
WorldDCSingleOwnerPmap(ProcessID owner)
Definition worlddc.h:314
const ProcessID owner_
Definition worlddc.h:311
ProcessID owner(const keyT &) const override
Maps key to processor.
Definition worlddc.h:315
ProcessID single_owner() const override
Definition worlddc.h:316
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
SafeMPI::Intracomm & comm()
Returns the associated SafeMPI communicator.
Definition worldmpi.h:286
void Send(const T *buf, long lenbuf, int dest, int tag=SafeMPI::DEFAULT_SEND_RECV_TAG) const
Send array of lenbuf elements to process dest.
Definition worldmpi.h:347
void Recv(T *buf, long lenbuf, int src, int tag) const
Receive data of up to lenbuf elements from process src.
Definition worldmpi.h:374
Implements most parts of a globally addressable object (via unique ID).
Definition world_object.h:491
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn) const
Definition world_object.h:858
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method returnT (this->*memfn)().
Definition world_object.h:1132
Future< bool > for_each(const rangeT &range, const opT &op)
Apply op(item) on all items in range.
Definition world_task_queue.h:572
void add(TaskInterface *t)
Add a new local task, taking ownership of the pointer.
Definition world_task_queue.h:466
void fence()
Returns after all local tasks have completed.
Definition world_task_queue.h:1384
A parallel world class.
Definition world.h:134
WorldTaskQueue & taskq
Task queue.
Definition world.h:215
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:344
WorldMpiInterface & mpi
MPI interface.
Definition world.h:213
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
bool dofence() const
Check if we should fence around a read/write operation.
Definition parallel_archive.h:295
World * get_world() const
Returns a pointer to the world.
Definition parallel_archive.h:130
bool is_io_node() const
Returns true if this node is doing physical I/O.
Definition parallel_archive.h:122
int num_io_clients() const
Returns the number of I/O clients for this node, including self (zero if not an I/O node).
Definition parallel_archive.h:114
ProcessID io_node(ProcessID rank) const
Returns the process doing I/O for given node.
Definition parallel_archive.h:99
ProcessID my_io_node() const
Returns the process doing I/O for this node.
Definition parallel_archive.h:106
Archive & local_archive() const
Returns a reference to the local archive.
Definition parallel_archive.h:248
Wraps an archive around a memory buffer for output.
Definition buffer_archive.h:59
std::size_t size() const
Return the amount of data stored (counted) in the buffer.
Definition buffer_archive.h:123
Archive allowing buffering, serialization of data, and point-to-point communication between processes...
Definition mpi_archive.h:118
void flush() const
Send all data in the buffer to the destination process.
Definition mpi_archive.h:158
An archive for storing local or parallel data wrapping a BinaryFstreamOutputArchive.
Definition parallel_archive.h:321
Objects that implement their own parallel archive interface should derive from this class.
Definition parallel_archive.h:58
Wraps an archive around an STL vector for output.
Definition vector_archive.h:55
Class for unique global IDs.
Definition uniqueid.h:53
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
void run(World &world, ansatzT ansatz, const int nuclear_charge, const commandlineparser &parser, const int nstates)
Definition dirac-hatom.cc:1392
static void load(const ParallelInputArchive< localarchiveT > &ar, WorldContainer< keyT, valueT > &t)
Read container from parallel archive.
Definition worlddc.h:2466
static const double v
Definition hatom_sf_dirac.cc:20
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:182
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
Implements archives to serialize data for MPI.
void deferred_cleanup(World &world, const std::shared_ptr< objT > &p, bool assume_p_is_unique=false)
Defer the cleanup of a shared pointer to the end of the next fence.
Definition deferred_cleanup.h:135
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:13
DistributionType from_string(std::string type)
Definition worlddc.h:106
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:401
std::string to_string(const Representation r)
Definition Restart.h:64
DistributionType
some introspection of how data is distributed
Definition worlddc.h:84
@ NodeReplicated
even if there are several ranks per node
Definition worlddc.h:87
@ Distributed
no replication of the container, the container is distributed over the world
Definition worlddc.h:85
@ RankReplicated
replicate the container over all world ranks
Definition worlddc.h:86
std::vector< int > primary_ranks_per_host(World &world, const std::map< std::string, std::vector< long > > &ranks_per_host1)
Definition ranks_and_hosts.cpp:94
DistributionType validate_distribution_type(const dcT &dc)
check distribution type of WorldContainer – global communication
Definition worlddc.h:347
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:2620
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition timers.cc:48
std::string type(const PairType &n)
Definition PNOParameters.h:18
long lowest_rank_on_host_of_rank(const std::map< std::string, std::vector< long > > ranks_per_host1, int rank)
Definition ranks_and_hosts.cpp:81
std::map< std::string, std::vector< long > > ranks_per_host(World &universe)
for each host, return a list of its ranks
Definition ranks_and_hosts.cpp:60
void swap(Function< R, MDIM > &f1, Function< R, MDIM > &f2)
Definition mra.h:2952
void advance(madness::Hash_private::HashIterator< hashT > &it, const distT &dist)
Definition worldhashmap.h:610
static const double d
Definition nonlinschro.cc:121
Implements ParallelInputArchive and ParallelOutputArchive for parallel serialization of data.
static const double c
Definition relops.cc:10
Definition worlddc.h:1104
bool operator()(typename rangeT::iterator &iterator) const
Definition worlddc.h:1109
implT * impl
Definition worlddc.h:1105
P2Op(const P2Op &p)
Definition worlddc.h:1108
P2Op(implT *impl)
Definition worlddc.h:1107
Range< typename std::vector< keyT >::const_iterator > rangeT
Definition worlddc.h:1106
World & world
Memoized reference to the world to which this object belongs.
Definition world_object.h:348
World & get_world() const
Definition world_object.h:446
Default load of an object via serialize(ar, t).
Definition archive.h:667
static void postamble_store(const Archive &)
By default there is no postamble.
Definition archive.h:546
static void preamble_store(const Archive &ar)
Serialize a cookie for type checking.
Definition archive.h:536
static void store(const ParallelOutputArchive< VectorOutputArchive > &ar, const WorldContainer< keyT, valueT > &t)
Definition worlddc.h:2190
static void store(const ParallelOutputArchive< localarchiveT > &ar, const WorldContainer< keyT, valueT > &t)
Definition worlddc.h:2397
Default store of an object via serialize(ar, t).
Definition archive.h:612
int MPI_Gatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int recvcounts[], const int[], MPI_Datatype recvtype, int, MPI_Comm)
Definition stubmpi.h:218
#define MPI_INT
Definition stubmpi.h:81
#define MPI_BYTE
Definition stubmpi.h:77
int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
Definition stubmpi.h:233
AtomicInt sum
Definition test_atomicint.cc:46
std::pair< int, double > valueT
Definition test_binsorter.cc:6
int me
Definition test_binsorter.cc:10
const double offset
Definition testfuns.cc:143
double source(const coordT &r)
Definition testperiodic.cc:48
#define REMFUTURE(T)
Macro to determine type of future (by removing wrapping Future template).
Definition type_traits.h:163
#define MEMFUN_RETURNT(MEMFUN)
Macro to make member function type traits easier to use.
Definition type_traits.h:773
Defines and implements WorldObject.
Defines and implements a concurrent hashmap.
int ProcessID
Used to clearly identify process number/rank.
Definition worldtypes.h:43
int Tag
Used to clearly identify message tag/type.
Definition worldtypes.h:44