Skip to content

Commit

Permalink
Merge pull request #1754 from DARMA-tasking/1715-allow-labels-on-obje…
Browse files Browse the repository at this point in the history
…ct-collections-and-groups

#1715 allow labels on object groups and collections
  • Loading branch information
nlslatt authored Jun 2, 2022
2 parents c1b5f62 + c6c6d25 commit 4feceef
Show file tree
Hide file tree
Showing 79 changed files with 534 additions and 270 deletions.
6 changes: 3 additions & 3 deletions docs/md/collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ definition (shown for a 1-dimensional collection):

\code{.cpp}
vt::NodeType my_map(vt::Index1D* idx, vt::Index1D* bounds, vt::NodeType num_nodes) {
return idx->x() % num_nodes;
return idx->x() % num_nodes;
}
\endcode

Expand Down Expand Up @@ -149,7 +149,7 @@ membership. This is performed in the following way (note that this is a
collective interface):

\code{.cpp}
auto proxy = vt::makeCollection<MyCollection>()
auto proxy = vt::makeCollection<MyCollection>("collection_label")
.dynamicMembership(true)
.collective(true)
.wait();
Expand All @@ -158,7 +158,7 @@ collective interface):
auto token = proxy.beginModification();
for (int i = 0; i < range.x() / 2; i++) {
if (i % num_nodes == this_node) {
proxy[i].insertAt(token, i % 2);
proxy[i].insertAt(token, i % 2);
}
}
proxy.finishModification(std::move(token));
Expand Down
4 changes: 2 additions & 2 deletions examples/callback/callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ int main(int argc, char** argv) {
return vt::rerror("requires at least 2 nodes");
}

auto obj = vt::theObjGroup()->makeCollective<MyObj>();
auto col = vt::makeCollection<MyCol>()
auto obj = vt::theObjGroup()->makeCollective<MyObj>("examples_callback");
auto col = vt::makeCollection<MyCol>("examples_callback")
.bounds(vt::Index1D(8))
.bulkInsert()
.wait();
Expand Down
2 changes: 1 addition & 1 deletion examples/collection/insertable_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int main(int argc, char** argv) {
}

auto range = vt::Index1D(num_elms);
auto proxy = vt::makeCollection<InsertCol>()
auto proxy = vt::makeCollection<InsertCol>("examples_insertable_collection")
.dynamicMembership(true)
.wait();

