diff --git a/include/shad/core/array.h b/include/shad/core/array.h index bd7aacda..a140622d 100644 --- a/include/shad/core/array.h +++ b/include/shad/core/array.h @@ -140,9 +140,9 @@ class array : public AbstractDataStructure> { /// @return an ::iterator to the beginning of the sequence. constexpr iterator begin() noexcept { if (rt::thisLocality() == rt::Locality(0)) { - return iterator{rt::Locality(0), 0, oid_, chunk_.get()}; + return iterator{rt::Locality(0), 0, this->oid_, chunk_.get()}; } - return iterator{rt::Locality(0), 0, oid_, nullptr}; + return iterator{rt::Locality(0), 0, this->oid_, nullptr}; } /// @brief The iterator to the beginning of the sequence. @@ -155,7 +155,7 @@ class array : public AbstractDataStructure> { if (N < rt::numLocalities()) { rt::Locality last(uint32_t(N - 1)); pointer chunk = last == rt::thisLocality() ? chunk_.get() : nullptr; - return iterator{std::forward(last), 1, oid_, chunk}; + return iterator{std::forward(last), 1, this->oid_, chunk}; } difference_type pos = chunk_size(); @@ -163,7 +163,7 @@ class array : public AbstractDataStructure> { rt::Locality last(rt::numLocalities() - 1); pointer chunk = last == rt::thisLocality() ? chunk_.get() : nullptr; - return iterator{std::forward(last), pos, oid_, chunk}; + return iterator{std::forward(last), pos, this->oid_, chunk}; } /// @brief The iterator to the end of the sequence. @@ -174,7 +174,7 @@ class array : public AbstractDataStructure> { /// @return a ::const_iterator to the beginning of the sequence. constexpr const_iterator cbegin() const noexcept { if (rt::thisLocality() == rt::Locality(0)) { - return const_iterator{rt::Locality(0), 0, oid_, chunk_.get()}; + return const_iterator{rt::Locality(0), 0, this->oid_, chunk_.get()}; } pointer chunk = nullptr; @@ -183,8 +183,8 @@ class array : public AbstractDataStructure> { auto This = array::GetPtr(ID); *result = This->chunk_.get(); }, - GetGlobalID(), &chunk); - return const_iterator{rt::Locality(0), 0, oid_, chunk}; + this->GetGlobalID(), &chunk); + return const_iterator{rt::Locality(0), 0, this->oid_, chunk}; } /// @brief The iterator to the end of the sequence. @@ -193,7 +193,7 @@ class array : public AbstractDataStructure> { if (N < rt::numLocalities()) { rt::Locality last(uint32_t(N - 1)); pointer chunk = last == rt::thisLocality() ? chunk_.get() : nullptr; - return const_iterator{std::forward(last), 1, oid_, chunk}; + return const_iterator{std::forward(last), 1, this->oid_, chunk}; } difference_type pos = chunk_size(); @@ -201,7 +201,7 @@ class array : public AbstractDataStructure> { rt::Locality last(rt::numLocalities() - 1); pointer chunk = last == rt::thisLocality() ? chunk_.get() : nullptr; - return const_iterator{std::forward(last), pos, oid_, chunk}; + return const_iterator{std::forward(last), pos, this->oid_, chunk}; } /// @} @@ -240,13 +240,13 @@ class array : public AbstractDataStructure> { if (n < chunk) { difference_type position(n); - return reference{l, position, oid_, nullptr}; + return reference{l, position, this->oid_, nullptr}; } n -= chunk; } difference_type position(n); - return reference{rt::Locality(rt::numLocalities() - 1), position, oid_, + return reference{rt::Locality(rt::numLocalities() - 1), position, this->oid_, nullptr}; } @@ -265,14 +265,14 @@ class array : public AbstractDataStructure> { if (n < chunk) { difference_type position(n); - return const_reference{l, position, oid_, nullptr}; + return const_reference{l, position, this->oid_, nullptr}; } n -= chunk; } difference_type position(n); return const_reference{rt::Locality(rt::numLocalities() - 1), position, - oid_, nullptr}; + this->oid_, nullptr}; } /// @brief Checked element access operator. @@ -305,14 +305,6 @@ class array : public AbstractDataStructure> { /// @} - /// @brief DataStructure identifier getter. - /// - /// Returns the global object identifier associated to a DataStructure - /// instance. - /// - /// @warning It must be implemented in the inheriting DataStructure. - ObjectID GetGlobalID() const { return oid_; } - friend bool operator!=(const array &LHS, const array &RHS) { bool result[rt::numLocalities()]; @@ -408,11 +400,10 @@ class array : public AbstractDataStructure> { } /// @brief Constructor. - explicit array(ObjectID oid) : chunk_{new T[chunk_size()]}, oid_{oid} {} + explicit array(ObjectID oid) : chunk_{new T[chunk_size()]}, AbstractDataStructure>(oid) {} private: std::unique_ptr chunk_; - ObjectID oid_; }; template diff --git a/include/shad/data_structures/abstract_data_structure.h b/include/shad/data_structures/abstract_data_structure.h index cb85308e..aa25cab0 100644 --- a/include/shad/data_structures/abstract_data_structure.h +++ b/include/shad/data_structures/abstract_data_structure.h @@ -61,8 +61,8 @@ class AbstractDataStructure { /// SharedPtr to DataStructure using SharedPtr = std::shared_ptr; - /// @brief Default constructor - AbstractDataStructure() = default; +/// @brief Constructor. + explicit AbstractDataStructure(ObjectID oid) : oid_(oid) {} /// @brief Create method. /// @@ -125,11 +125,11 @@ class AbstractDataStructure { /// /// Returns the global object identifier associated to a DataStructure /// instance. - /// - /// @warning It must be implemented in the inheriting DataStructure. - virtual ObjectID GetGlobalID() const = 0; + ObjectID GetGlobalID() const { return oid_; } protected: + const ObjectID oid_; + template static void UpdateCatalogAndConstruct(const ObjectID &oid, Args &&... args) { // Get a local instance on the remote node. diff --git a/include/shad/data_structures/array.h b/include/shad/data_structures/array.h index f17fab50..cbd4035a 100644 --- a/include/shad/data_structures/array.h +++ b/include/shad/data_structures/array.h @@ -59,11 +59,6 @@ class Array : public AbstractDataStructure> { using BuffersVector = impl::BuffersVector, Array>; using ShadArrayPtr = typename AbstractDataStructure>::SharedPtr; - /// @brief Retrieve the Global Identifier. - /// - /// @return The global identifier associated with the array instance. - ObjectID GetGlobalID() const { return oid_; } - /// @brief Return the size of the shad::Array. /// @return The size of the shad::Array. size_t Size() const noexcept { return size_; } @@ -460,7 +455,7 @@ class Array : public AbstractDataStructure> { protected: Array(ObjectID oid, size_t size, const T &initValue) - : oid_(oid), + : AbstractDataStructure>(oid), size_(size), pivot_((size % rt::numLocalities() == 0) ? rt::numLocalities() @@ -492,7 +487,6 @@ class Array : public AbstractDataStructure> { } private: - ObjectID oid_; size_t size_; uint32_t pivot_; std::vector data_; @@ -711,7 +705,7 @@ void Array::InsertAt(const size_t pos, const T &value) { if (target.first == rt::thisLocality()) { data_[target.second] = value; } else { - InsertAtArgs args = {oid_, target.second, value}; + InsertAtArgs args = {this->oid_, target.second, value}; rt::executeAt(target.first, InsertAtFun, args); } } @@ -723,7 +717,7 @@ void Array::AsyncInsertAt(rt::Handle &handle, const size_t pos, if (target.first == rt::thisLocality()) { data_[target.second] = value; } else { - InsertAtArgs args = {oid_, target.second, value}; + InsertAtArgs args = {this->oid_, target.second, value}; rt::asyncExecuteAt(handle, target.first, AsyncInsertAtFun, args); } } @@ -758,12 +752,12 @@ void Array::InsertAt(const size_t pos, const T *values, } else { chunkSize = constants::min(chunkSize, kMaxChunkSize); size_t argsSize = - sizeof(oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize; + sizeof(this->oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize; std::shared_ptr args(new uint8_t[argsSize], std::default_delete()); uint8_t *argsPtr = args.get(); - memcpy(argsPtr, &oid_, sizeof(oid_)); - argsPtr += sizeof(oid_); + memcpy(argsPtr, &this->oid_, sizeof(this->oid_)); + argsPtr += sizeof(this->oid_); memcpy(argsPtr, &tgtPos, sizeof(size_t)); argsPtr += sizeof(size_t); memcpy(argsPtr, &chunkSize, sizeof(size_t)); @@ -789,13 +783,13 @@ void Array::InsertAt(const size_t pos, const T *values, } else { chunkSize = constants::min(chunkSize, kMaxChunkSize); size_t argsSize = - sizeof(oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize; + sizeof(this->oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize; // FIXME(SHAD-125) std::shared_ptr args(new uint8_t[argsSize], std::default_delete()); uint8_t *argsPtr = args.get(); - memcpy(argsPtr, &oid_, sizeof(oid_)); - argsPtr += sizeof(oid_); + memcpy(argsPtr, &this->oid_, sizeof(this->oid_)); + argsPtr += sizeof(this->oid_); memcpy(argsPtr, &tgtPos, sizeof(size_t)); argsPtr += sizeof(size_t); memcpy(argsPtr, &chunkSize, sizeof(size_t)); @@ -839,14 +833,14 @@ void Array::AsyncInsertAt(rt::Handle &handle, const size_t pos, } else { chunkSize = constants::min(chunkSize, kMaxChunkSize); size_t argsSize = - sizeof(oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize; + sizeof(this->oid_) + sizeof(size_t) * 2 + sizeof(T) * chunkSize; // FIXME(SHAD-125) std::shared_ptr args(new uint8_t[argsSize], std::default_delete()); ; uint8_t *argsPtr = args.get(); - memcpy(argsPtr, &oid_, sizeof(oid_)); - argsPtr += sizeof(oid_); + memcpy(argsPtr, &this->oid_, sizeof(this->oid_)); + argsPtr += sizeof(this->oid_); memcpy(argsPtr, &tgtPos, sizeof(size_t)); argsPtr += sizeof(size_t); memcpy(argsPtr, &chunkSize, sizeof(size_t)); @@ -885,7 +879,7 @@ T Array::At(const size_t pos) { if (target.first == rt::thisLocality()) { retValue = data_[target.second]; } else { - AtArgs args{oid_, target.second}; + AtArgs args{this->oid_, target.second}; rt::executeAtWithRet(target.first, AtFun, args, &retValue); } return retValue; @@ -897,7 +891,7 @@ void Array::AsyncAt(rt::Handle &handle, const size_t pos, T *result) { if (target.first == rt::thisLocality()) { *result = data_[target.second]; } else { - AtArgs args = {oid_, target.second}; + AtArgs args = {this->oid_, target.second}; rt::asyncExecuteAtWithRet(handle, target.first, AsyncAtFun, args, result); } } @@ -914,7 +908,7 @@ void Array::Apply(const size_t pos, ApplyFunT &&function, Args &... args) { FunctionTy fn = std::forward(function); using ArgsTuple = std::tuple>; - ArgsTuple argsTuple{oid_, pos, target.second, fn, + ArgsTuple argsTuple{this->oid_, pos, target.second, fn, std::tuple(args...)}; rt::executeAt(target.first, ApplyFunWrapper, argsTuple); @@ -930,7 +924,7 @@ void Array::AsyncApply(rt::Handle &handle, const size_t pos, FunctionTy fn = std::forward(function); using ArgsTuple = std::tuple>; - ArgsTuple argsTuple{oid_, pos, target.second, fn, + ArgsTuple argsTuple{this->oid_, pos, target.second, fn, std::tuple(args...)}; rt::asyncExecuteAt(handle, target.first, @@ -951,7 +945,7 @@ void Array::ForEachInRange(const size_t first, const size_t last, size_t remainingValues = last - first; size_t chunkSize = 0; - ArgsTuple argsTuple{oid_, firstPos, tgtPos, fn, std::tuple(args...)}; + ArgsTuple argsTuple{this->oid_, firstPos, tgtPos, fn, std::tuple(args...)}; while (remainingValues > 0) { if (firstPos < pivot_ * (size_ / rt::numLocalities())) { tgtLoc = rt::Locality(firstPos / (size_ / rt::numLocalities())); @@ -993,7 +987,7 @@ void Array::AsyncForEachInRange(rt::Handle &handle, const size_t first, size_t remainingValues = last - first; size_t chunkSize = 0; // first it - ArgsTuple argsTuple{oid_, firstPos, tgtPos, fn, std::tuple(args...)}; + ArgsTuple argsTuple{this->oid_, firstPos, tgtPos, fn, std::tuple(args...)}; while (remainingValues > 0) { if (firstPos < pivot_ * (size_ / rt::numLocalities())) { @@ -1032,7 +1026,7 @@ void Array::AsyncForEach(rt::Handle &handle, ApplyFunT &&function, using feArgs = std::tuple>; using ArgsTuple = std::tuple>; - feArgs arguments{oid_, fn, std::tuple(args...)}; + feArgs arguments{this->oid_, fn, std::tuple(args...)}; auto feLambda = [](rt::Handle &handle, const feArgs &args) { auto arrayPtr = Array::GetPtr(std::get<0>(args)); @@ -1058,7 +1052,7 @@ void Array::ForEach(ApplyFunT &&function, Args &... args) { using feArgs = std::tuple>; using ArgsTuple = std::tuple>; - feArgs arguments{oid_, fn, std::tuple(args...)}; + feArgs arguments{this->oid_, fn, std::tuple(args...)}; auto feLambda = [](const feArgs &args) { auto arrayPtr = Array::GetPtr(std::get<0>(args)); diff --git a/include/shad/data_structures/hashmap.h b/include/shad/data_structures/hashmap.h index ae56e3e6..192a2ad3 100644 --- a/include/shad/data_structures/hashmap.h +++ b/include/shad/data_structures/hashmap.h @@ -102,11 +102,6 @@ class Hashmap : public AbstractDataStructure< static ShadHashmapPtr Create(const size_t numEntries); #endif - /// @brief Getter of the Global Identifier. - /// - /// @return The global identifier associated with the hashmap instance. - ObjectID GetGlobalID() const { return oid_; } - /// @brief Overall size of the hashmap (number of entries). /// @warning Calling the size method may result in one-to-all /// communication among localities to retrieve consinstent information. @@ -156,7 +151,7 @@ class Hashmap : public AbstractDataStructure< auto ptr = HmapT::GetPtr(oid); ptr->buffers_.FlushAll(); }; - rt::executeOnAll(flushLambda_, oid_); + rt::executeOnAll(flushLambda_, this->oid_); } /// @brief Remove a key-value pair from the hashmap. /// @param[in] key the key. @@ -176,7 +171,7 @@ class Hashmap : public AbstractDataStructure< auto mapPtr = HmapT::GetPtr(oid); mapPtr->localMap_.Clear(); }; - rt::executeOnAll(clearLambda, oid_); + rt::executeOnAll(clearLambda, this->oid_); } using LookupResult = @@ -297,7 +292,7 @@ class Hashmap : public AbstractDataStructure< std::cout << "---- Locality: " << rt::thisLocality() << std::endl; mapPtr->localMap_.PrintAllEntries(); }; - rt::executeOnAll(printLambda, oid_); + rt::executeOnAll(printLambda, this->oid_); } // FIXME it should be protected @@ -339,7 +334,6 @@ class Hashmap : public AbstractDataStructure< void buffered_async_flush() { WaitForBufferedInsert(); } private: - ObjectID oid_; LocalHashmap localMap_; BuffersVector buffers_; @@ -356,7 +350,8 @@ class Hashmap : public AbstractDataStructure< protected: Hashmap(ObjectID oid, const size_t numEntries) - : oid_(oid), + : AbstractDataStructure< + Hashmap>(oid), localMap_(std::max( numEntries / (constants::kDefaultNumEntriesPerBucket * rt::numLocalities()), @@ -375,7 +370,7 @@ inline size_t Hashmap::Size() const { }; for (auto tgtLoc : rt::allLocalities()) { if (tgtLoc != rt::thisLocality()) { - rt::executeAtWithRet(tgtLoc, sizeLambda, oid_, &remoteSize); + rt::executeAtWithRet(tgtLoc, sizeLambda, this->oid_, &remoteSize); size += remoteSize; } } @@ -410,7 +405,8 @@ Hashmap::Insert(const KTYPE &key, }; rt::executeAtWithRet( targetLocality, insertLambda, - std::make_tuple(begin(), end(), InsertArgs{oid_, key, value}), &res); + std::make_tuple(begin(), end(), InsertArgs{this->oid_, key, value}), + &res); } return res; } @@ -429,7 +425,7 @@ inline void Hashmap::AsyncInsert( auto mapPtr = HmapT::GetPtr(args.oid); mapPtr->localMap_.AsyncInsert(handle, args.key, args.value); }; - InsertArgs args = {oid_, key, value}; + InsertArgs args = {this->oid_, key, value}; rt::asyncExecuteAt(handle, targetLocality, insertLambda, args); } } @@ -468,7 +464,7 @@ inline void Hashmap::Erase( auto mapPtr = HmapT::GetPtr(args.oid); mapPtr->localMap_.Erase(args.key); }; - LookupArgs args = {oid_, key}; + LookupArgs args = {this->oid_, key}; rt::executeAt(targetLocality, eraseLambda, args); } } @@ -487,7 +483,7 @@ inline void Hashmap::AsyncErase( auto mapPtr = HmapT::GetPtr(args.oid); mapPtr->localMap_.AsyncErase(handle, args.key); }; - LookupArgs args = {oid_, key}; + LookupArgs args = {this->oid_, key}; rt::asyncExecuteAt(handle, targetLocality, eraseLambda, args); } } @@ -506,7 +502,7 @@ inline bool Hashmap::Lookup( auto mapPtr = HmapT::GetPtr(args.oid); res->found = mapPtr->localMap_.Lookup(args.key, &res->value); }; - LookupArgs args = {oid_, key}; + LookupArgs args = {this->oid_, key}; LookupResult lres; rt::executeAtWithRet(targetLocality, lookupLambda, args, &lres); if (lres.found) { @@ -534,7 +530,7 @@ inline void Hashmap::AsyncLookup( mapPtr->localMap_.Lookup(args.key, &tres); *res = tres; }; - LookupArgs args = {oid_, key}; + LookupArgs args = {this->oid_, key}; rt::asyncExecuteAtWithRet(handle, targetLocality, lookupLambda, args, res); } } @@ -549,7 +545,7 @@ void Hashmap::ForEachEntry( using feArgs = std::tuple>; using LMapPtr = LocalHashmap *; using ArgsTuple = std::tuple>; - feArgs arguments(oid_, fn, std::tuple(args...)); + feArgs arguments(this->oid_, fn, std::tuple(args...)); auto feLambda = [](const feArgs &args) { auto mapPtr = HmapT::GetPtr(std::get<0>(args)); ArgsTuple argsTuple(&mapPtr->localMap_, std::get<1>(args), @@ -570,7 +566,7 @@ void Hashmap::AsyncForEachEntry( FunctionTy fn = std::forward(function); using feArgs = std::tuple>; using ArgsTuple = std::tuple>; - feArgs arguments(oid_, fn, std::tuple(args...)); + feArgs arguments(this->oid_, fn, std::tuple(args...)); auto feLambda = [](rt::Handle &handle, const feArgs &args) { auto mapPtr = HmapT::GetPtr(std::get<0>(args)); ArgsTuple argsTuple(&mapPtr->localMap_, std::get<1>(args), @@ -592,7 +588,7 @@ void Hashmap::ForEachKey( FunctionTy fn = std::forward(function); using feArgs = std::tuple>; using ArgsTuple = std::tuple>; - feArgs arguments(oid_, fn, std::tuple(args...)); + feArgs arguments(this->oid_, fn, std::tuple(args...)); auto feLambda = [](const feArgs &args) { auto mapPtr = HmapT::GetPtr(std::get<0>(args)); ArgsTuple argsTuple(&mapPtr->localMap_, std::get<1>(args), @@ -613,7 +609,7 @@ void Hashmap::AsyncForEachKey( FunctionTy fn = std::forward(function); using feArgs = std::tuple>; using ArgsTuple = std::tuple>; - feArgs arguments(oid_, fn, std::tuple(args...)); + feArgs arguments(this->oid_, fn, std::tuple(args...)); auto feLambda = [](rt::Handle &handle, const feArgs &args) { auto mapPtr = HmapT::GetPtr(std::get<0>(args)); ArgsTuple argsTuple(&mapPtr->localMap_, std::get<1>(args), @@ -640,7 +636,7 @@ void Hashmap::Apply( FunctionTy fn = std::forward(function); using ArgsTuple = std::tuple>; - ArgsTuple arguments(oid_, key, fn, std::tuple(args...)); + ArgsTuple arguments(this->oid_, key, fn, std::tuple(args...)); auto feLambda = [](const ArgsTuple &args) { constexpr auto Size = std::tuple_size< typename std::decay(args))>::type>::value; @@ -670,7 +666,7 @@ void Hashmap::AsyncApply( FunctionTy fn = std::forward(function); using ArgsTuple = std::tuple>; - ArgsTuple arguments(oid_, key, fn, std::tuple(args...)); + ArgsTuple arguments(this->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; diff --git a/include/shad/data_structures/one_per_locality.h b/include/shad/data_structures/one_per_locality.h index e071d38e..dc690fa6 100644 --- a/include/shad/data_structures/one_per_locality.h +++ b/include/shad/data_structures/one_per_locality.h @@ -57,11 +57,6 @@ class OnePerLocality : public AbstractDataStructure> { static SharedPtr Create(Args... args); #endif - /// @brief Retieve the Global Identifier. - /// - /// @return The global identifier associated with the array instance. - ObjectID GetGlobalID() const { return oid_; } - /// @brief Access the local instance. /// /// @return A pointer to the local instance. @@ -83,13 +78,12 @@ class OnePerLocality : public AbstractDataStructure> { /// @brief Constructor. template explicit OnePerLocality(ObjectID oid, Args... args) - : oid_{oid}, localInstance_{args...} {} + : AbstractDataStructure>{oid}, localInstance_{args...} {} private: template friend class AbstractDataStructure; - ObjectID oid_; T localInstance_; }; diff --git a/include/shad/data_structures/set.h b/include/shad/data_structures/set.h index 935f66b1..83c9337a 100644 --- a/include/shad/data_structures/set.h +++ b/include/shad/data_structures/set.h @@ -78,11 +78,6 @@ class Set : public AbstractDataStructure> { static ShadSetPtr Create(const size_t numEntries); #endif - /// @brief Getter of the Global Identifier. - /// - /// @return The global identifier associated with the set instance. - ObjectID GetGlobalID() const { return oid_; } - /// @brief Overall size of the set (number of elements). /// @warning Calling the size method may result in one-to-all /// communication among localities to retrieve consinstent information. @@ -140,7 +135,7 @@ class Set : public AbstractDataStructure> { auto setPtr = SetT::GetPtr(oid); setPtr->localSet_.Clear(); }; - rt::executeOnAll(clearLambda, oid_); + rt::executeOnAll(clearLambda, this->oid_); } /// @brief Clear the content of the set. @@ -149,7 +144,7 @@ class Set : public AbstractDataStructure> { auto setPtr = SetT::GetPtr(std::get<0>(t)); setPtr->localSet_.Reset(std::get<1>(t)); }; - rt::executeOnAll(resetLambda, std::make_tuple(oid_, numElements)); + rt::executeOnAll(resetLambda, std::make_tuple(this->oid_, numElements)); } /// @brief Check if the set contains a given element. /// @param[in] element the element to find. @@ -203,7 +198,7 @@ class Set : public AbstractDataStructure> { std::cout << "---- Locality: " << rt::thisLocality() << std::endl; setPtr->localSet_.PrintAllElements(); }; - rt::executeOnAll(printLambda, oid_); + rt::executeOnAll(printLambda, this->oid_); } // FIXME it should be protected @@ -243,7 +238,6 @@ class Set : public AbstractDataStructure> { void buffered_async_flush() { WaitForBufferedInsert(); } private: - ObjectID oid_; LocalSet localSet_; BuffersVector buffers_; @@ -254,7 +248,7 @@ class Set : public AbstractDataStructure> { protected: Set(ObjectID oid, const size_t numEntries) - : oid_(oid), + : AbstractDataStructure>(oid), localSet_( std::max(numEntries / (constants::kSetDefaultNumEntriesPerBucket * rt::numLocalities()), @@ -272,7 +266,7 @@ inline size_t Set::Size() const { }; for (auto tgtLoc : rt::allLocalities()) { if (tgtLoc != rt::thisLocality()) { - rt::executeAtWithRet(tgtLoc, sizeLambda, oid_, &remoteSize); + rt::executeAtWithRet(tgtLoc, sizeLambda, this->oid_, &remoteSize); size += remoteSize; } } @@ -302,7 +296,7 @@ Set::Insert(const T& element) { *res_ptr = std::make_pair(git, lres.second); }; rt::executeAtWithRet(targetLocality, insertLambda, - std::make_tuple(begin(), end(), oid_, element), &res); + std::make_tuple(begin(), end(), this->oid_, element), &res); return res; } @@ -318,7 +312,7 @@ inline void Set::AsyncInsert(rt::Handle& handle, auto setPtr = SetT::GetPtr(args.oid); setPtr->localSet_.AsyncInsert(handle, args.element); }; - ExeAtArgs args = {oid_, element}; + ExeAtArgs args = {this->oid_, element}; rt::asyncExecuteAt(handle, targetLocality, insertLambda, args); } } @@ -349,7 +343,7 @@ inline void Set::Erase(const T& element) { auto setPtr = SetT::GetPtr(args.oid); setPtr->localSet_.Erase(args.element); }; - ExeAtArgs args = {oid_, element}; + ExeAtArgs args = {this->oid_, element}; rt::executeAt(targetLocality, eraseLambda, args); } } @@ -366,7 +360,7 @@ inline void Set::AsyncErase(rt::Handle& handle, auto setPtr = SetT::GetPtr(args.oid); setPtr->localSet_.AsyncErase(handle, args.element); }; - ExeAtArgs args = {oid_, element}; + ExeAtArgs args = {this->oid_, element}; rt::asyncExecuteAt(handle, targetLocality, eraseLambda, args); } } @@ -382,7 +376,7 @@ inline bool Set::Find(const T& element) { auto setPtr = SetT::GetPtr(args.oid); *res = setPtr->localSet_.Find(args.element); }; - ExeAtArgs args = {oid_, element}; + ExeAtArgs args = {this->oid_, element}; bool found; rt::executeAtWithRet(targetLocality, findLambda, args, &found); return found; @@ -403,7 +397,7 @@ inline void Set::AsyncFind(rt::Handle& handle, auto setPtr = SetT::GetPtr(args.oid); *res = setPtr->localSet_.Find(args.element); }; - ExeAtArgs args = {oid_, element}; + ExeAtArgs args = {this->oid_, element}; rt::asyncExecuteAtWithRet(handle, targetLocality, findLambda, args, found); } } @@ -415,7 +409,7 @@ void Set::ForEachElement(ApplyFunT&& function, Args&... args) { FunctionTy fn = std::forward(function); using feArgs = std::tuple>; using ArgsTuple = std::tuple>; - feArgs arguments(oid_, fn, std::tuple(args...)); + feArgs arguments(this->oid_, fn, std::tuple(args...)); auto feLambda = [](const feArgs& args) { auto setPtr = SetT::GetPtr(std::get<0>(args)); ArgsTuple argsTuple(&setPtr->localSet_, std::get<1>(args), @@ -436,7 +430,7 @@ void Set::AsyncForEachElement(rt::Handle& handle, FunctionTy fn = std::forward(function); using feArgs = std::tuple>; using ArgsTuple = std::tuple>; - feArgs arguments{oid_, fn, std::tuple(args...)}; + feArgs arguments{this->oid_, fn, std::tuple(args...)}; auto feLambda = [](rt::Handle& handle, const feArgs& args) { auto setPtr = SetT::GetPtr(std::get<0>(args)); ArgsTuple argsTuple = std::make_tuple(&setPtr->localSet_, std::get<1>(args), diff --git a/include/shad/data_structures/vector.h b/include/shad/data_structures/vector.h index f74d901d..63888c72 100644 --- a/include/shad/data_structures/vector.h +++ b/include/shad/data_structures/vector.h @@ -493,8 +493,6 @@ class Vector : public AbstractDataStructure> { /// @} - ObjectID GetGlobalID() const { return oid_; } - /// @brief Destructor. ~Vector() { _clear(); } @@ -506,7 +504,7 @@ class Vector : public AbstractDataStructure> { protected: Vector(ObjectID oid, size_type n) - : oid_(oid), + : AbstractDataStructure>(oid), dataBlocks_(), mainLocality_(static_cast(oid) % rt::numLocalities()), sizeCapacityLock_(), @@ -601,7 +599,7 @@ class Vector : public AbstractDataStructure> { This->allocator_, kBlockSize)); } }, - std::make_pair(oid_, newBlocks[i])); + std::make_pair(this->oid_, newBlocks[i])); } rt::waitForCompletion(handle); @@ -722,7 +720,6 @@ class Vector : public AbstractDataStructure> { impl::BuffersVector, Vector>; friend class impl::BuffersVector, Vector>; - ObjectID oid_; rt::Locality mainLocality_; std::vector dataBlocks_; rt::Lock sizeCapacityLock_; @@ -841,7 +838,7 @@ typename Vector::size_type Vector::Size() const auto This = Vector::GetPtr(oid); *size = This->size_; }, - oid_, &size); + this->oid_, &size); return size; } @@ -862,7 +859,7 @@ typename Vector::size_type Vector::Capacity() const auto ptr = Vector::GetPtr(oid); *capacity = ptr->capacity_; }, - oid_, &capacity); + this->oid_, &capacity); return capacity; } @@ -881,7 +878,7 @@ void Vector::Reserve(Vector::size_type n) { std::lock_guard _(This->sizeCapacityLock_); This->_reserve(n); }, - std::make_pair(oid_, n)); + std::make_pair(this->oid_, n)); } template @@ -897,7 +894,7 @@ void Vector::Resize(Vector::size_type n) { This->_reserve(n); This->size_ = n; }, - std::make_pair(oid_, n)); + std::make_pair(this->oid_, n)); } template @@ -922,7 +919,7 @@ typename Vector::value_type Vector::At( *result = This->dataBlocks_[localBlock][std::get<2>(args)]; }, - std::make_tuple(oid_, blockNumber, offset), &value); + std::make_tuple(this->oid_, blockNumber, offset), &value); return value; } } @@ -963,7 +960,7 @@ void Vector::AsyncAt( *result = This->dataBlocks_[localBlock][std::get<2>(args)]; }, - std::make_tuple(oid_, blockNumber, offset), result); + std::make_tuple(this->oid_, blockNumber, offset), result); } template @@ -983,7 +980,7 @@ void Vector::Clear() noexcept { }, args); }, - oid_); + this->oid_); } template @@ -1000,7 +997,7 @@ void Vector::PushBack( if (This->size_ > This->capacity_) This->_reserve(This->size_); }, - oid_, &newSize); + this->oid_, &newSize); size_type position = newSize - 1; @@ -1024,7 +1021,7 @@ void Vector::PushBack( This->dataBlocks_[localBlock][std::get<2>(args)] = std::get<3>(args); }, - std::make_tuple(oid_, blockNumber, offset, value)); + std::make_tuple(this->oid_, blockNumber, offset, value)); } } @@ -1052,10 +1049,10 @@ typename Vector::iterator Vector::InsertAt( This->dataBlocks_[localBlock][std::get<2>(args)] = std::get<3>(args); }, - std::make_tuple(oid_, blockNumber, offset, value)); + std::make_tuple(this->oid_, blockNumber, offset, value)); } - return Vector::iterator(position, GetGlobalID()); + return Vector::iterator(position, this->GetGlobalID()); } template @@ -1069,7 +1066,7 @@ typename Vector::iterator Vector::InsertAt( rt::waitForCompletion(handle); - return Vector::iterator(position, GetGlobalID()); + return Vector::iterator(position, this->GetGlobalID()); } template @@ -1098,7 +1095,7 @@ void Vector::AsyncInsertAt( This->dataBlocks_[localBlock][std::get<2>(args)] = std::get<3>(args); }, - std::make_tuple(oid_, blockNumber, offset, value)); + std::make_tuple(this->oid_, blockNumber, offset, value)); } } @@ -1132,7 +1129,7 @@ void Vector::AsyncInsertAt( *size = This->size_; }, - std::make_tuple(oid_, position, newElements), &newSize); + std::make_tuple(this->oid_, position, newElements), &newSize); // Trying to insert in an invalid position. if (position > newSize) { @@ -1167,7 +1164,7 @@ void Vector::AsyncInsertAt( InsertMessage args; size_t spaceLeftInBlock = kBlockSize - (startingPoint % kBlockSize); // first block - args.objID = oid_; + args.objID = this->oid_; args.startPosition = startingPoint; args.numElements = std::min(newElements, std::min(kNumElements, spaceLeftInBlock)); @@ -1254,7 +1251,7 @@ void Vector::Apply(const Vector::size_type position, FunctionTy fn = std::forward(function); using ArgsTuple = std::tuple>; - ArgsTuple argsTuple{oid_, position, fn, std::tuple(args...)}; + ArgsTuple argsTuple{this->oid_, position, fn, std::tuple(args...)}; rt::executeAt(target, ApplyFunWrapper, argsTuple); } @@ -1274,7 +1271,7 @@ void Vector::AsyncApply( FunctionTy fn = std::forward(function); using ArgsTuple = std::tuple>; - ArgsTuple argsTuple{oid_, position, fn, std::tuple(args...)}; + ArgsTuple argsTuple{this->oid_, position, fn, std::tuple(args...)}; rt::asyncExecuteAt(handle, target, AsyncApplyFunWrapper, argsTuple); @@ -1303,7 +1300,7 @@ void Vector::ForEachInRange(const size_type begin, std::tie(target, std::ignore, std::ignore) = _targetFromPosition(start, kBlockSize); - ArgsTuple argsTuple{oid_, start, fn, std::tuple(args...)}; + ArgsTuple argsTuple{this->oid_, start, fn, std::tuple(args...)}; rt::forEachAt(target, ForEachInRangeFunWrapper, argsTuple, blockSize); @@ -1351,7 +1348,7 @@ void Vector::AsyncForEachInRange(rt::Handle &handle, std::tie(target, std::ignore, std::ignore) = _targetFromPosition(start, kBlockSize); - ArgsTuple argsTuple{oid_, start, fn, std::tuple(args...)}; + ArgsTuple argsTuple{this->oid_, start, fn, std::tuple(args...)}; rt::asyncForEachAt(handle, target, AsyncForEachInRangeFunWrapper, diff --git a/include/shad/extensions/graph_library/edge_index.h b/include/shad/extensions/graph_library/edge_index.h index fd1e9680..217d592c 100755 --- a/include/shad/extensions/graph_library/edge_index.h +++ b/include/shad/extensions/graph_library/edge_index.h @@ -85,11 +85,6 @@ class EdgeIndex static EdgeIndexPtr Create(const size_t numVertices); #endif - /// @brief Getter of the Global Identifier. - /// - /// @return The global identifier associated with the hashmap instance. - ObjectID GetGlobalID() const { return oid_; } - /// @brief Overall size of the edge index (number of unique sources). /// @return the number of unique source vertices in the index. size_t Size() const; @@ -192,7 +187,7 @@ class EdgeIndex auto ptr = EdgeIndex::GetPtr(oid); ptr->buffers_.FlushAll(); }; - rt::executeOnAll(flushLambda_, oid_); + rt::executeOnAll(flushLambda_, this->oid_); } /// @brief Delete an edge. @@ -357,7 +352,6 @@ class EdgeIndex Args &... args); private: - ObjectID oid_; LocalEdgeIndex localIndex_; BuffersVector buffers_; @@ -380,7 +374,7 @@ class EdgeIndex using LocalEdgeListChunk = typename StorageT::LocalEdgeListChunk; struct EdgeListChunk { - EdgeListChunk(ObjectID &_oid, SrcT _src, LocalEdgeListChunk &_chunk) + EdgeListChunk(ObjectID _oid, SrcT _src, LocalEdgeListChunk &_chunk) : oid(_oid), src(_src), chunk(_chunk) {} typename EdgeIndex::ObjectID oid; SrcT src; @@ -445,10 +439,14 @@ class EdgeIndex protected: EdgeIndex(ObjectID oid, const size_t numVertices) - : oid_(oid), localIndex_(numVertices), buffers_(oid) {} + : AbstractDataStructure>(oid), + localIndex_(numVertices), + buffers_(oid) {} EdgeIndex(ObjectID oid, const size_t numVertices, const typename StorageT::SrcAttributesT &initAttr) - : oid_(oid), localIndex_(numVertices, initAttr), buffers_(oid) {} + : AbstractDataStructure>(oid), + localIndex_(numVertices, initAttr), + buffers_(oid) {} }; template @@ -461,7 +459,7 @@ inline size_t EdgeIndex::Size() const { }; for (auto tgtLoc : rt::allLocalities()) { if (tgtLoc != rt::thisLocality()) { - rt::executeAtWithRet(tgtLoc, sizeLambda, oid_, &remoteSize); + rt::executeAtWithRet(tgtLoc, sizeLambda, this->oid_, &remoteSize); size += remoteSize; } } @@ -478,7 +476,7 @@ inline size_t EdgeIndex::NumEdges() { }; for (auto tgtLoc : rt::allLocalities()) { if (tgtLoc != rt::thisLocality()) { - rt::executeAtWithRet(tgtLoc, sizeLambda, oid_, &remoteSize); + rt::executeAtWithRet(tgtLoc, sizeLambda, this->oid_, &remoteSize); size += remoteSize; } } @@ -499,7 +497,7 @@ inline size_t EdgeIndex::GetDegree(const SrcT &src) { *res = ptr->localIndex_.GetDegree(std::get<1>(args)); }; rt::executeAtWithRet(targetLocality, degreeLambda, - std::make_tuple(oid_, src), °ree); + std::make_tuple(this->oid_, src), °ree); } return degree; } @@ -517,7 +515,7 @@ inline void EdgeIndex::Insert(const SrcT &src, auto ptr = EdgeIndex::GetPtr(args.oid); ptr->localIndex_.Insert(args.src, args.dest); }; - InsertArgs args{oid_, src, dest}; + InsertArgs args{this->oid_, src, dest}; rt::executeAt(targetLocality, insertLambda, args); } } @@ -538,14 +536,14 @@ inline void EdgeIndex::InsertEdgeList( size_t locSize = StorageT::kEdgeListChunkSize_; size_t chunkSize = std::min(locSize, toInsert); LocalEdgeListChunk lchunk(numDest, overwrite, destinations); - EdgeListChunk args(oid_, src, lchunk); + EdgeListChunk args(this->oid_, src, lchunk); rt::executeAt(targetLocality, insertLambda, args); toInsert -= chunkSize; while (toInsert > 0) { destinations += chunkSize; chunkSize = std::min(locSize, toInsert); LocalEdgeListChunk lchunk(chunkSize, false, destinations); - EdgeListChunk args(oid_, src, lchunk); + EdgeListChunk args(this->oid_, src, lchunk); rt::executeAt(targetLocality, insertLambda, args); toInsert -= chunkSize; } @@ -575,7 +573,7 @@ inline void EdgeIndex::AsyncInsertEdgeList( size_t locSize = StorageT::kEdgeListChunkSize_; size_t chunkSize = std::min(locSize, toInsert); LocalEdgeListChunk lchunk(numDest, overwrite, destinations); - EdgeListChunk args(oid_, src, lchunk); + EdgeListChunk args(this->oid_, src, lchunk); if (numDest <= locSize) { rt::asyncExecuteAt(handle, targetLocality, insertLambda, args); return; @@ -587,7 +585,7 @@ inline void EdgeIndex::AsyncInsertEdgeList( destinations += chunkSize; chunkSize = std::min(locSize, toInsert); lchunk = LocalEdgeListChunk(chunkSize, false, destinations); - args = EdgeListChunk(oid_, src, lchunk); + args = EdgeListChunk(this->oid_, src, lchunk); rt::asyncExecuteAt(handle, targetLocality, insertLambda, args); toInsert -= chunkSize; } @@ -608,7 +606,7 @@ inline void EdgeIndex::AsyncInsert(rt::Handle &handle, auto ptr = EdgeIndex::GetPtr(args.oid); ptr->localIndex_.AsyncInsert(handle, args.src, args.dest); }; - InsertArgs args = {oid_, src, dest}; + InsertArgs args = {this->oid_, src, dest}; rt::asyncExecuteAt(handle, targetLocality, insertLambda, args); } } @@ -626,7 +624,7 @@ inline void EdgeIndex::Erase(const SrcT &src, auto ptr = EdgeIndex::GetPtr(args.oid); ptr->localIndex_.Erase(args.src, args.dest); }; - InsertArgs args = {oid_, src, dest}; + InsertArgs args = {this->oid_, src, dest}; rt::executeAt(targetLocality, eraseLambda, args); } } @@ -645,7 +643,7 @@ inline void EdgeIndex::AsyncErase(rt::Handle &handle, auto ptr = EdgeIndex::GetPtr(args.oid); ptr->localIndex_.AsyncErase(handle, args.src, args.dest); }; - InsertArgs args = {oid_, src, dest}; + InsertArgs args = {this->oid_, src, dest}; rt::asyncExecuteAt(handle, targetLocality, eraseLambda, args); } } @@ -681,7 +679,7 @@ void EdgeIndex::ForEachVertex(ApplyFunT &&function, using FunctionTy = void (*)(const SrcT &src, Args &...); FunctionTy fn = std::forward(function); using feArgs = std::tuple>; - feArgs arguments(oid_, fn, std::tuple(args...)); + feArgs arguments(this->oid_, fn, std::tuple(args...)); auto feLambda = [](const feArgs &args) { constexpr auto size = std::tuple_size< typename std::decay(args))>::type>::value; @@ -700,7 +698,7 @@ void EdgeIndex::AsyncForEachVertex(rt::Handle &handle, using FunctionTy = void (*)(rt::Handle & h, const SrcT &src, Args &...); FunctionTy fn = std::forward(function); using feArgs = std::tuple>; - feArgs arguments(oid_, fn, std::tuple(args...)); + feArgs arguments(this->oid_, fn, std::tuple(args...)); auto feLambda = [](rt::Handle &handle, const feArgs &args) { constexpr auto size = std::tuple_size< typename std::decay(args))>::type>::value; @@ -726,7 +724,7 @@ void EdgeIndex::ForEachNeighbor(const SrcT &src, using FunctionTy = void (*)(const SrcT &src, const DestT &dest, Args &...); FunctionTy fn = std::forward(function); using feArgs = std::tuple>; - feArgs arguments(oid_, src, fn, std::tuple(args...)); + feArgs arguments(this->oid_, src, fn, std::tuple(args...)); auto feLambda = [](const feArgs &args) { feArgs &fargs = const_cast(args); constexpr auto size = std::tuple_size< @@ -752,7 +750,7 @@ void EdgeIndex::AsyncForEachNeighbor( const DestT &dest, Args &...); FunctionTy fn = std::forward(function); using feArgs = std::tuple>; - feArgs arguments(oid_, src, fn, std::tuple(args...)); + feArgs arguments(this->oid_, src, fn, std::tuple(args...)); auto feLambda = [](rt::Handle &handle, const feArgs &args) { feArgs &fargs = const_cast(args); constexpr auto size = std::tuple_size< @@ -771,7 +769,7 @@ void EdgeIndex::ForEachEdge(ApplyFunT &&function, using FunctionTy = void (*)(const SrcT &src, const DestT &dest, Args &...); FunctionTy fn = std::forward(function); using feArgs = std::tuple>; - feArgs arguments(oid_, fn, std::tuple(args...)); + feArgs arguments(this->oid_, fn, std::tuple(args...)); auto feLambda = [](const feArgs &args) { feArgs &fargs = const_cast(args); constexpr auto size = std::tuple_size< @@ -791,7 +789,7 @@ void EdgeIndex::AsyncForEachEdge(rt::Handle &handle, const DestT &dest, Args &...); FunctionTy fn = std::forward(function); using feArgs = std::tuple>; - feArgs arguments(oid_, fn, std::tuple(args...)); + feArgs arguments(this->oid_, fn, std::tuple(args...)); auto feLambda = [](rt::Handle &handle, const feArgs &args) { feArgs &fargs = const_cast(args); constexpr auto size = std::tuple_size< @@ -816,7 +814,7 @@ bool EdgeIndex::GetVertexAttributes( auto eiPtr = EdgeIndex::GetPtr(args.oid); res->found = eiPtr->localIndex_.GetVertexAttributes(args.src, &res->attr); }; - LookupArgs args = {oid_, src}; + LookupArgs args = {this->oid_, src}; LookupResult lres; rt::executeAtWithRet(targetLocality, lookupLambda, args, &lres); if (lres.found) { @@ -843,7 +841,7 @@ void EdgeIndex::VertexAttributesApply( FunctionTy fn = std::forward(function); using ApplyArgs = std::tuple>; - ApplyArgs arguments(oid_, src, fn, std::tuple(args...)); + ApplyArgs arguments(this->oid_, src, fn, std::tuple(args...)); auto applyLambda = [](const ApplyArgs &args) { ApplyArgs &tuple = const_cast(args); constexpr auto Size = std::tuple_size<