32#ifndef MADNESS_WORLD_WORLDDC_H__INCLUDED
33#define MADNESS_WORLD_WORLDDC_H__INCLUDED
51#include <unordered_set>
63 template <
typename keyT,
typename valueT,
typename hashfunT>
66 template <
typename keyT,
typename valueT,
typename hashfunT>
69 template <
typename keyT,
typename valueT,
typename hashfunT>
72 template <
typename keyT>
75 template <
typename keyT>
79 virtual std::size_t
size()
const = 0;
94 template<
typename T=
long>
102 template<
typename T=
long>
104 std::stringstream ss; ss <<
type;
108 template<
typename T=
long>
111 std::transform(
type.begin(),
type.end(),
type.begin(), [](
unsigned char c){ return std::tolower(c); });
115 std::string msg=
"unknown distribution type:"+
type;
126 template <
typename keyT>
187 for (
typename std::set<ptrT>::iterator iter =
ptrs.begin();
191 (*iter)->redistribute_phase1(newpmap);
194 for (
typename std::set<ptrT>::iterator iter =
ptrs.begin();
198 (*iter)->redistribute_phase2();
199 newpmap->register_callback(*iter);
202 for (
typename std::set<ptrT>::iterator iter =
ptrs.begin();
206 (*iter)->redistribute_phase3();
210 newpmap->print_data_sizes(world,
"after redistributing");
229 for (
typename std::set<ptrT>::iterator iter =
ptrs.begin(); iter !=
ptrs.end(); ++iter)
231 sum += (*iter)->size();
243 std::vector<std::size_t> sizes(world.
size());
246 if (world.
rank() == 0)
250 std::cout <<
" procs: ";
251 for (
int i = 0; i < world.
size(); i++)
252 std::cout << sizes[i] <<
" ";
253 std::cout << std::endl;
262 template <
typename keyT,
typename hashfunT = Hash<keyT>>
286 template <
typename keyT,
typename hashfunT = Hash<keyT>>
310 template <
typename keyT>
325 template <
typename keyT,
typename hashfunT = Hash<keyT>>
349 template <
typename dcT>
353 World& world=dc.get_world();
354 auto result= dc.get_pmap()->distribution_type();
356 auto local_size=dc.
size();
357 auto global_size=local_size;
358 world.
gop.
sum(global_size);
360 auto number_of_duplicates = [](
const std::vector<hashT>&
v) {
361 std::unordered_map<hashT, size_t> counts;
362 size_t duplicates = 0;
363 for (
const auto& elem :
v) {
364 if (++counts[elem] > 1) duplicates++;
370 std::vector<hashT> all_hashes(local_size);
371 const auto& hashfun=dc.get_hash();
373 for (
auto it=dc.begin();it!=dc.end();++it,++i) all_hashes[i]=hashfun(it->first);
375 std::size_t ndup=number_of_duplicates(all_hashes);
386 std::size_t nrank=world.
size();
396 print(
"primary_rank_per_host",primary_ranks);
398 std::size_t nnodes=primary_ranks.size();
399 bool is_primary=(std::find(primary_ranks.begin(),primary_ranks.end(),world.
rank())!=primary_ranks.end());
402 MADNESS_CHECK_THROW(global_size==(nnodes*local_size),
"WorldDC inconsistent - global size");
415 template <
class internal_iteratorT>
420 typedef typename std::iterator_traits<internal_iteratorT>::value_type
value_type;
421 typedef typename std::iterator_traits<internal_iteratorT>::difference_type
difference_type;
422 typedef typename std::iterator_traits<internal_iteratorT>::pointer
pointer;
423 typedef typename std::iterator_traits<internal_iteratorT>::reference
reference;
426 internal_iteratorT
it;
452 template <
class iteratorT>
481 return !(*
this == other);
523 return value !=
nullptr;
526 template <
typename Archive>
533 template <
class iteratorT>
536 template <
class iteratorT>
539 if (
static_cast<const void *
>(
this) !=
static_cast<const void *
>(&other))
545 it = internal_iteratorT();
559 template <
typename keyT,
typename valueT,
typename hashfunT>
561 :
public WorldObject<WorldContainerImpl<keyT, valueT, hashfunT>>,
563#ifndef MADNESS_DISABLE_SHARED_FROM_THIS
565 public std::enable_shared_from_this<WorldContainerImpl<keyT, valueT, hashfunT>>
569 typedef typename std::pair<const keyT, valueT>
pairT;
600 std::shared_ptr<WorldDCPmapInterface<keyT>>
pmap;
611 if (r ==
local.end())
647 if (r ==
local.end())
677 pmap->register_callback(
this);
682 pmap->deregister_callback(
this);
685 const std::shared_ptr<WorldDCPmapInterface<keyT>> &
get_pmap()
const
690 std::shared_ptr<WorldDCPmapInterface<keyT>> &
get_pmap()
698 pmap->deregister_callback(
this);
700 pmap->register_callback(
this);
720 world.gop.min(complete);
723 if (fence)
world.gop.fence();
727 pmap->deregister_callback(
this);
729 pmap->register_callback(
this);
733 if (fence)
world.gop.fence();
761 world.gop.broadcast_serializable(primary_ranks,0);
774 pmap->deregister_callback(
this);
776 pmap->register_callback(
this);
779 if (
world.size()==1) {
781 pmap->deregister_callback(
this);
783 pmap->register_callback(
this);
789 std::vector<int> secondary_ranks;
790 for (
int r=0; r<
world.size(); ++r) {
791 if (std::find(primary_ranks.begin(),primary_ranks.end(),r)==primary_ranks.end())
792 secondary_ranks.push_back(r);
800 if (
world.rank() != myowner) {
802 for (
auto it =
begin(); it !=
end(); ++it) {
803 keyT key = it->first;
820 pmap->deregister_callback(
this);
822 pmap->register_callback(
this);
825 bool i_am_in_primary_list=
world.rank()==myowner;
826 if (i_am_in_primary_list) {
830 SafeMPI::Group primary_group =
world.mpi.comm().Get_group().Incl(primary_ranks.size(), &primary_ranks[0]);
834 World world_primary(comm_primary);
847 SafeMPI::Group secondary_group =
world.mpi.comm().Get_group().Incl(secondary_ranks.size(), &secondary_ranks[0]);
852 if (fence)
world.gop.fence();
861 std::vector<pairT> received;
864 if (rank ==
world.rank())
866 std::size_t sz =
size();
867 world.gop.broadcast_serializable(sz, rank);
869 for (
auto it =
begin(); it !=
end(); ++it)
871 keyT key = it->first;
873 world.gop.broadcast_serializable(key, rank);
874 world.gop.broadcast_serializable(
value, rank);
880 world.gop.broadcast_serializable(sz, rank);
881 received.reserve(received.size() + sz);
882 for (
size_t i = 0; i < sz; i++)
886 world.gop.broadcast_serializable(key, rank);
887 world.gop.broadcast_serializable(
value, rank);
888 received.emplace_back(std::move(key), std::move(
value));
892 for (
auto& datum : received)
905 return pmap->owner(key);
930 [[maybe_unused]]
auto inserted =
local.insert(acc, datum.first);
931 acc->second = datum.second;
943 return local.insert(acc, key);
949 return local.insert(acc, key);
958 for (
const pairT &kv : boxes)
961 [[maybe_unused]]
auto inserted =
local.insert(acc, kv.first);
962 acc->second = kv.second;
977 [[maybe_unused]]
auto erased =
local.try_erase(key);
983 this->
send(dest, eraser, key);
987 template <
typename InIter>
995 template <
typename InIter>
996 void erase(InIter first, InIter last)
1004 }
while (first != last);
1061 return local.find(acc, key);
1068 return local.find(acc, key);
1072 template <
typename memfunT>
1078 [[maybe_unused]]
auto inserted =
local.insert(acc, key);
1079 return (acc->second.*memfun)();
1083 template <
typename memfunT,
typename arg1T>
1089 [[maybe_unused]]
auto inserted =
local.insert(acc, key);
1090 return (acc->second.*memfun)(arg1);
1094 template <
typename memfunT,
typename arg1T,
typename arg2T>
1096 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2)
1100 [[maybe_unused]]
auto inserted =
local.insert(acc, key);
1101 return (acc->second.*memfun)(arg1, arg2);
1105 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
1107 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3)
1111 [[maybe_unused]]
auto inserted =
local.insert(acc, key);
1112 return (acc->second.*memfun)(arg1, arg2, arg3);
1116 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
1118 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4)
1122 [[maybe_unused]]
auto inserted =
local.insert(acc, key);
1123 return (acc->second.*memfun)(arg1, arg2, arg3, arg4);
1127 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
1129 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5)
1133 [[maybe_unused]]
auto inserted =
local.insert(acc, key);
1134 return (acc->second.*memfun)(arg1, arg2, arg3, arg4, arg5);
1138 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
1140 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3, const arg4T &arg4, const arg5T &arg5, const arg6T &arg6)
1144 [[maybe_unused]]
auto inserted =
local.insert(acc, key);
1145 return (acc->second.*memfun)(arg1, arg2, arg3, arg4, arg5, arg6);
1149 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
1151 itemfun(const
keyT &key, memfunT memfun, const arg1T &arg1, const arg2T &arg2, const arg3T &arg3,
1152 const arg4T &arg4, const arg5T &arg5, const arg6T &arg6, const arg7T &arg7)
1156 [[maybe_unused]]
auto inserted =
local.insert(acc, key);
1157 return (acc->second.*memfun)(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1187 impl->local.erase(iter);
1223 pmap->deregister_callback(
this);
1225 pmap->register_callback(
this);
1240 if (cap_boxes == 0) cap_boxes = 1;
1241 std::vector<ProcessID> dsts;
1246 std::stable_partition(dsts.begin(), dsts.end(),
1251 std::vector<pairT> batch;
1252 batch.reserve(std::min(cap_boxes, keys.size()));
1253 for (std::size_t i = 0; i < keys.size(); ++i)
1256 if (iter !=
local.end())
1258 batch.push_back(
pairT(keys[i], iter->second));
1261 if (batch.size() >= cap_boxes || i + 1 == keys.size())
1300 template <
typename keyT,
typename valueT,
typename hashfunT = Hash<keyT>>
1317 std::shared_ptr<implT>
p;
1348 p->process_pending();
1360 bool do_pending =
true,
1361 const hashfunT &hf = hashfunT())
1365 p->process_pending();
1395 return p->get_pmap()->distribution_type();
1414 return p->get_world();
1417 std::shared_ptr<WorldDCPmapInterface<keyT>> &
get_impl()
1429 p->replicate(fence);
1435 p->replicate_on_hosts(fence);
1443 p->redistribute_coalesced_phase1(newpmap);
1452 p->redistribute_coalesced_phase2(cap_boxes, rotate);
1472 return p->find(acc, key);
1479 return p->find(acc, key);
1486 return p->insert_acc(acc, key);
1493 return p->insert_acc(acc, key);
1497 template <
typename input_iterator>
1501 using std::placeholders::_1;
1509 return p->probe(key);
1519 return p->owner(key);
1526 return p->is_local(key);
1537 return p->find(key);
1548 return const_cast<const implT *
>(
p.get())->find(key);
1562 return const_cast<const implT *
>(
p.get())->begin();
1576 return const_cast<const implT *
>(
p.get())->end();
1604 p->erase(start, finish);
1624 inline const std::shared_ptr<WorldDCPmapInterface<keyT>> &
get_pmap()
const
1627 return p->get_pmap();
1633 p->reset_pmap_to_local();
1640 return p->get_hash();
1651 p->process_pending();
1663 template <
typename memfunT>
1669 (
implT::*itemfun)(
const keyT &, memfunT) = &implT::template itemfun<memfunT>;
1670 return p->send(
owner(key), itemfun, key, memfun);
1682 template <
typename memfunT,
typename arg1T>
1684 send(
const keyT &key,
const memfunT &memfun,
const arg1T &arg1)
1689 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &) = &implT::template itemfun<memfunT, arg1T>;
1690 return p->send(
owner(key), itemfun, key, memfun, arg1);
1705 template <
typename memfunT,
typename arg1T,
typename arg2T>
1707 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2)
1712 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &) = &implT::template itemfun<memfunT, arg1T, arg2T>;
1713 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2);
1727 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
1729 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3)
1733 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &,
const arg3T &) = &implT::template itemfun<memfunT, arg1T, arg2T, arg3T>;
1734 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3);
1746 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
1748 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4)
1752 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &,
const arg3T &,
const arg4T &) = &implT::template itemfun<memfunT, arg1T, arg2T, arg3T, arg4T>;
1753 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4);
1765 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
1767 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5)
1771 (
implT::*itemfun)(
const keyT &, memfunT,
const arg1T &,
const arg2T &,
const arg3T &,
const arg4T &,
const arg5T &) = &implT::template itemfun<memfunT, arg1T, arg2T, arg3T, arg4T, arg5T>;
1772 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5);
1784 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
1786 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6)
1790 (
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>;
1791 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, arg6);
1803 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
1805 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
1806 const arg5T &arg5,
const arg6T &arg6,
const arg7T &arg7)
1810 (
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>;
1811 return p->send(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1817 template <
typename memfunT>
1827 template <
typename memfunT,
typename arg1T>
1829 send(
const keyT &key, memfunT memfun,
const arg1T &arg1)
const
1837 template <
typename memfunT,
typename arg1T,
typename arg2T>
1839 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2)
const
1841 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2);
1847 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
1849 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3)
const
1851 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3);
1857 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
1859 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4)
const
1861 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3, arg4);
1867 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
1869 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
const arg4T &arg4,
const arg5T &arg5)
const
1871 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3, arg4, arg5);
1877 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
1879 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
1880 const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6)
const
1882 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3, arg4, arg5, arg6);
1888 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
1890 send(
const keyT &key, memfunT memfun,
const arg1T &arg1,
const arg2T &arg2,
const arg3T &arg3,
1891 const arg4T &arg4,
const arg5T &arg5,
const arg6T &arg6,
const arg7T &arg7)
const
1893 return const_cast<containerT *
>(
this)->
send(key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1906 template <
typename memfunT>
1912 (
implT::*itemfun)(
const keyT &, memfunT) = &implT::template itemfun<memfunT>;
1913 return p->task(
owner(key), itemfun, key, memfun, attr);
1926 template <
typename memfunT,
typename arg1T>
1933 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &) = &implT::template itemfun<memfunT, a1T>;
1934 return p->task(
owner(key), itemfun, key, memfun, arg1, attr);
1947 template <
typename memfunT,
typename arg1T,
typename arg2T>
1955 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &) = &implT::template itemfun<memfunT, a1T, a2T>;
1956 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, attr);
1969 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
1978 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &,
const a3T &) = &implT::template itemfun<memfunT, a1T, a2T, a3T>;
1979 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, attr);
1992 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
2002 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &,
const a3T &,
const a4T &) = &implT::template itemfun<memfunT, a1T, a2T, a3T, a4T>;
2003 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, attr);
2016 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
2027 (
implT::*itemfun)(
const keyT &, memfunT,
const a1T &,
const a2T &,
const a3T &,
const a4T &,
const a5T &) = &implT::template itemfun<memfunT, a1T, a2T, a3T, a4T, a5T>;
2028 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, attr);
2041 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
2043 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())
2053 (
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>;
2054 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, attr);
2067 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
2069 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())
2080 (
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>;
2081 return p->task(
owner(key), itemfun, key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, arg7, attr);
2087 template <
typename memfunT>
2097 template <
typename memfunT,
typename arg1T>
2101 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, attr);
2107 template <
typename memfunT,
typename arg1T,
typename arg2T>
2111 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, attr);
2117 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T>
2121 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, attr);
2127 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T>
2131 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, arg4, attr);
2137 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T>
2141 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, arg4, arg5, attr);
2147 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T>
2149 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
2151 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, attr);
2157 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
typename arg5T,
typename arg6T,
typename arg7T>
2159 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
2161 return const_cast<containerT *
>(
this)->
task(key, memfun, arg1, arg2, arg3, arg4, arg5, arg6, arg7, attr);
2167 template <
typename Archive>
2174 const long magic = 5881828;
2175 unsigned long count = 0;
2178 if (Archive::is_output_archive)
2220#ifdef MADNESS_DISABLE_SHARED_FROM_THIS
2221 p.reset(
static_cast<implT *
>(ptr), [](
implT *p_) ->
void{});
2223 p =
static_cast<implT *
>(ptr)->shared_from_this();
2246 template <
typename keyT,
typename valueT,
typename hashfunT>
2249 std::swap(dc0.
p, dc1.
p);
2261 template <
class keyT,
class valueT>
2267 const long magic = -5881828;
2269 using const_iterator =
typename dcT::const_iterator;
2270 int count = t.
size();
2284 const_iterator start, end;
2288 op_inspector(const_iterator start, const_iterator end,
size_t &size)
2289 : start(start), end(end), size(size) {}
2296 for (const_iterator it = start; it != end; ++it)
2304 const_iterator start, end;
2309 op_executor(const_iterator start, const_iterator end,
unsigned char *buf,
size_t size)
2310 : start(start), end(end), buf(buf), size(size) {}
2317 for (const_iterator it = start; it != end; ++it)
2327 const size_t ntasks = std::min(
size_t(count), std::max(
size_t(1),
ThreadPool::size()));
2328 size_t local_size = 0;
2329 double wall1 = wall0;
2330 unsigned char* buf = 0;
2333 const size_t max_items_per_task = (std::max(1, count) - 1) / ntasks + 1;
2335 std::vector<const_iterator> starts(ntasks), ends(ntasks);
2336 std::vector<size_t> local_sizes(ntasks);
2337 const_iterator start = t.
begin();
2338 size_t nleft = count;
2339 for (
size_t taskid = 0; taskid < ntasks; taskid++)
2341 const_iterator end = start;
2342 if (taskid == (ntasks - 1))
2348 size_t nitems = std::min(max_items_per_task, nleft);
2352 starts[taskid] = start;
2354 world->
taskq.
add(
new op_inspector(start, end, local_sizes[taskid]));
2364 for (
size_t taskid = 0; taskid < ntasks; taskid++)
2366 local_size += local_sizes[taskid];
2371 buf =
new unsigned char[local_size];
2375 for (
size_t taskid = 0; taskid < ntasks; taskid++)
2377 world->
taskq.
add(
new op_executor(starts[taskid], ends[taskid], buf +
offset, local_sizes[taskid]));
2378 offset += local_sizes[taskid];
2408 constexpr std::size_t max_msg =
2409 static_cast<std::size_t
>(std::numeric_limits<int>::max()) - (std::size_t(1) << 20);
2412 if (world->
rank() == 0)
2415 std::vector<std::size_t> sizes(world->
size(), 0);
2416 sizes[0] = local_size;
2418 world->
mpi.
Recv(sizes[
p],
p, gather_tag);
2420 std::size_t total_size = 0;
2422 total_size += sizes[
p];
2424 unsigned char *all_data =
new unsigned char[total_size];
2428 std::memcpy(all_data, buf, local_size);
2429 std::size_t
offset = local_size;
2434 std::size_t received = 0;
2435 while (received < sizes[
p])
2437 const std::size_t n = std::min(sizes[
p] - received, max_msg);
2438 world->
mpi.
Recv(all_data +
offset + received,
long(n),
p, gather_tag);
2446 localar & magic & 1;
2449 localar & -magic &(
unsigned long)(count);
2450 localar.store(all_data, total_size);
2458 world->
mpi.
Send(local_size, 0, gather_tag);
2459 std::size_t sent = 0;
2460 while (sent < local_size)
2462 const std::size_t n = std::min(local_size - sent, max_msg);
2463 world->
mpi.
Send(buf + sent,
long(n), 0, gather_tag);
2489 template <
class keyT,
class valueT,
class localarchiveT>
2494 const long magic = -5881828;
2497 typedef typename dcT::pairT pairT;
2518 unsigned long count = 0ul;
2523 localar &
cookie & count;
2549 template <
class keyT,
class valueT,
class localarchiveT>
2563 const long magic = -5881828;
2575 localar &
cookie & nclient;
Wrapper around MPI_Comm. Has a shallow copy constructor; use Create(Get_group()) for deep copy.
Definition safempi.h:497
int unique_tag()
Returns a unique tag for temporary use (1023<tag<4095).
Definition safempi.h:837
Definition worldhashmap.h:396
Hash_private::HashAccessor< const hashT, entryT::READLOCK > const_accessor
Definition worldhashmap.h:405
Hash_private::HashAccessor< hashT, entryT::WRITELOCK > accessor
Definition worldhashmap.h:404
Hash_private::HashIterator< const hashT > const_iterator
Definition worldhashmap.h:403
Hash_private::HashIterator< hashT > iterator
Definition worldhashmap.h:402
Implements the functionality of futures.
Definition future.h:75
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
Range, vaguely a la Intel TBB, to encapsulate a random-access, STL-like start and end iterator with c...
Definition range.h:64
iteratorT iterator
Alias for the iterator type.
Definition range.h:71
Simple structure used to manage references/pointers to remote instances.
Definition worldref.h:394
Contains attributes of a task.
Definition thread.h:330
All world tasks must be derived from this public interface.
Definition taskfn.h:69
virtual void run(const TaskThreadEnv &env)
Override this method to implement a multi-threaded task.
Definition world_task_queue.cc:45
static std::size_t size()
Returns the number of threads in the pool.
Definition thread.h:1460
Internal implementation of distributed container to facilitate shallow copy.
Definition worlddc.h:567
void erase(const keyT &key)
Definition worlddc.h:972
WorldContainerIterator< internal_iteratorT > iterator
Definition worlddc.h:582
const hashfunT & get_hash() const
Definition worlddc.h:896
bool find(const_accessor &acc, const keyT &key) const
Definition worlddc.h:1064
internal_containerT::accessor accessor
Definition worlddc.h:579
void find_handler(ProcessID requestor, const keyT &key, const RemoteReference< FutureImpl< iterator > > &ref)
Handles find request.
Definition worlddc.h:608
bool probe(const keyT &key) const
Definition worlddc.h:908
void find_success_handler(const RemoteReference< FutureImpl< iterator > > &ref, const pairT &datum)
Handles successful find response.
Definition worlddc.h:624
std::pair< const keyT, valueT > pairT
Definition worlddc.h:569
bool insert_const_acc(const_accessor &acc, const keyT &key)
Definition worlddc.h:946
void redistribute_coalesced_phase1(const std::shared_ptr< WorldDCPmapInterface< keyT > > &newpmap)
Definition worlddc.h:1220
WorldContainerIterator< internal_const_iteratorT > const_iteratorT
Definition worlddc.h:583
bool find(accessor &acc, const keyT &key)
Definition worlddc.h:1057
void redistribute_phase2()
Definition worlddc.h:1193
void insert(const pairT &datum)
Definition worlddc.h:922
WorldContainerIterator< internal_iteratorT > iteratorT
Definition worlddc.h:581
void clear()
Definition worlddc.h:966
bool insert_acc(accessor &acc, const keyT &key)
Definition worlddc.h:940
void find_const_failure_handler(const RemoteReference< FutureImpl< const_iterator > > &ref)
Handles unsuccessful const find response.
Definition worlddc.h:665
Future< iterator > find(const keyT &key)
Definition worlddc.h:1042
WorldContainerImpl(World &world, const std::shared_ptr< WorldDCPmapInterface< keyT > > &pm, const hashfunT &hf)
Definition worlddc.h:672
void redistribute_coalesced_phase2(std::size_t cap_boxes, bool rotate)
Definition worlddc.h:1238
void reset_pmap_to_local()
Definition worlddc.h:695
itemfun(const keyT &key, memfunT memfun)
Definition worlddc.h:1074
const pairT const_pairT
Definition worlddc.h:570
std::vector< keyT > * move_list
Tempoary used to record data that needs redistributing.
Definition worlddc.h:604
internal_containerT::iterator internal_iteratorT
Definition worlddc.h:577
WorldContainerImpl< keyT, valueT, hashfunT > implT
Definition worlddc.h:571
std::size_t size() const
Definition worlddc.h:917
void redistribute_phase1(const std::shared_ptr< WorldDCPmapInterface< keyT > > &newpmap)
Definition worlddc.h:1161
internal_containerT::const_iterator internal_const_iteratorT
Definition worlddc.h:578
std::shared_ptr< WorldDCPmapInterface< keyT > > pmap
Function/class to map from keys to owning process.
Definition worlddc.h:600
virtual ~WorldContainerImpl()
Definition worlddc.h:680
void do_replicate(World &world)
Definition worlddc.h:856
std::shared_ptr< WorldDCPmapInterface< keyT > > & get_pmap()
Definition worlddc.h:690
internal_containerT local
Locally owned data.
Definition worlddc.h:603
ConcurrentHashMap< keyT, valueT, hashfunT > internal_containerT
Definition worlddc.h:573
void find_const_success_handler(const RemoteReference< FutureImpl< const_iterator > > &ref, const pairT &datum)
Handles successful const find response.
Definition worlddc.h:658
void insert_batch(const std::vector< pairT > &boxes)
Definition worlddc.h:956
const_iterator begin() const
Definition worlddc.h:1012
void erase(InIter it)
Definition worlddc.h:988
void replicate(bool fence)
Definition worlddc.h:714
const_iterator end() const
Definition worlddc.h:1022
bool is_local(const keyT &key) const
Definition worlddc.h:898
void redistribute_phase3()
Definition worlddc.h:1207
bool rank_replication_complete_
True if the last replicate() completed and no reset followed.
Definition worlddc.h:601
void find_failure_handler(const RemoteReference< FutureImpl< iterator > > &ref)
Handles unsuccessful find response.
Definition worlddc.h:634
ProcessID owner(const keyT &key) const
Definition worlddc.h:903
void erase(InIter first, InIter last)
Definition worlddc.h:996
void find_const_handler(ProcessID requestor, const keyT &key, const RemoteReference< FutureImpl< const_iterator > > &ref)
Handles const find request.
Definition worlddc.h:644
void replicate_on_hosts(bool fence)
Definition worlddc.h:740
const std::shared_ptr< WorldDCPmapInterface< keyT > > & get_pmap() const
Definition worlddc.h:685
iterator begin()
Definition worlddc.h:1007
Future< const_iterator > find(const keyT &key) const
Definition worlddc.h:1027
const ProcessID me
My MPI rank.
Definition worlddc.h:602
iterator end()
Definition worlddc.h:1017
std::map< ProcessID, std::vector< keyT > > coalesced_move_
Temporary: keys to move, bucketed by destination (coalesced redistribute).
Definition worlddc.h:605
WorldContainerIterator< internal_const_iteratorT > const_iterator
Definition worlddc.h:584
internal_containerT::const_accessor const_accessor
Definition worlddc.h:580
Iterator for distributed container wraps the local iterator.
Definition worlddc.h:417
WorldContainerIterator(const WorldContainerIterator &other)
Definition worlddc.h:446
WorldContainerIterator(const internal_iteratorT &it)
Initializes from a local iterator.
Definition worlddc.h:436
WorldContainerIterator & operator++()
Pre-increment of an iterator (i.e., ++it) — local iterators only.
Definition worlddc.h:487
std::iterator_traits< internal_iteratorT >::iterator_category iterator_category
Definition worlddc.h:419
void copy(const WorldContainerIterator< iteratorT > &other)
Definition worlddc.h:537
std::iterator_traits< internal_iteratorT >::pointer pointer
Definition worlddc.h:422
bool operator==(const WorldContainerIterator &other) const
Determines if two iterators are identical.
Definition worlddc.h:472
const internal_iteratorT & get_internal_iterator() const
Private: (or should be) Returns iterator of internal container.
Definition worlddc.h:515
friend class WorldContainerIterator
Definition worlddc.h:534
WorldContainerIterator & operator=(const WorldContainerIterator &other)
Assignment.
Definition worlddc.h:465
value_type * value
Definition worlddc.h:428
bool is_cached() const
Returns true if this is non-local or cached value.
Definition worlddc.h:521
WorldContainerIterator operator++(int)
Definition worlddc.h:494
WorldContainerIterator(const value_type &v)
Initializes to cache a remote value.
Definition worlddc.h:440
pointer operator->() const
Iterators dereference to std::pair<const keyT,valueT>.
Definition worlddc.h:503
std::iterator_traits< internal_iteratorT >::reference reference
Definition worlddc.h:423
void serialize(const Archive &)
Definition worlddc.h:527
std::iterator_traits< internal_iteratorT >::value_type value_type
Definition worlddc.h:420
WorldContainerIterator(const WorldContainerIterator< iteratorT > &other)
Definition worlddc.h:453
WorldContainerIterator()
Default constructor makes a local uninitialized value.
Definition worlddc.h:432
internal_const_iteratorT it
Definition worlddc.h:426
reference operator*() const
Iterators dereference to std::pair<const keyT,valueT>.
Definition worlddc.h:509
std::iterator_traits< internal_iteratorT >::difference_type difference_type
Definition worlddc.h:421
bool operator!=(const WorldContainerIterator &other) const
Determines if two iterators are different.
Definition worlddc.h:479
~WorldContainerIterator()
Definition worlddc.h:459
Makes a distributed container with specified attributes.
Definition worlddc.h:1302
void process_pending()
Process pending messages.
Definition worlddc.h:1648
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:1342
const hashfunT & get_hash() const
Returns a reference to the hashing functor.
Definition worlddc.h:1637
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:1469
bool probe(const keyT &key) const
Returns true if local data is immediately available (no communication).
Definition worlddc.h:1506
void redistribute_coalesced_phase2(std::size_t cap_boxes, bool rotate=true)
Definition worlddc.h:1449
const_iterator begin() const
Returns an iterator to the beginning of the local data (no communication).
Definition worlddc.h:1559
void replace(const keyT &key, const valueT &value)
Inserts/replaces key+value pair (non-blocking communication if key not local).
Definition worlddc.h:1463
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:1490
iterator begin()
Returns an iterator to the beginning of the local data (no communication).
Definition worlddc.h:1552
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:2139
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:1358
Future< iterator > find(const keyT &key)
Returns a future iterator (non-blocking communication if key not local).
Definition worlddc.h:1534
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:1879
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:1890
Future< const_iterator > const_futureT
Definition worlddc.h:1314
bool is_replicated() const
Definition worlddc.h:1402
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:1928
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:1869
ProcessID owner(const keyT &key) const
Returns processor that logically owns key (no communication).
Definition worlddc.h:1516
implT::const_iterator const_iterator
Definition worlddc.h:1310
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:2109
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:2089
WorldContainer()
Makes an uninitialized container (no communication).
Definition worlddc.h:1330
void serialize(const archive::BufferOutputArchive &ar)
(de)Serialize — !! ONLY for purpose of interprocess communication
Definition worlddc.h:2205
Key< NDIM > key_type
Definition worlddc.h:1305
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:1729
void replicate(bool fence=true)
Definition worlddc.h:1427
virtual ~WorldContainer()
Destructor passes ownership of implementation to world for deferred cleanup.
Definition worlddc.h:2235
void erase(const keyT &key)
Erases entry from container (non-blocking comm if remote).
Definition worlddc.h:1587
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:1767
void reset_pmap_to_local()
Returns shared pointer to the process mapping.
Definition worlddc.h:1631
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:1684
const uniqueidT & id() const
Returns the associated unique id ... must be initialized.
Definition worlddc.h:2228
void redistribute_coalesced_phase1(const std::shared_ptr< WorldDCPmapInterface< keyT > > &newpmap)
Definition worlddc.h:1440
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:2069
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:1949
WorldContainerImpl< Key< NDIM >, FunctionNode< T, NDIM >, Hash< Key< NDIM > > > implT
Definition worlddc.h:1307
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:1839
void replace(const pairT &datum)
Inserts/replaces key+value pair (non-blocking communication if key not local).
Definition worlddc.h:1456
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:2119
iterator end()
Definition worlddc.h:1566
const std::shared_ptr< WorldDCPmapInterface< keyT > > & get_pmap() const
Returns shared pointer to the process mapping.
Definition worlddc.h:1624
std::shared_ptr< WorldDCPmapInterface< keyT > > & get_impl()
Definition worlddc.h:1417
void replace(input_iterator &start, input_iterator &end)
Inserts pairs (non-blocking communication if key(s) not local).
Definition worlddc.h:1498
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:2099
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:1483
Future< iterator > futureT
Definition worlddc.h:1313
void erase(const iterator &it)
Erases entry corresponding to local iterator (no communication).
Definition worlddc.h:1594
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:2129
void erase(const iterator &start, const iterator &finish)
Erases range defined by local iterators (no communication).
Definition worlddc.h:1601
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:1859
bool is_distributed() const
Definition worlddc.h:1398
WorldContainer(const WorldContainer &other)
Copy constructor is shallow (no communication).
Definition worlddc.h:1372
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:2043
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:1805
World & get_world() const
Returns the world associated with this container.
Definition worlddc.h:1411
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:1819
friend void swap(WorldContainer &, WorldContainer &)
implT::iterator iterator
Definition worlddc.h:1309
DistributionType get_distribution_type() const
return the way data is distributed
Definition worlddc.h:1393
implT::pairT pairT
Definition worlddc.h:1308
std::size_t size() const
Returns the number of local entries (no communication).
Definition worlddc.h:1617
containerT & operator=(const containerT &other)
Assignment is shallow (no communication).
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 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:2018
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:1476
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:1971
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:1748
void serialize(const archive::BufferInputArchive &ar)
(de)Serialize — !! ONLY for purpose of interprocess communication
Definition worlddc.h:2214
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:1908
bool is_local(const keyT &key) const
Returns true if the key maps to the local processor (no communication).
Definition worlddc.h:1523
const_iterator end() const
Returns an iterator past the end of the local data (no communication).
Definition worlddc.h:1573
void serialize(const Archive &ar)
(de)Serialize — Local data only to/from anything except Buffer*Archive and Parallel*Archive
Definition worlddc.h:2168
bool is_host_replicated() const
Definition worlddc.h:1406
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:2149
void clear()
Clears all local data (no communication).
Definition worlddc.h:1610
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:1994
Future< MEMFUN_RETURNT(memfunT)> send(const keyT &key, memfunT memfun)
Sends message "resultT memfun()" to item (non-blocking comm if remote).
Definition worlddc.h:1665
implT::const_accessor const_accessor
Definition worlddc.h:1312
std::shared_ptr< implT > p
Definition worlddc.h:1317
Future< const_iterator > find(const keyT &key) const
Returns a future iterator (non-blocking communication if key not local).
Definition worlddc.h:1545
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:1849
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:1786
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:1707
void replicate_on_hosts(bool fence=true)
replicates this WorldContainer on all hosts (one PID per host)
Definition worlddc.h:1433
void check_initialized() const
Definition worlddc.h:1319
WorldContainer< Key< NDIM >, FunctionNode< T, NDIM >, Hash< Key< NDIM > > > containerT
Definition worlddc.h:1306
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:2159
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:1829
implT::accessor accessor
Definition worlddc.h:1311
Default process map is "random" using madness::hash(key).
Definition worlddc.h:264
ProcessID owner(const keyT &key) const
Maps key to processor.
Definition worlddc.h:275
WorldDCDefaultPmap(World &world, const hashfunT &hf=hashfunT())
Definition worlddc.h:270
const int nproc
Definition worlddc.h:266
hashfunT hashfun
Definition worlddc.h:267
Local process map will always return the current process as owner.
Definition worlddc.h:288
ProcessID owner(const keyT &key) const override
Maps key to processor.
Definition worlddc.h:294
WorldDCLocalPmap(World &world)
Definition worlddc.h:293
ProcessID me
Definition worlddc.h:290
DistributionType distribution_type() const override
by default the map is distributed
Definition worlddc.h:299
DistributionType distribution_type() const override
by default the map is distributed
Definition worlddc.h:342
WorldDCNodeReplicatedPmap(World &world, const std::map< std::string, std::vector< long > > ranks_per_host)
Definition worlddc.h:333
ProcessID myowner
Definition worlddc.h:327
ProcessID owner(const keyT &key) const override
owner is the lowest rank on the node, same for all keys
Definition worlddc.h:338
Interface to be provided by any process map.
Definition worlddc.h:128
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:183
virtual DistributionType distribution_type() const
by default the map is distributed
Definition worlddc.h:148
virtual ProcessID single_owner() const
Definition worlddc.h:156
void print_data_sizes(World &world, const std::string msg="") const
Prints size info to std::cout.
Definition worlddc.h:239
std::size_t global_size(World &world) const
Counts global number of entries in all containers associated with this process map.
Definition worlddc.h:216
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:172
void register_callback(ptrT ptr)
Registers object for receipt of redistribute callbacks.
Definition worlddc.h:164
virtual void print() const
Definition worlddc.h:145
std::size_t local_size() const
Counts local number of entries in all containers associated with this process map.
Definition worlddc.h:226
std::set< ptrT > ptrs
Definition worlddc.h:134
virtual ~WorldDCPmapInterface()
Definition worlddc.h:143
WorldDCRedistributeInterface< keyT > * ptrT
Definition worlddc.h:130
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:83
WorldDCSingleOwnerPmap(ProcessID owner)
Definition worlddc.h:317
const ProcessID owner_
Definition worlddc.h:314
ProcessID owner(const keyT &) const override
Maps key to processor.
Definition worlddc.h:318
ProcessID single_owner() const override
Definition worlddc.h:319
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:177
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:189
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
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
WorldObject(const WorldObject &other)
Definition world_object.h:500
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
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:2561
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.
const unsigned char archive_typeinfo< T >::cookie
Definition archive_type_names.cc:44
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 DFConvergence.h:9
DistributionType from_string(std::string type)
Definition worlddc.h:109
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:452
std::string to_string(const Representation r)
Definition Restart.h:64
DistributionType
some introspection of how data is distributed
Definition worlddc.h:87
@ NodeReplicated
even if there are several ranks per node
Definition worlddc.h:90
@ Distributed
no replication of the container, the container is distributed over the world
Definition worlddc.h:88
@ RankReplicated
replicate the container over all world ranks
Definition worlddc.h:89
std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > FunctionDefaults< NDIM >::pmap
Definition mraimpl.h:3898
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
Function< T, NDIM > sum(World &world, const std::vector< Function< T, NDIM > > &f, bool fence=true)
Returns new function — q = sum_i f[i].
Definition vmra.h:1774
DistributionType validate_distribution_type(const dcT &dc)
check distribution type of WorldContainer – global communication
Definition worlddc.h:350
NDIM & f
Definition mra.h:2817
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition timers.cc:48
void print(const T &t, Ts &&... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:232
const Future< void > Future< void >::value
Definition future.cc:44
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:3149
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:1174
bool operator()(typename rangeT::iterator &iterator) const
Definition worlddc.h:1179
implT * impl
Definition worlddc.h:1175
P2Op(const P2Op &p)
Definition worlddc.h:1178
P2Op(implT *impl)
Definition worlddc.h:1177
Range< typename std::vector< keyT >::const_iterator > rangeT
Definition worlddc.h:1176
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:2264
static void store(const ParallelOutputArchive< localarchiveT > &ar, const WorldContainer< keyT, valueT > &t)
Definition worlddc.h:2492
Default store of an object via serialize(ar, t).
Definition archive.h:612
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
Key< D > keyT
Definition writecoeff2.cc:11