14#ifndef SRC_MADNESS_WORLD_CLOUD_H_
15#define SRC_MADNESS_WORLD_CLOUD_H_
33template<
typename keyT>
44 for (
auto &l2 : list2.
list)
list.push_back(l2);
54 keyT key =
list.front();
78 template<
typename T, std::
size_t NDIM>
81 template<
typename T, std::
size_t NDIM>
84 template<
typename keyQ,
typename valueT>
87 template<
typename keyQ,
typename valueT>
90 template<
typename T, std::
size_t NDIM>
110 std::size_t hashtype =
typeid(
T).hash_code();
158 using valueT = std::vector<unsigned char>;
159 typedef std::map<keyT, cached_objT>
cacheT;
168 template <
typename T>
171 template <
typename T>
195 std::size_t memsize=0;
196 std::size_t max_record_size=0;
198 memsize+=item.second.size();
199 max_record_size=std::max(max_record_size,item.second.size());
201 std::size_t global_memsize=memsize;
202 std::size_t max_memsize=memsize;
203 std::size_t min_memsize=memsize;
204 universe.
gop.
sum(global_memsize);
205 universe.
gop.
max(max_memsize);
206 universe.
gop.
max(max_record_size);
207 universe.
gop.
min(min_memsize);
210 auto global_size=local_size;
211 universe.
gop.
sum(global_size);
212 double byte2gbyte=1.0/(1024*1024*1024);
214 if (universe.
rank()==0) {
215 print(
"Cloud memory:");
217 print(
"size of cloud (total)");
218 print(
" number of records: ",global_size);
219 print(
" memory in GBytes: ",global_memsize*byte2gbyte);
220 print(
"size of cloud (average per node)");
221 print(
" number of records: ",
double(global_size)/universe.
size());
222 print(
" memory in GBytes: ",global_memsize*byte2gbyte/universe.
size());
223 print(
"min/max of node");
224 print(
" memory in GBytes: ",min_memsize*byte2gbyte,max_memsize*byte2gbyte);
225 print(
" max record size in GBytes:",max_record_size*byte2gbyte);
240 universe.
gop.
sum(cstores);
241 if (universe.
rank() == 0) {
242 auto precision = std::cout.precision();
243 std::cout << std::fixed << std::setprecision(1);
244 print(
"cloud storing cpu time", wtime * 0.001);
245 print(
"cloud replication cpu time", ptime * 0.001);
246 print(
"cloud reading cpu time", rtime * 0.001, std::defaultfloat);
247 std::cout << std::setprecision(precision) << std::scientific;
248 print(
"cloud cache stores ",
long(cstores));
249 print(
"cloud cache loads ",
long(creads));
279 return forward_load<T>(world, rlist);
291 return forward_load<T>(world, recordlist);
302 return load_tuple<T>(world, recordlist);
305 target.cloud_load(world, *
this, recordlist);
308 return do_load<T>(world, recordlist);
316 print(
"Cloud contents are replicated and read-only!");
329 recordlist+=
source.cloud_store(world,*
this);
346 std::list<keyT> keylist;
348 keylist.push_back(it->first);
352 if (rank == world.
rank()) {
353 std::size_t keylistsize = keylist.size();
356 for (
auto key : keylist) {
360 auto data = acc->second;
361 std::size_t sz=
data.size();
367 for (std::size_t start=0; start<sz; start+=chunk_size) {
368 std::size_t remainder = std::min(sz - start, chunk_size);
375 std::size_t keylistsize;
377 for (
size_t i=0; i<keylistsize; i++) {
384 for (std::size_t start=0; start<sz; start+=chunk_size) {
385 std::size_t remainder=std::min(sz-start,chunk_size);
395 if (world.
rank()==0)
print(
"replication ended after ",cpu1-cpu0,
" seconds at time",cpu1);
407 template<
typename>
struct is_tuple : std::false_type { };
408 template<
typename ...T>
struct is_tuple<
std::tuple<T...>> : std::true_type { };
410 template<
typename Q>
struct is_vector : std::false_type { };
411 template<
typename Q>
struct is_vector<
std::vector<Q>> : std::true_type { };
416 template<
typename T, std::
size_t NDIM>
446 if (
debug)
print(
"loading",
typeid(
T).
name(),
"from cache record", record,
"to world", world.
id());
447 if (
auto obj = std::any_cast<T>(&
cached_objects.find(record)->second))
return *obj;
481 if (is_already_present) std::cout <<
"skipping ";
483 std::cout <<
"storing world object of " <<
typeid(
T).
name() <<
"id " <<
source.id() <<
" to record " << record << std::endl;
485 std::cout <<
"storing object of " <<
typeid(
T).
name() <<
" to record " << record << std::endl;
488 if (
source.is_compressed() and T::dimT>3)
print(
"WARNING: storing compressed hi-dim `function");
492 if (is_already_present) {
511 typename std::enable_if<is_vector<T>::value,
T>
::type
513 std::size_t sz = do_load<std::size_t>(world, recordlist);
515 for (std::size_t i = 0; i < sz; ++i) {
516 target[i] = do_load<typename T::value_type>(world, recordlist);
526 typename std::enable_if<!is_vector<T>::value,
T>
::type
528 keyT record = recordlist.pop_front_and_return();
531 if (
is_cached(record))
return load_from_cache<T>(world, record);
532 if (
debug)
print(
"loading",
typeid(
T).
name(),
"from container record", record,
"to world", world.
id());
547 std::cout <<
"storing " <<
typeid(
source).
name() <<
" of size " <<
source.size() << std::endl;
551 if (
debug) std::cout <<
"done with vector storing; container size " <<
container.size() << std::endl;
556 template<
typename... Ts>
559 auto storeaway = [&](
const auto &
arg) {
562 auto l = [&](Ts
const &...
arg) {
563 ((storeaway(
arg)), ...);
565 std::apply(l, input);
575 if (
debug) std::cout <<
"loading tuple of type " <<
typeid(
T).
name() <<
" to world " << world.
id() << std::endl;
577 std::apply([&](
auto &&... args) {
578 ((args =
forward_load<
typename std::remove_reference<
decltype(args)>
::type>(world, recordlist)), ...);
cloud class
Definition cloud.h:147
bool is_cached(const keyT &key) const
Definition cloud.h:453
void clear()
Definition cloud.h:258
bool is_in_container(const keyT &key) const
checks if a (universe) container record is used
Definition cloud.h:461
bool force_load_from_cache
forces load from cache (mainly for debugging)
Definition cloud.h:152
bool debug
prints debug output
Definition cloud.h:149
std::atomic< long > writing_time1
Definition cloud.h:402
std::enable_if< is_vector< T >::value, T >::type do_load(World &world, recordlistT &recordlist) const
Definition cloud.h:512
recordlistT store_other(madness::World &world, const std::vector< T > &source)
Definition cloud.h:545
std::any cached_objT
Definition cloud.h:156
recordlistT store(madness::World &world, const T &source)
Definition cloud.h:314
T load_tuple(madness::World &world, recordlistT &recordlist) const
Definition cloud.h:574
std::is_base_of< archive::ParallelSerializableObject, T > is_parallel_serializable_object
Definition cloud.h:420
madness::archive::ContainerRecordOutputArchive::keyT keyT
Definition cloud.h:157
std::atomic< long > replication_time
Definition cloud.h:403
Recordlist< keyT > recordlistT
Definition cloud.h:160
std::is_constructible< T, World & > is_world_constructible
Definition cloud.h:422
recordlistT store_other(madness::World &world, const T &source)
Definition cloud.h:477
bool is_replicated
if contents of the container are replicated
Definition cloud.h:150
void set_force_load_from_cache(bool value)
Definition cloud.h:189
decltype(std::declval< T >().cloud_store(std::declval< World & >(), std::declval< Cloud & >())) member_cloud_serialize_t
Definition cloud.h:169
void replicate(const std::size_t chunk_size=INT_MAX)
Definition cloud.h:337
recordlistT local_list_of_container_keys
Definition cloud.h:165
void print_size(World &universe)
Definition cloud.h:193
std::atomic< long > reading_time
Definition cloud.h:400
void clear_timings()
Definition cloud.h:262
recordlistT store_tuple(World &world, const std::tuple< Ts... > &input)
store a tuple in multiple records
Definition cloud.h:557
void set_debug(bool value)
Definition cloud.h:181
std::enable_if<!is_vector< T >::value, T >::type do_load(World &world, recordlistT &recordlist) const
Definition cloud.h:527
T load(madness::World &world, const recordlistT recordlist) const
Definition cloud.h:274
void cache(madness::World &world, const T &obj, const keyT &record) const
Definition cloud.h:438
void set_fence(bool value)
Definition cloud.h:185
std::atomic< long > cache_reads
Definition cloud.h:404
Cloud(madness::World &universe)
Definition cloud.h:177
cacheT cached_objects
Definition cloud.h:164
void clear_cache(World &subworld)
Definition cloud.h:252
T load_from_cache(madness::World &world, const keyT &record) const
load an object from the cache, record is unchanged
Definition cloud.h:444
madness::meta::is_detected< member_cloud_serialize_t, T > has_cloud_serialize
Definition cloud.h:172
std::vector< unsigned char > valueT
Definition cloud.h:158
bool dofence
fences after load/store
Definition cloud.h:151
void print_timings(World &universe) const
Definition cloud.h:230
T allocator(World &world) const
Definition cloud.h:468
std::atomic< long > writing_time
Definition cloud.h:401
madness::WorldContainer< keyT, valueT > container
Definition cloud.h:163
T forward_load(madness::World &world, recordlistT &recordlist) const
load a single object from the cloud, recordlist is consumed while loading elements
Definition cloud.h:296
std::map< keyT, cached_objT > cacheT
Definition cloud.h:159
T consuming_load(madness::World &world, recordlistT &recordlist) const
similar to load, but will consume the recordlist
Definition cloud.h:287
std::atomic< long > cache_stores
Definition cloud.h:405
FunctionImpl holds all Function state to facilitate shallow copy semantics.
Definition funcimpl.h:945
A multiresolution adaptive numerical function.
Definition mra.h:139
A tensor is a multidimensional array.
Definition tensor.h:317
Makes a distributed container with specified attributes.
Definition worlddc.h:866
bool find(accessor &acc, const keyT &key)
Write access to LOCAL value by key. Returns true if found, false otherwise (always false for remote).
Definition worlddc.h:987
void max(T *buf, size_t nelem)
Inplace global max while still processing AM & tasks.
Definition worldgop.h:882
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:161
void min(T *buf, size_t nelem)
Inplace global min while still processing AM & tasks.
Definition worldgop.h:876
void sum(T *buf, size_t nelem)
Inplace global sum while still processing AM & tasks.
Definition worldgop.h:870
void Bcast(T *buffer, int count, int root) const
MPI broadcast an array of count elements.
Definition worldmpi.h:416
A parallel world class.
Definition world.h:132
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:320
WorldMpiInterface & mpi
MPI interface.
Definition world.h:204
ProcessID size() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition world.h:330
unsigned long id() const
Definition world.h:315
WorldGopInterface & gop
Global operations.
Definition world.h:207
Definition parallel_dc_archive.h:14
long keyT
Definition parallel_dc_archive.h:16
An archive for storing local or parallel data wrapping a BinaryFstreamOutputArchive.
Definition parallel_archive.h:321
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only)
Definition tensor.h:2503
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
Definition array_addons.h:50
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
void hash_range(hashT &seed, It first, It last)
Definition worldhash.h:280
static double cpu_time()
Returns the cpu time in seconds relative to an arbitrary origin.
Definition timers.h:127
void hash_combine(hashT &seed, const T &v)
Combine hash values.
Definition worldhash.h:260
static class madness::twoscale_cache_class cache[kmax+1]
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:225
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
std::string name(const FuncType &type, const int ex=-1)
Definition ccpairfunction.h:28
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness hash.
Definition array_addons.h:78
Definition hatom_sf_dirac.cc:91
Definition test_ccpairfunction.cc:22
std::atomic< long > & rtime
Definition cloud.h:427
World & world
Definition cloud.h:425
double wall0
Definition cloud.h:426
~cloudtimer()
Definition cloud.h:431
cloudtimer(World &world, std::atomic< long > &readtime)
Definition cloud.h:429
static keyT compute_record(const std::vector< T > &arg)
Definition cloud.h:94
keyT pop_front_and_return()
Definition cloud.h:53
static keyT compute_record(const Function< T, NDIM > &arg)
Definition cloud.h:79
Recordlist(const Recordlist &other)
Definition cloud.h:41
Recordlist(const keyT &key)
Definition cloud.h:39
static keyT compute_record(const std::shared_ptr< T > &arg)
Definition cloud.h:100
static keyT compute_record(const T &arg)
Definition cloud.h:103
std::size_t size() const
Definition cloud.h:59
madness::meta::is_detected< member_id_t, T > has_member_id
Definition cloud.h:69
decltype(std::declval< T >().id()) member_id_t
Definition cloud.h:66
friend std::ostream & operator<<(std::ostream &os, const Recordlist &arg)
Definition cloud.h:117
Recordlist & operator+=(const Recordlist &list2)
Definition cloud.h:43
static keyT compute_record(const WorldContainer< keyQ, valueT > &arg)
Definition cloud.h:85
decltype(std::declval< T >().hash()) member_hash_t
Definition cloud.h:73
static keyT compute_record(const std::shared_ptr< WorldContainer< keyQ, valueT > > &arg)
Definition cloud.h:88
std::list< keyT > list
Definition cloud.h:35
Recordlist & operator+=(const keyT &key)
Definition cloud.h:48
static keyT compute_record(const FunctionImpl< T, NDIM > *arg)
Definition cloud.h:82
static keyT compute_record(const std::shared_ptr< madness::FunctionImpl< T, NDIM > > &arg)
Definition cloud.h:91
static keyT compute_record(const Tensor< T > &arg)
Definition cloud.h:97
madness::meta::is_detected< member_hash_t, T > has_member_hash
Definition cloud.h:76
Recordlist()
Definition cloud.h:37
#define MPI_BYTE
Definition stubmpi.h:77
double source(const coordT &r)
Definition testperiodic.cc:48
int ProcessID
Used to clearly identify process number/rank.
Definition worldtypes.h:43
FLOAT target(const FLOAT &x)
Definition y.cc:295