From 089bfd446d76196457635477f7983fc779d8f7eb Mon Sep 17 00:00:00 2001 From: Vito G Castellana Date: Tue, 8 Feb 2022 12:24:51 -0800 Subject: [PATCH] [#204] additional multimap methods --- include/shad/data_structures/multimap.h | 387 ++++++++++++------------ 1 file changed, 188 insertions(+), 199 deletions(-) diff --git a/include/shad/data_structures/multimap.h b/include/shad/data_structures/multimap.h index df7a57d6..0b224587 100644 --- a/include/shad/data_structures/multimap.h +++ b/include/shad/data_structures/multimap.h @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// // -// Copyright 2021 Battelle Memorial Institute +// Copyright 2018 Battelle Memorial Institute // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy @@ -26,13 +26,13 @@ #define INCLUDE_SHAD_DATA_STRUCTURES_MULTIMAP_H_ #include -#include #include -#include -#include #include -#include +#include #include +#include +#include +#include #include "shad/data_structures/abstract_data_structure.h" #include "shad/data_structures/buffer.h" @@ -40,6 +40,7 @@ #include "shad/data_structures/local_multimap.h" #include "shad/distributed_iterator_traits.h" #include "shad/runtime/runtime.h" +#include "shad/runtime/mappings/gmt/gmt_synchronous_interface.h" #define PREFIX_SIZE 80 @@ -55,17 +56,17 @@ class multimap_iterator; /// @tparam VTYPE type of the multimap values. /// @tparam KEY_COMPARE key comparison function; default is MemCmp. /// @warning obects of type KTYPE and VTYPE need to be trivially copiable. -template > -class Multimap - : public AbstractDataStructure> { +template < typename KTYPE, typename VTYPE, typename KEY_COMPARE = MemCmp > +class Multimap : public AbstractDataStructure< Multimap > { + template friend class AbstractDataStructure; friend class multimap_iterator, - const std::pair, - std::pair>; + const std::pair, + std::pair>; friend class multimap_iterator, - const std::pair, - std::pair>; + const std::pair, + std::pair>; public: using value_type = std::pair; @@ -76,16 +77,16 @@ class Multimap using iterator = multimap_iterator, - const std::pair, std::pair>; + const std::pair, std::pair>; using const_iterator = multimap_iterator, - const std::pair, std::pair>; + const std::pair, std::pair>; using local_iterator = lmultimap_iterator, - const std::pair>; + const std::pair>; using const_local_iterator = lmultimap_iterator, - const std::pair>; + const std::pair>; struct EntryT { EntryT(const KTYPE &k, const VTYPE &v) : key(k), value(v) {} @@ -116,6 +117,12 @@ class Multimap /// @return the size of the multimap. size_t Size() const; + /// @brief Number of keys of the multimap. + /// @warning Calling this method may result in one-to-all + /// communication among localities to retrieve consistent information. + /// @return the size of the multimap. + size_t NumberKeys() const; + /// @brief Insert a key-value pair in the multimap. /// @param[in] key the key. /// @param[in] value the value to copy into the multimap. @@ -125,8 +132,7 @@ class Multimap /// @brief Asynchronously Insert a key-value pair in the multimap. /// @warning Asynchronous operations are guaranteed to have completed /// only after calling the rt::waitForCompletion(rt::Handle &handle) method. - /// @param[in,out] handle Reference to the handle to be used to wait for - /// completion. + /// @param[in,out] handle Reference to the handle to be used to wait for completion. /// @param[in] key the key. /// @param[in] value the value to copy into the multimap. /// @return a pointer to the value if the the key-value was inserted @@ -148,8 +154,7 @@ class Multimap /// @param[in,out] handle Reference to the handle /// @param[in] key The key. /// @param[in] value The value. - void BufferedAsyncInsert(rt::Handle &handle, const KTYPE &key, - const VTYPE &value); + void BufferedAsyncInsert(rt::Handle &handle, const KTYPE &key, const VTYPE &value); /// @brief Finalize method for buffered insertions. void WaitForBufferedInsert() { @@ -163,12 +168,10 @@ class Multimap /// @param[in] key the key. void Erase(const KTYPE &key); - /// @brief Asynchronously remove a key and associated values from the - /// multimap. + /// @brief Asynchronously remove a key and associated values from the multimap. /// @warning Asynchronous operations are guaranteed to have completed /// only after calling the rt::waitForCompletion(rt::Handle &handle) method. - /// @param[in,out] handle Reference to the handle to be used to wait for - /// completion. + /// @param[in,out] handle Reference to the handle to be used to wait for completion. /// @param[in] key the key. void AsyncErase(rt::Handle &handle, const KTYPE &key); @@ -181,33 +184,35 @@ class Multimap rt::executeOnAll(clearLambda, oid_); } - using LookupResult = - typename LocalMultimap::LookupResult; - using LookupRemoteResult = - typename LocalMultimap::LookupRemoteResult; + using LookupResult = typename LocalMultimap::LookupResult; + using LookupRemoteResult = typename LocalMultimap::LookupRemoteResult; /// @brief Get all the values associated to a key. /// @param[in] key the key. - /// @param[out] res a pointer to the values if the the key-value was found, - /// otherwise NULL + /// @param[out] res a pointer to the values if the the key-value was found, otherwise NULL /// @return true if the entry is found, otherwise false bool Lookup(const KTYPE &key, LookupResult *res); /// @brief Asynchronous lookup method. /// @warning Asynchronous operations are guaranteed to have completed. /// only after calling the rt::waitForCompletion(rt::Handle &handle) method. - /// @param[in,out] handle Reference to the handle to be used to wait for - /// completion. + /// @param[in,out] handle Reference to the handle to be used to wait for completion. /// @param[in] key the key. /// @param[out] res the result of the lookup operation. void AsyncLookup(rt::Handle &handle, const KTYPE &key, LookupResult *res); + /// @brief Read records from multiple files + /// @param[in] prefix the file prefix + /// @param[in] lb the lower bound postscript + /// @param[in] ub the upper bound postscript + void readFromFiles(rt::Handle & handle, std::string prefix, uint64_t lb, uint64_t ub); + + /// @brief Apply a user-defined function to a key-value pair. /// - /// @tparam ApplyFunT User-defined function type. The function prototype - /// should be: + /// @tparam ApplyFunT User-defined function type. The function prototype should be: /// @code - /// void(const KTYPE&, VTYPE&, Args&); + /// void(const KTYPE&, std::vector &, Args&); /// @endcode /// @tparam ...Args Types of the function arguments. /// @@ -215,14 +220,14 @@ class Multimap /// @param function The function to apply. /// @param args The function arguments. template - void Apply(const KTYPE &key, ApplyFunT &&function, Args &...args); + void Apply(const KTYPE &key, ApplyFunT &&function, Args &... args); + /// @brief Asynchronously apply a user-defined function to a key-value pair. /// - /// @tparam ApplyFunT User-defined function type. The function prototype - /// should be: + /// @tparam ApplyFunT User-defined function type. The function prototype should be: /// @code - /// void(rt::Handle &handle, const KTYPE&, VTYPE&, Args&); + /// void(rt::Handle &handle, const KTYPE&, std::vector &, Args&); /// @endcode /// @tparam ...Args Types of the function arguments. /// @@ -231,30 +236,26 @@ class Multimap /// @param function The function to apply. /// @param args The function arguments. template - void AsyncApply(rt::Handle &handle, const KTYPE &key, ApplyFunT &&function, - Args &...args); + void AsyncApply(rt::Handle &handle, const KTYPE &key, ApplyFunT &&function, Args &... args); /// @brief Apply a user-defined function to each key-value pair. /// - /// @tparam ApplyFunT User-defined function type. The function prototype - /// should be: + /// @tparam ApplyFunT User-defined function type. The function prototype should be: /// @code - /// void(const KTYPE&, VTYPE&, Args&); + /// void(const KTYPE&, std::vector *, Args&); /// @endcode /// @tparam ...Args Types of the function arguments. /// /// @param function The function to apply. /// @param args The function arguments. template - void ForEachEntry(ApplyFunT &&function, Args &...args); + void ForEachEntry(ApplyFunT &&function, Args &... args); - /// @brief Asynchronously apply a user-defined function to each key-value - /// pair. + /// @brief Asynchronously apply a user-defined function to each key-value pair. /// - /// @tparam ApplyFunT User-defined function type. he function prototype - /// should be: + /// @tparam ApplyFunT User-defined function type. he function prototype should be: /// @code - /// void(shad::rt::Handle&, const KTYPE&, VTYPE&, Args&); + /// void(shad::rt::Handle&, const KTYPE&, std::vector *, Args&); /// @endcode /// @tparam ...Args Types of the function arguments. /// @@ -262,13 +263,11 @@ class Multimap /// @param function The function to apply. /// @param args The function arguments. template - void AsyncForEachEntry(rt::Handle &handle, ApplyFunT &&function, - Args &...args); + void AsyncForEachEntry(rt::Handle &handle, ApplyFunT &&function, Args &... args); /// @brief Apply a user-defined function to each key. /// - /// @tparam ApplyFunT User-defined function type. The function prototype - /// should be: + /// @tparam ApplyFunT User-defined function type. The function prototype should be: /// @code /// void(const KTYPE&, Args&); /// @endcode @@ -277,12 +276,11 @@ class Multimap /// @param function The function to apply. /// @param args The function arguments. template - void ForEachKey(ApplyFunT &&function, Args &...args); + void ForEachKey(ApplyFunT &&function, Args &... args); /// @brief Asynchronously apply a user-defined function to each key. /// - /// @tparam ApplyFunT User-defined function type. The function prototype - /// should be: + /// @tparam ApplyFunT User-defined function type. The function prototype should be: /// @code /// void(shad::rt::Handle&, const KTYPE&, Args&); /// @endcode @@ -292,28 +290,24 @@ class Multimap /// @param function The function to apply. /// @param args The function arguments. template - void AsyncForEachKey(rt::Handle &handle, ApplyFunT &&function, Args &...args); + void AsyncForEachKey(rt::Handle &handle, ApplyFunT &&function, Args &... args); void PrintAllEntries() { - auto printLambda = [](const ObjectID &oid) { + auto printLambda = [](const ObjectID & oid) { auto mapPtr = HmapT::GetPtr(oid); mapPtr->localMultimap_.PrintAllEntries(); }; - for (auto loc : rt::allLocalities()) { - rt::executeAt(loc, printLambda, oid_); - } + for (auto loc : rt::allLocalities()) rt::executeAt(loc, printLambda, oid_); } void PrintAllKeys() { - auto printLambda = [](const ObjectID &oid) { + auto printLambda = [](const ObjectID & oid) { auto mapPtr = HmapT::GetPtr(oid); mapPtr->localMultimap_.PrintAllKeys(); }; - for (auto loc : rt::allLocalities()) { - rt::executeAt(loc, printLambda, oid_); - } + for (auto loc : rt::allLocalities()) rt::executeAt(loc, printLambda, oid_); } // FIXME it should be protected @@ -330,9 +324,7 @@ class Multimap local_iterator local_begin() { return local_iterator::lmultimap_begin(&localMultimap_); } - local_iterator local_end() { - return local_iterator::lmultimap_end(&localMultimap_); - } + local_iterator local_end() { return local_iterator::lmultimap_end(&localMultimap_); } const_local_iterator clocal_begin() { return const_local_iterator::lmultimap_begin(&localMultimap_); } @@ -352,13 +344,9 @@ class Multimap BufferedAsyncInsert(h, value.first, value.second); } - void buffered_async_wait(rt::Handle &h) { - rt::waitForCompletion(h); - } + void buffered_async_wait(rt::Handle &h) { rt::waitForCompletion(h); } - void buffered_async_flush() { - WaitForBufferedInsert(); - } + void buffered_async_flush() { WaitForBufferedInsert(); } private: ObjectID oid_; @@ -376,13 +364,16 @@ class Multimap KTYPE key; }; + struct RFArgs { + uint64_t lb; + ObjectID oid; + char prefix[PREFIX_SIZE]; + }; + protected: Multimap(ObjectID oid, const size_t numEntries) : oid_(oid), - localMultimap_(std::max( - numEntries / - (constants::kDefaultNumEntriesPerBucket * rt::numLocalities()), - 1lu)), + localMultimap_(std::max(numEntries / (constants::kDefaultNumEntriesPerBucket * rt::numLocalities()), 1lu)), buffers_(oid) {} }; @@ -407,9 +398,28 @@ inline size_t Multimap::Size() const { } template -inline std::pair::iterator, bool> -Multimap::Insert(const KTYPE &key, - const VTYPE &value) { +inline size_t Multimap::NumberKeys() const { + size_t size = localMultimap_.numberKeys_; + size_t remoteKeys; + + auto sizeLambda = [](const ObjectID &oid, size_t *res) { + auto mapPtr = HmapT::GetPtr(oid); + *res = mapPtr->localMultimap_.numberKeys_; + }; + + for (auto tgtLoc : rt::allLocalities()) { + if (tgtLoc != rt::thisLocality()) { + rt::executeAtWithRet(tgtLoc, sizeLambda, oid_, &remoteKeys); + size += remoteKeys; + } + } + + return size; +} + +template +inline std::pair < typename Multimap::iterator, bool > +Multimap::Insert(const KTYPE &key, const VTYPE &value) { using itr_traits = distributed_iterator_traits; size_t targetId = shad::hash{}(key) % rt::numLocalities(); @@ -427,8 +437,7 @@ Multimap::Insert(const KTYPE &key, auto &args(std::get<2>(args_)); auto mapPtr = HmapT::GetPtr(args.oid); auto lres = mapPtr->localMultimap_.Insert(args.key, args.value); - res_ptr->first = itr_traits::iterator_from_local( - std::get<0>(args_), std::get<1>(args_), lres.first); + res_ptr->first = itr_traits::iterator_from_local (std::get<0>(args_), std::get<1>(args_), lres.first); res_ptr->second = lres.second; }; rt::executeAtWithRet( @@ -458,16 +467,16 @@ inline void Multimap::AsyncInsert( } template -inline void Multimap::BufferedInsert( - const KTYPE &key, const VTYPE &value) { +inline void Multimap::BufferedInsert(const KTYPE &key, const VTYPE &value) { size_t targetId = shad::hash{}(key) % rt::numLocalities(); rt::Locality targetLocality(targetId); buffers_.Insert(EntryT(key, value), targetLocality); } template -inline void Multimap::BufferedAsyncInsert( - rt::Handle &handle, const KTYPE &key, const VTYPE &value) { +inline void Multimap:: + BufferedAsyncInsert(rt::Handle &handle, const KTYPE &key, const VTYPE &value) { + size_t targetId = shad::hash{}(key) % rt::numLocalities(); rt::Locality targetLocality(targetId); buffers_.AsyncInsert(handle, EntryT(key, value), targetLocality); @@ -491,8 +500,7 @@ inline void Multimap::Erase(const KTYPE &key) { } template -inline void Multimap::AsyncErase(rt::Handle &handle, - const KTYPE &key) { +inline void Multimap::AsyncErase(rt::Handle &handle, const KTYPE &key) { size_t targetId = shad::hash{}(key) % rt::numLocalities(); rt::Locality targetLocality(targetId); @@ -509,8 +517,7 @@ inline void Multimap::AsyncErase(rt::Handle &handle, } template -inline bool Multimap::Lookup(const KTYPE &key, - LookupResult *res) { +inline bool Multimap::Lookup(const KTYPE &key, LookupResult *res) { rt::Handle handle; AsyncLookup(handle, key, res); waitForCompletion(handle); @@ -519,65 +526,87 @@ inline bool Multimap::Lookup(const KTYPE &key, template inline void Multimap::AsyncLookup( - rt::Handle &handle, const KTYPE &key, LookupResult *result) { + rt::Handle & handle, const KTYPE & key, LookupResult * result) { + size_t targetId = shad::hash{}(key) % rt::numLocalities(); rt::Locality targetLocality(targetId); - + if (targetLocality == rt::thisLocality()) { localMultimap_.AsyncLookup(handle, key, result); - + } else { - auto lookupLambda = [](const LookupArgs &args, LookupRemoteResult *ret) { - auto my_key = args.key; - auto my_map = HmapT::GetPtr(args.oid); - LookupRemoteResult remote_result; - my_map->localMultimap_.LookupFromRemote(my_key, &remote_result); + auto lookupLambda = [](const LookupArgs & args, LookupRemoteResult * ret) { + auto my_key = args.key; + auto my_map = HmapT::GetPtr(args.oid); - *ret = remote_result; + LookupRemoteResult remote_result; + my_map->localMultimap_.LookupFromRemote(my_key, & remote_result); + + * ret = remote_result; }; // executed at remote site, so meaning of remote and local are switched - auto lookupFetchLambda = [](rt::Handle &handle, - const LookupRemoteResult &args) { - rt::dma(args.localLoc, args.local_elems, args.remote_elems, - args.size); - free(args.remote_elems); + auto lookupFetchLambda = [](rt::Handle & handle, const LookupRemoteResult & args) { + rt::dma(args.localLoc, args.local_elems, args.remote_elems, args.size); + free(args.remote_elems); }; LookupArgs args = {oid_, key}; LookupRemoteResult remote_result; - rt::executeAtWithRet(targetLocality, lookupLambda, args, &remote_result); - - (*result).found = remote_result.found; - (*result).size = remote_result.size; + rt::executeAtWithRet(targetLocality, lookupLambda, args, & remote_result); + (* result).found = remote_result.found; + (* result).size = remote_result.size; + if (remote_result.found) { - (*result).value.resize(remote_result.size); - remote_result.localLoc = rt::thisLocality(); - remote_result.local_elems = (*result).value.data(); - rt::asyncExecuteAt(handle, targetLocality, lookupFetchLambda, - remote_result); + (* result).value.resize(remote_result.size); + remote_result.localLoc = rt::thisLocality(); + remote_result.local_elems = (* result).value.data(); + rt::asyncExecuteAt(handle, targetLocality, lookupFetchLambda, remote_result); } } } +template +inline void Multimap::readFromFiles( + rt::Handle & handle, std::string prefix, uint64_t lb, uint64_t ub) { + + auto readFileLambda = [](rt::Handle & handle, const RFArgs & args, size_t it) { + std::string line; + auto my_map = HmapT::GetPtr(args.oid); + std::string filename = args.prefix + std::to_string(args.lb + it); + printf("reading file %s\n", filename.c_str()); + + std::ifstream file(filename); + if (! file.is_open()) { printf("Cannot open file %s\n", filename.c_str()); exit(-1); } + + while (getline(file, line)) { + if (line[0] == '#') continue; // skip comments + + VTYPE record = VTYPE(line); + // my_map->AsyncInsert(handle, record.key(), record); + my_map->BufferedAsyncInsert(handle, record.key(), record); + } }; + + RFArgs args = {lb, oid_}; + memcpy(args.prefix, prefix.c_str(), prefix.size() + 1); + rt::asyncForEachOnAll(handle, readFileLambda, args, ub - lb + 1); +} + template template -void Multimap::ForEachEntry(ApplyFunT &&function, - Args &...args) { - using FunctionTy = void (*)(const KTYPE &, VTYPE &, Args &...); +void Multimap::ForEachEntry(ApplyFunT &&function, Args &... args) { + using FunctionTy = void (*)(const KTYPE &, std::vector &, Args &...); FunctionTy fn = std::forward(function); using feArgs = std::tuple>; - using LMapPtr = LocalMultimap *; using ArgsTuple = std::tuple>; feArgs arguments(oid_, fn, std::tuple(args...)); auto feLambda = [](const feArgs &args) { auto mapPtr = HmapT::GetPtr(std::get<0>(args)); - ArgsTuple argsTuple(&mapPtr->localMultimap_, std::get<1>(args), - std::get<2>(args)); + ArgsTuple argsTuple(&mapPtr->localMultimap_, std::get<1>(args), std::get<2>(args)); rt::forEachAt(rt::thisLocality(), LMapT::template ForEachEntryFunWrapper, argsTuple, mapPtr->localMultimap_.numBuckets_); @@ -588,8 +617,9 @@ void Multimap::ForEachEntry(ApplyFunT &&function, template template void Multimap::AsyncForEachEntry( - rt::Handle &handle, ApplyFunT &&function, Args &...args) { - using FunctionTy = void (*)(rt::Handle &, const KTYPE &, VTYPE &, Args &...); + rt::Handle &handle, ApplyFunT &&function, Args &... args) { + + using FunctionTy = void (*)(rt::Handle &, const KTYPE &, std::vector &, Args &...); FunctionTy fn = std::forward(function); using feArgs = std::tuple>; @@ -598,8 +628,7 @@ void Multimap::AsyncForEachEntry( feArgs arguments(oid_, fn, std::tuple(args...)); auto feLambda = [](rt::Handle &handle, const feArgs &args) { auto mapPtr = HmapT::GetPtr(std::get<0>(args)); - ArgsTuple argsTuple(&mapPtr->localMultimap_, std::get<1>(args), - std::get<2>(args)); + ArgsTuple argsTuple(&mapPtr->localMultimap_, std::get<1>(args), std::get<2>(args)); rt::asyncForEachAt( handle, rt::thisLocality(), @@ -611,8 +640,7 @@ void Multimap::AsyncForEachEntry( template template -void Multimap::ForEachKey(ApplyFunT &&function, - Args &...args) { +void Multimap::ForEachKey(ApplyFunT &&function, Args &... args) { using FunctionTy = void (*)(const KTYPE &, Args &...); FunctionTy fn = std::forward(function); @@ -622,8 +650,7 @@ void Multimap::ForEachKey(ApplyFunT &&function, feArgs arguments(oid_, fn, std::tuple(args...)); auto feLambda = [](const feArgs &args) { auto mapPtr = HmapT::GetPtr(std::get<0>(args)); - ArgsTuple argsTuple(&mapPtr->localMultimap_, std::get<1>(args), - std::get<2>(args)); + ArgsTuple argsTuple(&mapPtr->localMultimap_, std::get<1>(args), std::get<2>(args)); rt::forEachAt(rt::thisLocality(), LMapT::template ForEachKeyFunWrapper, argsTuple, mapPtr->localMultimap_.numBuckets_); @@ -633,9 +660,8 @@ void Multimap::ForEachKey(ApplyFunT &&function, template template -void Multimap::AsyncForEachKey(rt::Handle &handle, - ApplyFunT &&function, - Args &...args) { +void Multimap::AsyncForEachKey( + rt::Handle &handle, ApplyFunT &&function, Args &... args) { using FunctionTy = void (*)(rt::Handle &, const KTYPE &, Args &...); FunctionTy fn = std::forward(function); @@ -645,8 +671,7 @@ void Multimap::AsyncForEachKey(rt::Handle &handle, feArgs arguments(oid_, fn, std::tuple(args...)); auto feLambda = [](rt::Handle &handle, const feArgs &args) { auto mapPtr = HmapT::GetPtr(std::get<0>(args)); - ArgsTuple argsTuple(&mapPtr->localMultimap_, std::get<1>(args), - std::get<2>(args)); + ArgsTuple argsTuple(&mapPtr->localMultimap_, std::get<1>(args), std::get<2>(args)); rt::asyncForEachAt( handle, rt::thisLocality(), LMapT::template AsyncForEachKeyFunWrapper, @@ -657,9 +682,7 @@ void Multimap::AsyncForEachKey(rt::Handle &handle, template template -void Multimap::Apply(const KTYPE &key, - ApplyFunT &&function, - Args &...args) { +void Multimap::Apply(const KTYPE &key, ApplyFunT &&function, Args &... args) { size_t targetId = shad::hash{}(key) % rt::numLocalities(); rt::Locality targetLocality(targetId); @@ -667,16 +690,14 @@ void Multimap::Apply(const KTYPE &key, localMultimap_.Apply(key, function, args...); } else { - using FunctionTy = void (*)(const KTYPE &, VTYPE &, Args &...); + using FunctionTy = void (*)(const KTYPE &, std::vector &, Args &...); FunctionTy fn = std::forward(function); - using ArgsTuple = - std::tuple>; + using ArgsTuple = std::tuple>; ArgsTuple arguments(oid_, key, fn, std::tuple(args...)); auto feLambda = [](const ArgsTuple &args) { - constexpr auto Size = std::tuple_size< - typename std::decay(args))>::type>::value; + constexpr auto Size = std::tuple_size(args))>::type>::value; ArgsTuple &tuple = const_cast(args); LMapT *mapPtr = &(HmapT::GetPtr(std::get<0>(tuple))->localMultimap_); LMapT::CallApplyFun(mapPtr, std::get<1>(tuple), std::get<2>(tuple), @@ -688,10 +709,8 @@ void Multimap::Apply(const KTYPE &key, template template -void Multimap::AsyncApply(rt::Handle &handle, - const KTYPE &key, - ApplyFunT &&function, - Args &...args) { +void Multimap::AsyncApply( + rt::Handle &handle, const KTYPE &key, ApplyFunT &&function, Args &... args) { size_t targetId = shad::hash{}(key) % rt::numLocalities(); rt::Locality targetLocality(targetId); @@ -699,16 +718,13 @@ void Multimap::AsyncApply(rt::Handle &handle, localMultimap_.AsyncApply(handle, key, function, args...); } else { - using FunctionTy = - void (*)(rt::Handle &, const KTYPE &, VTYPE &, Args &...); + using FunctionTy = void (*)(rt::Handle &, const KTYPE &, std::vector &, Args &...); FunctionTy fn = std::forward(function); - using ArgsTuple = - std::tuple>; + using ArgsTuple = std::tuple>; ArgsTuple arguments(oid_, key, fn, std::tuple(args...)); auto feLambda = [](rt::Handle &handle, const ArgsTuple &args) { - constexpr auto Size = std::tuple_size< - typename std::decay(args))>::type>::value; + constexpr auto Size = std::tuple_size(args))>::type>::value; ArgsTuple &tuple(const_cast(args)); LMapT *mapPtr = &(HmapT::GetPtr(std::get<0>(tuple))->localMultimap_); LMapT::AsyncCallApplyFun(handle, mapPtr, std::get<1>(tuple), @@ -729,13 +745,11 @@ class multimap_iterator : public std::iterator { using value_type = NonConstT; multimap_iterator() {} - multimap_iterator(uint32_t locID, const OIDT mapOID, local_iterator_type &lit, - T element) { + multimap_iterator(uint32_t locID, const OIDT mapOID, local_iterator_type &lit, T element) { data_ = {locID, mapOID, lit, element}; } - multimap_iterator(uint32_t locID, const OIDT mapOID, - local_iterator_type &lit) { + multimap_iterator(uint32_t locID, const OIDT mapOID, local_iterator_type &lit) { auto mapPtr = MapT::GetPtr(mapOID); const LMap *lmapPtr = &(mapPtr->localMultimap_); @@ -751,9 +765,7 @@ class multimap_iterator : public std::iterator { if (static_cast(rt::thisLocality()) == 0) { auto localBegin = local_iterator_type::lmultimap_begin(lmapPtr); - if (localBegin != localEnd) { - return multimap_iterator(0, mapPtr->oid_, localBegin); - } + if (localBegin != localEnd) { return multimap_iterator(0, mapPtr->oid_, localBegin); } multimap_iterator beg(0, mapPtr->oid_, localEnd, T()); return ++beg; } @@ -777,8 +789,7 @@ class multimap_iterator : public std::iterator { } static multimap_iterator multimap_end(const MapT *mapPtr) { - local_iterator_type lend = - local_iterator_type::lmultimap_end(&(mapPtr->localMultimap_)); + local_iterator_type lend = local_iterator_type::lmultimap_end(&(mapPtr->localMultimap_)); multimap_iterator end(rt::numLocalities(), OIDT(0), lend, T()); return end; } @@ -787,9 +798,7 @@ class multimap_iterator : public std::iterator { return (data_ == other.data_); } - bool operator!=(const multimap_iterator &other) const { - return !(*this == other); - } + bool operator!=(const multimap_iterator &other) const { return !(*this == other); } T operator*() const { return data_.element_; } @@ -799,25 +808,19 @@ class multimap_iterator : public std::iterator { if (static_cast(rt::thisLocality()) == data_.locId_) { const LMap *lmapPtr = &(mapPtr->localMultimap_); auto lend = local_iterator_type::lmultimap_end(lmapPtr); - if (data_.lmapIt_ != lend) { - ++(data_.lmapIt_); - } + if (data_.lmapIt_ != lend) { ++(data_.lmapIt_); } if (data_.lmapIt_ != lend) { - data_.element_ = *(data_.lmapIt_); - return *this; + data_.element_ = *(data_.lmapIt_); + return *this; - } else { // find the local begin on next localities + } else { // find the local begin on next localities itData itd; for (uint32_t i = data_.locId_ + 1; i < rt::numLocalities(); ++i) { - rt::executeAtWithRet(rt::Locality(i), getLocBeginIt, data_.oid_, - &itd); + rt::executeAtWithRet(rt::Locality(i), getLocBeginIt, data_.oid_, &itd); // if Data is valid - if (itd.locId_ != rt::numLocalities()) { - data_ = itd; - return *this; - } + if (itd.locId_ != rt::numLocalities()) { data_ = itd; return *this; } } data_ = itData(rt::numLocalities(), OIDT(0), lend, T()); @@ -849,8 +852,7 @@ class multimap_iterator : public std::iterator { local_iterator_type end_; }; - static local_iterator_range local_range(multimap_iterator &B, - multimap_iterator &E) { + static local_iterator_range local_range(multimap_iterator &B, multimap_iterator &E) { auto mapPtr = MapT::GetPtr(B.data_.oid_); local_iterator_type lbeg, lend; uint32_t thisLocId = static_cast(rt::thisLocality()); @@ -870,26 +872,18 @@ class multimap_iterator : public std::iterator { return local_iterator_range(lbeg, lend); } - static rt::localities_range localities(multimap_iterator &B, - multimap_iterator &E) { + static rt::localities_range localities(multimap_iterator &B, multimap_iterator &E) { return rt::localities_range(rt::Locality(B.data_.locId_), - rt::Locality(std::min( - rt::numLocalities(), E.data_.locId_ + 1))); + rt::Locality(std::min(rt::numLocalities(), E.data_.locId_ + 1))); } - static multimap_iterator iterator_from_local(multimap_iterator &B, - multimap_iterator &E, - local_iterator_type itr) { - return multimap_iterator(static_cast(rt::thisLocality()), - B.data_.oid_, itr); + static multimap_iterator iterator_from_local(multimap_iterator &B, multimap_iterator &E, local_iterator_type itr) { + return multimap_iterator(static_cast(rt::thisLocality()), B.data_.oid_, itr); } private: struct itData { - itData() - : oid_(0), - lmapIt_(nullptr, 0, 0, nullptr, nullptr, - typename std::vector::iterator()) {} + itData() : oid_(0), lmapIt_(nullptr, 0, 0, nullptr, nullptr, typename std::vector::iterator()) {} itData(uint32_t locId, OIDT oid, local_iterator_type lmapIt, T element) : locId_(locId), oid_(oid), lmapIt_(lmapIt), element_(element) {} @@ -912,8 +906,7 @@ class multimap_iterator : public std::iterator { auto localEnd = local_iterator_type::lmultimap_end(lmapPtr); auto localBegin = local_iterator_type::lmultimap_begin(lmapPtr); if (localBegin != localEnd) { - *res = itData(static_cast(rt::thisLocality()), mapOID, - localBegin, *localBegin); + *res = itData(static_cast(rt::thisLocality()), mapOID, localBegin, *localBegin); } else { *res = itData(rt::numLocalities(), OIDT(0), localEnd, T()); } @@ -927,18 +920,14 @@ class multimap_iterator : public std::iterator { ++cit; if (cit != localEnd) { - *res = itData(static_cast(rt::thisLocality()), itd.oid_, cit, - *cit); + *res = itData(static_cast(rt::thisLocality()), itd.oid_, cit, *cit); return; } else { itData outitd; for (uint32_t i = itd.locId_ + 1; i < rt::numLocalities(); ++i) { rt::executeAtWithRet(rt::Locality(i), getLocBeginIt, itd.oid_, &outitd); // It Data is valid - if (outitd.locId_ != rt::numLocalities()) { - *res = outitd; - return; - } + if (outitd.locId_ != rt::numLocalities()) { *res = outitd; return; } } *res = itData(rt::numLocalities(), OIDT(0), localEnd, T()); }