Expand Down
4 changes: 2 additions & 2 deletions examples/collection/jacobi1d_vt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ int main(int argc, char** argv) {

// Object group of all nodes that take part in computation
// Used to determine whether the computation is finished
auto grp_proxy = vt::theObjGroup()->makeCollective<NodeObj>();
auto grp_proxy = vt::theObjGroup()->makeCollective<NodeObj>("examples_jacobi1d");

// Create the decomposition into objects
using BaseIndexType = typename vt::Index1D::DenseIndexType;
auto range = vt::Index1D(static_cast<BaseIndexType>(num_objs));

auto col_proxy = vt::makeCollection<LinearPb1DJacobi>()
auto col_proxy = vt::makeCollection<LinearPb1DJacobi>("examples_jacobi1d")
.bounds(range)
.bulkInsert()
.wait();
Expand Down
4 changes: 2 additions & 2 deletions examples/collection/jacobi2d_vt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ int main(int argc, char** argv) {

// Object group of all nodes that take part in computation
// Used to determine whether the computation is finished
auto grp_proxy = vt::theObjGroup()->makeCollective<NodeObj>();
auto grp_proxy = vt::theObjGroup()->makeCollective<NodeObj>("examples_jacobi2d");

// Create the decomposition into objects
using BaseIndexType = typename vt::Index2D::DenseIndexType;
Expand All @@ -497,7 +497,7 @@ int main(int argc, char** argv) {
static_cast<BaseIndexType>(numY_objs)
);

auto col_proxy = vt::makeCollection<LinearPb2DJacobi>()
auto col_proxy = vt::makeCollection<LinearPb2DJacobi>("examples_jacobi2d")
.bounds(range)
.bulkInsert()
.wait();
Expand Down
2 changes: 1 addition & 1 deletion examples/collection/lb_iter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int main(int argc, char** argv) {
}

auto range = vt::Index1D(num_elms);
auto proxy = vt::makeCollection<IterCol>()
auto proxy = vt::makeCollection<IterCol>("examples_lb_iter")
.bounds(range)
.bulkInsert()
.wait();
Expand Down
2 changes: 1 addition & 1 deletion examples/collection/migrate_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int main(int argc, char** argv) {
}

auto range = vt::Index1D(num_elms);
auto proxy = vt::makeCollection<Hello>()
auto proxy = vt::makeCollection<Hello>("examples_migrate_collection")
.bounds(range)
.bulkInsert()
.wait();
Expand Down
2 changes: 1 addition & 1 deletion examples/collection/reduce_integral.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ int main(int argc, char** argv) {
using BaseIndexType = typename vt::Index1D::DenseIndexType;
auto range = vt::Index1D(static_cast<BaseIndexType>(num_objs));

auto proxy = vt::makeCollection<Integration1D>()
auto proxy = vt::makeCollection<Integration1D>("examples_reduce_integral")
.bounds(range)
.bulkInsert()
.wait();
Expand Down
2 changes: 1 addition & 1 deletion examples/collection/transpose.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ int main(int argc, char** argv) {
vt::NodeType this_node = vt::theContext()->getNode();

auto range = vt::Index1D(num_pieces);
auto proxy = vt::makeCollection<Block>()
auto proxy = vt::makeCollection<Block>("examples_transpose")
.bounds(range)
.bulkInsert()
.mapperFunc<my_map>()
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/hello_world_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main(int argc, char** argv) {

if (this_node == 0) {
auto range = vt::Index1D(num_elms);
auto proxy = vt::makeCollectionRooted<Hello>()
auto proxy = vt::makeCollectionRooted<Hello>("examples_hello_world_collection")
.bounds(range)
.bulkInsert()
.wait();
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/hello_world_collection_collective.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main(int argc, char** argv) {
}

auto range = vt::Index1D(num_elms);
auto proxy = vt::makeCollection<Hello>()
auto proxy = vt::makeCollection<Hello>("examples_hello_world_collection_collective")
.bounds(range)
.bulkInsert()
.wait();
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/hello_world_collection_reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char** argv) {
}

auto range = vt::Index1D(num_elms);
auto proxy = vt::makeCollection<Hello>()
auto proxy = vt::makeCollection<Hello>("hello_world_collection_reduce")
.bounds(range)
.bulkInsert()
.wait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int main(int argc, char** argv) {
}
}

auto proxy = vt::makeCollection<Hello>()
auto proxy = vt::makeCollection<Hello>("examples_hello_world_collection_staged_insert")
.bounds(range)
.listInsertHere(std::move(elms))
.wait();
Expand Down
4 changes: 3 additions & 1 deletion examples/hello_world/objgroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ int main(int argc, char** argv) {
vt::NodeType this_node = vt::theContext()->getNode();
vt::NodeType num_nodes = vt::theContext()->getNumNodes();

auto proxy = vt::theObjGroup()->makeCollective<MyObjGroup>();
auto proxy = vt::theObjGroup()->makeCollective<MyObjGroup>(
"examples_hello_world"
);

if (this_node == 0) {
proxy[0].send<MyMsg,&MyObjGroup::handler>(5,10);
Expand Down
4 changes: 3 additions & 1 deletion src/vt/messaging/collection_chain_set.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ CollectionChainSet<Index>::CollectionChainSet(
static_assert(std::is_same<IndexT, Index>::value, "Must match index type");

// Make this chain set an objgroup instance so we can send updates
auto p = theObjGroup()->makeCollective<CollectionChainSet<Index>>(this);
auto p = theObjGroup()->makeCollective<CollectionChainSet<Index>>(
this, "CollectionChainSet"
);

auto const this_node = theContext()->getNode();
auto const proxy_bits = proxy.getProxy();
Expand Down
4 changes: 3 additions & 1 deletion src/vt/objgroup/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void ObjGroupManager::dispatch(MsgSharedPtr<ShortMessage> msg, HandlerType han)
}

ObjGroupProxyType ObjGroupManager::makeCollectiveImpl(
HolderBasePtrType base, void* obj_ptr
std::string const& label, HolderBasePtrType base, void* obj_ptr
) {
auto const id = cur_obj_id_++;
auto const node = theContext()->getNode();
Expand All @@ -126,6 +126,8 @@ ObjGroupProxyType ObjGroupManager::makeCollectiveImpl(
std::forward_as_tuple(proxy),
std::forward_as_tuple(std::move(base))
);
labels_.emplace(proxy, label);

return proxy;
}

Expand Down
49 changes: 37 additions & 12 deletions src/vt/objgroup/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,34 +121,37 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
* \brief Collectively construct a new object group. Allocates and constructs
* the object on each node by forwarding constructor arguments.
*
* \param[in] label object group label
* \param[in] args args to pass to the object's constructor on each node
*
* \return proxy to the object group
*/
template <typename ObjT, typename... Args>
ProxyType<ObjT> makeCollective(Args&&... args);
ProxyType<ObjT> makeCollective(std::string const& label, Args&&... args);

/**
* \brief Collectively construct a new object group from a existing unique
* pointer to the local object
*
* \param[in] obj the std::unique_ptr<ObjT> to the local object
* \param[in] label object group label
*
* \return proxy to the object group
*/
template <typename ObjT>
ProxyType<ObjT> makeCollective(std::unique_ptr<ObjT> obj);
ProxyType<ObjT> makeCollective(std::unique_ptr<ObjT> obj, std::string const& label = {});

/**
* \brief Collectively construct a new object group with a callback to provide
* a unique pointer on each node.
*
* \param[in] fn callback function to construct
* \param[in] label object group label
*
* \return proxy to the object group
*/
template <typename ObjT>
ProxyType<ObjT> makeCollective(MakeFnType<ObjT> fn);
ProxyType<ObjT> makeCollective(MakeFnType<ObjT> fn, std::string const& label = {});

/**
* \brief Collectively construct a new object group from a raw pointer to the
Expand All @@ -159,23 +162,25 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
* is destroyed.
*
* \param[in] obj raw pointer to the object
* \param[in] label object group label
*
* \return proxy to the object group
*/
template <typename ObjT>
ProxyType<ObjT> makeCollective(ObjT* obj);
ProxyType<ObjT> makeCollective(ObjT* obj, std::string const& label = {});

/**
* \brief Collectively construct a new object group from a smart-pointer-like
* handle.
*
* \param[in] obj the smart-pointer-like handle that the system holds until
* destruction
* \param[in] label object group label
*
* \return proxy to the object group
*/
template <template <typename> class UserPtr, typename ObjT>
ProxyType<ObjT> makeCollective(UserPtr<ObjT> obj);
ProxyType<ObjT> makeCollective(UserPtr<ObjT> obj, std::string const& label = {});

/**
* \brief Collectively destroy an object group across the whole system
Expand Down Expand Up @@ -314,6 +319,17 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
template <typename ObjT>
ProxyElmType<ObjT> proxyElm(ObjT* obj);

/**
* \brief Get object group label
*
* \param[in] proxy indexed proxy to the object group (must be the current
* node)
*
* \return label of the Object Group
*/
template <typename ObjT>
std::string getLabel(ProxyType<ObjT> proxy) const;

/*
* Dispatch to a live obj group pointer with a handler
*/
Expand Down Expand Up @@ -370,7 +386,8 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
| dispatch_
| objs_
| obj_to_proxy_
| pending_;
| pending_
| labels_;
}

// Friend function to access the holder without including this header file
Expand All @@ -380,23 +397,29 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
/**
* \internal \brief Untyped system call to make a new collective objgroup
*
* \param[in] label object group label
* \param[in] b the base holder
* \param[in] obj_ptr type-erased pointer to the object
*
* \return a new untyped proxy
*/
ObjGroupProxyType makeCollectiveImpl(HolderBasePtrType b, void* obj_ptr);
ObjGroupProxyType makeCollectiveImpl(
std::string const& label, HolderBasePtrType b, void* obj_ptr
);

/**
* \internal \brief Typed system class to make a new collective objgroup
*
* \param[in] label
* \param[in] obj pointer to the object instance
* \param[in] base_holder the base holder
*
* \return the new typed proxy
*/
template <typename ObjT>
ProxyType<ObjT> makeCollectiveObj(ObjT* obj, HolderBasePtrType base_holder);
ProxyType<ObjT> makeCollectiveObj(
std::string const& label, ObjT* obj, HolderBasePtrType base_holder
);

/**
* \internal \brief Register a new objgroup with proxy
Expand Down Expand Up @@ -429,13 +452,15 @@ struct ObjGroupManager : runtime::component::Component<ObjGroupManager> {
/// The current obj ID, sequential on each node for collective construction
ObjGroupIDType cur_obj_id_ = fst_obj_group_id;
/// Function to dispatch to the base class for type-erasure to run handler
std::unordered_map<ObjGroupProxyType,DispatchBasePtrType> dispatch_;
std::unordered_map<ObjGroupProxyType, DispatchBasePtrType> dispatch_;
/// Type-erased pointers to the objects held on this node
std::unordered_map<ObjGroupProxyType,HolderBasePtrType> objs_;
std::unordered_map<ObjGroupProxyType, HolderBasePtrType> objs_;
/// Reverse lookup map from an object pointer to the proxy
std::unordered_map<void*,ObjGroupProxyType> obj_to_proxy_;
std::unordered_map<void*, ObjGroupProxyType> obj_to_proxy_;
/// Messages that are pending creation for delivery
std::unordered_map<ObjGroupProxyType,MsgContainerType> pending_;
std::unordered_map<ObjGroupProxyType, MsgContainerType> pending_;
/// Map of object groups' labels
std::unordered_map<ObjGroupProxyType, std::string> labels_;
};

}} /* end namespace vt::objgroup */
Expand Down
Loading

0 comments on commit 4feceef

Please sign in to comment.