From 5a65e03a840ab84ff07b4f25f28b4d0eae484552 Mon Sep 17 00:00:00 2001 From: Matthieu Dorier Date: Fri, 7 Jun 2024 15:38:29 +0100 Subject: [PATCH] updated C++ and python wrappers --- CMakeLists.txt | 2 + include/flock/cxx/client.hpp | 15 +- include/flock/cxx/group-view.hpp | 160 ++++++++++++++-------- include/flock/cxx/group.hpp | 56 -------- include/flock/cxx/server.hpp | 22 ++- python/CMakeLists.txt | 6 +- python/src/py-flock-client.cpp | 144 ++++---------------- python/src/py-flock-common.cpp | 39 +++++- python/src/py-flock-server.cpp | 226 +------------------------------ spack.yaml | 1 + src/CMakeLists.txt | 8 +- tests/spack.yaml | 1 + 12 files changed, 207 insertions(+), 473 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 071ce5d..a07ff11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,8 @@ endif () pkg_check_modules (margo REQUIRED IMPORTED_TARGET margo) # search for json-c pkg_check_modules (json-c REQUIRED IMPORTED_TARGET json-c) +# search for thallium +find_package (thallium REQUIRED) if (ENABLE_MPI) find_package (MPI REQUIRED) diff --git a/include/flock/cxx/client.hpp b/include/flock/cxx/client.hpp index c1f0a83..91ad41c 100644 --- a/include/flock/cxx/client.hpp +++ b/include/flock/cxx/client.hpp @@ -6,6 +6,7 @@ #ifndef __FLOCK_CLIENT_HPP #define __FLOCK_CLIENT_HPP +#include #include #include #include @@ -19,11 +20,18 @@ class Client { Client() = default; - Client(margo_instance_id mid, ABT_pool pool = ABT_POOL_NULL) { + Client(margo_instance_id mid, ABT_pool pool = ABT_POOL_NULL) + : m_engine{mid} { auto err = flock_client_init(mid, pool, &m_client); FLOCK_CONVERT_AND_THROW(err); } + Client(const thallium::engine& engine, thallium::pool pool = thallium::pool()) + : m_engine{engine} { + auto err = flock_client_init(engine.get_margo_instance(), pool.native_handle(), &m_client); + FLOCK_CONVERT_AND_THROW(err); + } + ~Client() { if(m_client != FLOCK_CLIENT_NULL) { flock_client_finalize(m_client); @@ -68,8 +76,13 @@ class Client { return m_client; } + auto engine() const { + return m_engine; + } + private: + thallium::engine m_engine; flock_client_t m_client = FLOCK_CLIENT_NULL; }; diff --git a/include/flock/cxx/group-view.hpp b/include/flock/cxx/group-view.hpp index 3fd69fe..07e91d1 100644 --- a/include/flock/cxx/group-view.hpp +++ b/include/flock/cxx/group-view.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -27,9 +28,98 @@ class GroupView { public: struct Member { - uint64_t rank; - uint16_t provider_id; std::string address; + uint16_t provider_id; + }; + + struct Metadata { + std::string key; + std::string value; + }; + + struct MembersProxy { + + private: + + friend class GroupView; + + GroupView& m_owner; + + MembersProxy(GroupView& gv) + : m_owner(gv) {} + + public: + + MembersProxy(MembersProxy&&) = default; + + void add(const char* address, uint16_t provider_id) { + flock_group_view_add_member(&m_owner.m_view, address, provider_id); + } + + void remove(size_t index) { + auto member = flock_group_view_member_at(&m_owner.m_view, index); + if(!flock_group_view_remove_member(&m_owner.m_view, member)) + throw Exception{FLOCK_ERR_NO_MEMBER}; + } + + void remove(const char* address, uint16_t provider_id) { + auto member = flock_group_view_find_member(&m_owner.m_view, address, provider_id); + if(!flock_group_view_remove_member(&m_owner.m_view, member)) + throw Exception{FLOCK_ERR_NO_MEMBER}; + } + + bool exists(const char* address, uint16_t provider_id) const { + return static_cast(flock_group_view_find_member( + const_cast(&m_owner.m_view), address, provider_id)); + } + + size_t count() const { + return flock_group_view_member_count(&m_owner.m_view); + } + + Member operator[](size_t i) const { + if(i >= count()) throw std::out_of_range{"Invalid member index"}; + auto member = flock_group_view_member_at(&m_owner.m_view, i); + return Member{member->address, member->provider_id}; + } + }; + + struct MetadataProxy { + + private: + + friend class GroupView; + + GroupView& m_owner; + + MetadataProxy(GroupView& gv) + : m_owner(gv) {} + + public: + + MetadataProxy(MetadataProxy&&) = default; + + void add(const char* key, const char* value) { + flock_group_view_add_metadata(&m_owner.m_view, key, value); + } + + void remove(const char* key) { + flock_group_view_remove_metadata(&m_owner.m_view, key); + } + + size_t count() const { + return flock_group_view_metadata_count(&m_owner.m_view); + } + + Metadata operator[](size_t i) const { + if(i >= count()) throw std::out_of_range{"Invalid metadata index"}; + auto metadata = flock_group_view_metadata_at(&m_owner.m_view, i); + return Metadata{metadata->key, metadata->value}; + } + + const char* operator[](const char* key) const { + return flock_group_view_find_metadata(&m_owner.m_view, key); + } }; GroupView() = default; @@ -39,7 +129,7 @@ class GroupView { } ~GroupView() { - flock_group_view_clear(&m_view); + clear(); } GroupView(GroupView&& other) { @@ -48,7 +138,7 @@ class GroupView { GroupView& operator=(GroupView&& other) { if(this == &other) return *this; - flock_group_view_clear(&m_view); + clear(); FLOCK_GROUP_VIEW_MOVE(&other.m_view, &m_view); return *this; } @@ -69,68 +159,18 @@ class GroupView { flock_group_view_clear(&m_view); } - void addMember(uint64_t rank, const char* address, uint16_t provider_id) { - auto member = flock_group_view_add_member(&m_view, rank, provider_id, address); - if(!member) throw Exception{FLOCK_ERR_RANK_USED}; - } - - void removeMember(uint64_t rank) { - if(!flock_group_view_remove_member(&m_view, rank)) - throw Exception{FLOCK_ERR_NO_MEMBER}; + auto members() { + return MembersProxy{*this}; } - Member findMember(uint64_t rank) const { - auto member = flock_group_view_find_member(&m_view, rank); - if(!member) throw Exception{FLOCK_ERR_NO_MEMBER}; - return Member{member->rank, member->provider_id, member->address}; - } - - std::vector members() const { - std::vector result; - result.reserve(m_view.members.size); - for(size_t i = 0; i < m_view.members.size; ++i) { - result.push_back(Member{ - m_view.members.data[i].rank, - m_view.members.data[i].provider_id, - m_view.members.data[i].address - }); - } - return result; - } - - size_t maxNumMembers() const { - return m_view.members.data[m_view.members.size-1].rank; - } - - size_t numLiveMembers() const { - return m_view.members.size; - } - - void setMetadata(const char* key, const char* value) { - flock_group_view_add_metadata(&m_view, key, value); - } - - void removeMetadata(const char* key) { - if(!flock_group_view_remove_metadata(&m_view, key)) - throw Exception{FLOCK_ERR_NO_METADATA}; - } - - std::map metadata() const { - std::map result; - for(size_t i = 0; i < m_view.metadata.size; ++i) { - result.insert( - std::make_pair( - m_view.metadata.data[i].key, - m_view.metadata.data[i].value)); - } - return result; + auto metadata() { + return MetadataProxy{*this}; } - std::string toString(margo_instance_id mid, uint64_t credentials = 0) const { + operator std::string() const { std::string result; flock_return_t ret = flock_group_view_serialize( - mid, credentials, &m_view, - [](void* ctx, const char* content, size_t size) { + &m_view, [](void* ctx, const char* content, size_t size) { auto str = static_cast(ctx); str->assign(content, size); }, static_cast(&result)); diff --git a/include/flock/cxx/group.hpp b/include/flock/cxx/group.hpp index 31bebbd..8182599 100644 --- a/include/flock/cxx/group.hpp +++ b/include/flock/cxx/group.hpp @@ -111,48 +111,6 @@ class GroupHandle { return GroupHandle{gh}; } - operator std::string() const { - std::string result; - auto err = flock_group_serialize(m_gh, - [](void* uargs, const char* content, size_t size) -> void { - auto s = static_cast(uargs); - *s = std::string{content, size}; - }, &result); - FLOCK_CONVERT_AND_THROW(err); - return result; - } - - template - void serialize(const Function& function) const { - struct { - const Function& cb; - std::exception_ptr ex; - } context{function, nullptr}; - auto err = flock_group_serialize(m_gh, - [](void* uargs, const char* content, size_t size) -> void { - auto context_ptr = static_cast(uargs); - try { - (context_ptr->cb)(std::string_view{content, size}); - } catch(...) { - context_ptr->ex = std::current_exception(); - } - }, &context); - if(context.ex) std::rethrow_exception(context.ex); - FLOCK_CONVERT_AND_THROW(err); - } - - void serializeToFile(const char* filename) const { - auto err = flock_group_serialize_to_file(m_gh, filename); - FLOCK_CONVERT_AND_THROW(err); - } - - uint64_t digest() const { - uint64_t d; - auto err = flock_group_digest(m_gh, &d); - FLOCK_CONVERT_AND_THROW(err); - return d; - } - GroupView view() const { GroupView v; auto err = flock_group_get_view(m_gh, &v.m_view); @@ -160,20 +118,6 @@ class GroupHandle { return v; } - size_t maxNumMembers() const { - size_t count; - auto err = flock_group_size(m_gh, &count); - FLOCK_CONVERT_AND_THROW(err); - return count; - } - - size_t numLiveMembers() const { - size_t count; - auto err = flock_group_live_member_count(m_gh, &count); - FLOCK_CONVERT_AND_THROW(err); - return count; - } - void update() const { auto err = flock_group_update_view(m_gh, NULL); FLOCK_CONVERT_AND_THROW(err); diff --git a/include/flock/cxx/server.hpp b/include/flock/cxx/server.hpp index 43d175c..5dd9559 100644 --- a/include/flock/cxx/server.hpp +++ b/include/flock/cxx/server.hpp @@ -6,9 +6,11 @@ #ifndef __FLOCK_CLIENT_HPP #define __FLOCK_CLIENT_HPP +#include #include #include #include +#include namespace flock { @@ -23,7 +25,6 @@ class Observer { virtual void onMembershipUpdate( flock_update_t update, - uint64_t rank, const char* address, uint16_t provider_id) = 0; @@ -43,12 +44,10 @@ class Provider { uint16_t provider_id, const char* config, GroupView& initial_view, - ABT_pool pool = ABT_POOL_NULL, - uint64_t credentials = 0) { + ABT_pool pool = ABT_POOL_NULL) { m_mid = mid; flock_provider_args args; args.backend = nullptr; - args.credentials = credentials; args.initial_view = &initial_view.m_view; args.pool = pool; auto err = flock_provider_register(mid, provider_id, config, &args, &m_provider); @@ -60,6 +59,17 @@ class Provider { }, this); } + Provider(const thallium::engine& engine, + uint16_t provider_id, + const char* config, + GroupView& initial_view, + const thallium::pool& pool = thallium::pool()) + : Provider(engine.get_margo_instance(), + provider_id, + config, + initial_view, + pool.native_handle()) {} + ~Provider() { if(m_provider != FLOCK_PROVIDER_NULL) { margo_provider_pop_finalize_callback(m_mid, this); @@ -99,8 +109,8 @@ class Provider { void addObserver(Observer* observer) { auto membership_update_fn = - [](void* ctx, flock_update_t update, size_t rank, const char* address, uint16_t provider_id) { - static_cast(ctx)->onMembershipUpdate(update, rank, address, provider_id); + [](void* ctx, flock_update_t update, const char* address, uint16_t provider_id) { + static_cast(ctx)->onMembershipUpdate(update, address, provider_id); }; auto metadata_update_fn = [](void* ctx, const char* key, const char* value) { diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 1719652..90505ef 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,15 +1,15 @@ add_library (pyflock_client MODULE src/py-flock-client.cpp) -target_link_libraries (pyflock_client PRIVATE pybind11::module flock-client PRIVATE coverage_config) +target_link_libraries (pyflock_client PRIVATE pybind11::module flock-cxx-headers PRIVATE coverage_config) pybind11_extension (pyflock_client) pybind11_strip (pyflock_client) add_library (pyflock_server MODULE src/py-flock-server.cpp) -target_link_libraries (pyflock_server PRIVATE pybind11::module flock-server PRIVATE coverage_config) +target_link_libraries (pyflock_server PRIVATE pybind11::module flock-cxx-headers PRIVATE coverage_config) pybind11_extension (pyflock_server) pybind11_strip (pyflock_server) add_library (pyflock_common MODULE src/py-flock-common.cpp) -target_link_libraries (pyflock_common PRIVATE pybind11::module flock-client PRIVATE coverage_config) +target_link_libraries (pyflock_common PRIVATE pybind11::module flock-cxx-headers PRIVATE coverage_config) pybind11_extension (pyflock_common) pybind11_strip (pyflock_common) diff --git a/python/src/py-flock-client.cpp b/python/src/py-flock-client.cpp index 9f54a31..bffb2cd 100644 --- a/python/src/py-flock-client.cpp +++ b/python/src/py-flock-client.cpp @@ -21,133 +21,41 @@ typedef py11::capsule pymargo_instance_id; PYBIND11_MODULE(pyflock_client, m) { m.doc() = "Flock client python extension"; -#if 0 - py11::register_exception(m, "Exception", PyExc_RuntimeError); - py11::class_(m, "Client") + py11::module_::import("pyflock_common"); + + py11::class_(m, "Client") .def(py11::init()) .def_property_readonly("margo_instance_id", - [](const Client& client) { + [](const flock::Client& client) { return MID2CAPSULE(client.engine().get_margo_instance()); }) - .def("make_service_handle", - &Client::makeServiceHandle, - "Create a ServiceHandle instance", - "address"_a, - "provider_id"_a=0) - .def("make_service_group_handle", - [](const Client& client, - const std::string& groupfile, + .def("make_group_handle", + [](const flock::Client& client, + const std::string& address, uint16_t provider_id) { - return client.makeServiceGroupHandle(groupfile, provider_id); + auto addr = client.engine().lookup(address); + return client.makeGroupHandle(addr.get_addr(), provider_id); }, - "Create a ServiceHandle instance", - "group_file"_a, + "Create a GroupHandle instance", + "address"_a, "provider_id"_a=0) - .def("make_service_group_handle", - [](const Client& client, - const std::vector& addresses, - uint16_t provider_id) { - return client.makeServiceGroupHandle(addresses, provider_id); + .def("make_group_handle_from_file", + [](const flock::Client& client, + const std::string& filename) { + return flock::GroupHandle::FromFile(client, filename.c_str()); }, - "Create a ServiceHandle instance", - "addresses"_a, - "provider_id"_a=0) - .def("make_service_group_handle", - [](const Client& client, - uint64_t gid, - uint16_t provider_id) { - return client.makeServiceGroupHandle(gid, provider_id); + "Create a GroupHandle instance", + "filename"_a) + .def("make_group_handle_from_serialized", + [](const flock::Client& client, + std::string_view serialized) { + return flock::GroupHandle::FromSerialized(client, serialized); }, - "Create a ServiceHandle instance", - "group_id"_a, - "provider_id"_a=0); - py11::class_(m, "ServiceHandle") - .def_property_readonly("client", &ServiceHandle::client) - .def_property_readonly("address", [](const ServiceHandle& sh) { - return static_cast(sh.providerHandle()); - }) - .def_property_readonly("provider_id", [](const ServiceHandle& sh) { - return sh.providerHandle().provider_id(); - }) - .def("get_config", - [](const ServiceHandle& sh) { - std::string config; - sh.getConfig(&config); - return config; - }) - .def("query_config", - [](const ServiceHandle& sh, const std::string& script) { - std::string result; - sh.queryConfig(script, &result); - return result; - }, "script"_a) - .def("load_module", - [](const ServiceHandle& sh, - const std::string& name, - const std::string& path) { - sh.loadModule(name, path); - }, "name"_a, "path"_a) - .def("add_provider", - [](const ServiceHandle& sh, - const std::string& description) { - uint16_t provider_id_out; - sh.addProvider(description, &provider_id_out); - return provider_id_out; - }, "description"_a) - .def("change_provider_pool", - [](const ServiceHandle& sh, - const std::string& provider_name, - const std::string& pool_name) { - sh.changeProviderPool(provider_name, pool_name); - }) - .def("add_client", - [](const ServiceHandle& sh, - const std::string& description) { - sh.addClient(description); - }, "description"_a) - .def("add_abtio_instance", - [](const ServiceHandle& sh, - const std::string& description) { - sh.addABTioInstance(description); - }, "description"_a = std::string("{}")) - .def("add_ssg_group", [](const ServiceHandle& sh, const std::string& config) { - sh.addSSGgroup(config); - }, - "description"_a) - .def("add_pool", [](const ServiceHandle& sh, const std::string& config) { - sh.addPool(config); - }, - "description"_a) - .def("remove_pool", [](const ServiceHandle& sh, const std::string& pool_name) { - sh.removePool(pool_name); - }, - "name"_a) - .def("add_xstream", [](const ServiceHandle& sh, const std::string& config) { - sh.addXstream(config); - }, - "description"_a) - .def("remove_xstream", [](const ServiceHandle& sh, const std::string& es_name) { - sh.removeXstream(es_name); - }, - "name"_a) + "Create a GroupHandle instance", + "serialized"_a) ; - py11::class_(m, "ServiceGroupHandle") - .def("refresh", &ServiceGroupHandle::refresh) - .def_property_readonly("size", &ServiceGroupHandle::size) - .def_property_readonly("client", &ServiceGroupHandle::client) - .def("__getitem__", &ServiceGroupHandle::operator[]) - .def("get_config", - [](const ServiceGroupHandle& sh) { - std::string config; - sh.getConfig(&config); - return config; - }) - .def("query_config", - [](const ServiceGroupHandle& sh, const std::string& script) { - std::string result; - sh.queryConfig(script, &result); - return result; - }, "script"_a) + py11::class_(m, "GroupHandle") + .def("update", &flock::GroupHandle::update) + .def_property_readonly("view", &flock::GroupHandle::view) ; -#endif } diff --git a/python/src/py-flock-common.cpp b/python/src/py-flock-common.cpp index bf3d090..850cb8d 100644 --- a/python/src/py-flock-common.cpp +++ b/python/src/py-flock-common.cpp @@ -23,19 +23,48 @@ PYBIND11_MODULE(pyflock_common, m) { py11::register_exception(m, "Exception", PyExc_RuntimeError); py11::class_(m, "Member") - .def_readonly("rank", &flock::GroupView::Member::rank) .def_readonly("provider_id", &flock::GroupView::Member::provider_id) .def_readonly("address", &flock::GroupView::Member::address); + py11::class_(m, "Metadata") + .def_readonly("key", &flock::GroupView::Metadata::key) + .def_readonly("value", &flock::GroupView::Metadata::value); + + py11::class_(m, "MembersProxy") + .def("__len__", &flock::GroupView::MembersProxy::count) + .def("count", &flock::GroupView::MembersProxy::count) + .def("add", &flock::GroupView::MembersProxy::add) + .def("remove", [](flock::GroupView::MembersProxy& proxy, size_t i) { + proxy.remove(i); + }) + .def("remove", [](flock::GroupView::MembersProxy& proxy, const char* address, uint16_t provider_id) { + proxy.remove(address, provider_id); + }) + .def("exists", &flock::GroupView::MembersProxy::exists) + .def("__getitem__", &flock::GroupView::MembersProxy::operator[]) + .def("__delitem__", [](flock::GroupView::MembersProxy& proxy, size_t i) { + proxy.remove(i); + }) + ; + + py11::class_(m, "MetadataProxy") + .def("__len__", &flock::GroupView::MetadataProxy::count) + .def("count", &flock::GroupView::MetadataProxy::count) + .def("add", &flock::GroupView::MetadataProxy::add) + .def("remove", &flock::GroupView::MetadataProxy::remove) + .def("__getitem__", [](flock::GroupView::MetadataProxy& proxy, const char* key) { + return proxy[key]; + }) + .def("__delitem__", &flock::GroupView::MetadataProxy::remove) + ; + py11::class_(m, "GroupView") .def(py11::init<>()) .def_property_readonly("digest", &flock::GroupView::digest) .def("clear", &flock::GroupView::clear) .def("lock", &flock::GroupView::lock) .def("unlock", &flock::GroupView::unlock) - .def("add_member", &flock::GroupView::addMember) - .def("remove_member", &flock::GroupView::removeMember) - .def("find_member", &flock::GroupView::findMember) - .def_property_readonly("members", &flock::GroupView::members) + .def_property_readonly("members", &flock::GroupView::members, py11::keep_alive<0, 1>()) + .def_property_readonly("metadata", &flock::GroupView::metadata, py11::keep_alive<0, 1>()) ; } diff --git a/python/src/py-flock-server.cpp b/python/src/py-flock-server.cpp index d5ae1c5..d02b111 100644 --- a/python/src/py-flock-server.cpp +++ b/python/src/py-flock-server.cpp @@ -5,6 +5,7 @@ */ #include #include +#include namespace py11 = pybind11; using namespace pybind11::literals; @@ -18,231 +19,10 @@ typedef py11::capsule pyhg_addr_t; #define MID2CAPSULE(__mid) py11::capsule((void*)(__mid), "margo_instance_id") #define CAPSULE2MID(__caps) (margo_instance_id)(__caps) -#define ADDR2CAPSULE(__addr) py11::capsule((void*)(__addr), "hg_addr_t") -#define CAPSULE2ADDR(__caps) (hg_add_t)(__caps) - PYBIND11_MODULE(pybedrock_server, m) { m.doc() = "Flock server python extension"; -#if 0 - py11::register_exception(m, "Exception", PyExc_RuntimeError); - - py11::class_> named_dep(m, "NamedDependency"); - named_dep - .def_property_readonly("name", - [](std::shared_ptr nd) { return nd->getName(); }) - .def_property_readonly("type", - [](std::shared_ptr nd) { return nd->getType(); }) - .def_property_readonly("handle", - [](std::shared_ptr nd) { return nd->getHandle(); }) - ; - - py11::class_> (m, "ProviderDependency", named_dep) - .def_property_readonly("provider_id", - [](std::shared_ptr nd) { return nd->getProviderID(); }) - ; - - py11::class_> server(m, "Server"); - - py11::enum_(server, "ConfigType") - .value("JSON", ConfigType::JSON) - .value("JX9", ConfigType::JX9) - .export_values(); - - server - .def(py11::init([](const std::string& address, const std::string& config, - ConfigType configType, - const Jx9ParamMap& jx9Params) { - return std::make_shared(address, config, configType, jx9Params); - }), "address"_a, "config"_a="{}", "config_type"_a=ConfigType::JSON, - "jx9_params"_a=Jx9ParamMap{}) - .def("wait_for_finalize", - [](std::shared_ptr server) { - server->waitForFinalize(); - }) - .def("finalize", - [](std::shared_ptr server) { - server->finalize(); - }) - .def_property_readonly("margo_instance_id", - [](std::shared_ptr server) { - return MID2CAPSULE(server->getMargoManager().getMargoInstance()); - }) - .def_property_readonly("config", - [](std::shared_ptr server) { - return server->getCurrentConfig(); - }) - .def_property_readonly("margo_manager", - [](std::shared_ptr server) { - return server->getMargoManager(); - }) - .def_property_readonly("abtio_manager", - [](std::shared_ptr server) { - return server->getABTioManager(); - }) - .def_property_readonly("provider_manager", - [](std::shared_ptr server) { - return server->getProviderManager(); - }) - .def_property_readonly("client_manager", - [](std::shared_ptr server) { - return server->getClientManager(); - }) - .def_property_readonly("ssg_manager", - [](std::shared_ptr server) { - return server->getSSGManager(); - }) - ; - - py11::class_ (m, "MargoManager") - .def_property_readonly("margo_instance_id", [](const MargoManager& m) { - return MID2CAPSULE(m.getMargoInstance()); - }) - .def_property_readonly("default_handler_pool", &MargoManager::getDefaultHandlerPool) - .def_property_readonly("config", &MargoManager::getCurrentConfig) - .def("get_pool", [](const MargoManager& m, const std::string& pool_name) { - return m.getPool(pool_name); - }, "name"_a) - .def("get_pool", [](const MargoManager& m, uint32_t index) { - return m.getPool(index); - }, "index"_a) - .def("add_pool", &MargoManager::addPool, - "config"_a) - .def("remove_pool", [](MargoManager& m, const std::string& pool_name) { - return m.removePool(pool_name); - }, "name"_a) - .def("remove_pool", [](MargoManager& m, uint32_t index) { - return m.removePool(index); - }, "index"_a) - .def_property_readonly("num_pools", &MargoManager::getNumPools) - .def("get_xstream", [](const MargoManager& m, const std::string& es_name) { - return m.getXstream(es_name); - }, "name"_a) - .def("get_xstream", [](const MargoManager& m, uint32_t index) { - return m.getXstream(index); - }, "index"_a) - .def("add_xstream", &MargoManager::addXstream, - "config"_a) - .def("remove_xstream", [](MargoManager& m, const std::string& es_name) { - return m.removeXstream(es_name); - }, "name"_a) - .def("remove_xstream", [](MargoManager& m, uint32_t index) { - return m.removeXstream(index); - }, "index"_a) - .def_property_readonly("num_xstreams", &MargoManager::getNumXstreams) - ; - - py11::class_ (m, "SSGManager") - .def_property_readonly("config", [](const SSGManager& manager) { - return manager.getCurrentConfig().dump(); - }) - .def_property_readonly("num_groups", &SSGManager::getNumGroups) - .def("get_group", [](const SSGManager& ssg, const std::string& name) { - return ssg.getGroup(name); - }, "name_a") - .def("get_group", [](const SSGManager& ssg, size_t index) { - return ssg.getGroup(index); - }, "index_a") - .def("add_group", - [](SSGManager& ssg, - const std::string& name, - const py11::dict& config, - const std::shared_ptr& pool, - const std::string& bootstrap_method, - const std::string& group_file, - int64_t credential) { -#ifdef ENABLE_SSG - ssg_group_config_t cfg = SSG_GROUP_CONFIG_INITIALIZER; - cfg.ssg_credential = credential; -#define GET_SSG_FIELD(__field__) do { \ - if(config.contains(#__field__)) \ - cfg.swim_##__field__ = config[#__field__].cast(); \ - } while(0) - GET_SSG_FIELD(period_length_ms); - GET_SSG_FIELD(suspect_timeout_periods); - GET_SSG_FIELD(subgroup_member_count); - GET_SSG_FIELD(disabled); -#undef GET_SSG_FIELD - return ssg.addGroup(name, cfg, pool, bootstrap_method, group_file); -#else - throw Exception{"Bedrock was not compiled with SSG support"}; -#endif - }, "name"_a, "swim"_a=py11::dict{}, - "pool"_a=nullptr, "bootstrap"_a="init", - "group_file"_a="", "credential"_a=-1) - .def("resolve_address", [](const SSGManager& ssg, const std::string& address) { - return ADDR2CAPSULE(ssg.resolveAddress(address)); - }, "address"_a) - ; - - py11::class_ (m, "ABTioManager") - .def_property_readonly("config", [](const ABTioManager& manager) { - return manager.getCurrentConfig().dump(); - }) - .def_property_readonly("num_abtio_instances", &ABTioManager::numABTioInstances) - .def("get_abtio_instance", [](const ABTioManager& abtio, const std::string& name) { - return abtio.getABTioInstance(name); - }, "name"_a) - .def("get_abtio_instance", [](const ABTioManager& abtio, size_t index) { - return abtio.getABTioInstance(index); - }, "index"_a) - .def("add_abtio_instance", &ABTioManager::addABTioInstance) - ; - - py11::class_ (m, "ProviderManager") - .def_property_readonly("config", &ProviderManager::getCurrentConfig) - .def_property_readonly("num_providers", &ProviderManager::numProviders) - .def("get_provider", [](const ProviderManager& pm, size_t index) { - return pm.getProvider(index); - }, "index"_a) - .def("get_provider", [](const ProviderManager& pm, const std::string& name) { - return pm.getProvider(name); - }, "name"_a) - .def("lookup_provider", &ProviderManager::lookupProvider, - "spec"_a) - .def("deregister_provider", - &ProviderManager::deregisterProvider, - "spec"_a) - .def("add_provider", - &ProviderManager::addProviderFromJSON, - "description"_a) - .def("change_pool", - &ProviderManager::changeProviderPool, - "provider"_a, "pool"_a) - .def("migrate_provider", - &ProviderManager::migrateProvider, - "provider"_a, "dest_addr"_a, "dest_provider_id"_a, - "migration_config"_a, "remove_source"_a) - .def("snapshot_provider", - &ProviderManager::snapshotProvider, - "provider"_a, "dest_path"_a, "snapshot_config"_a, "remove_source"_a) - .def("restore_provider", - &ProviderManager::restoreProvider, - "provider"_a, "src_path"_a, "restore_config"_a) - ; - py11::class_ (m, "ClientManager") - .def_property_readonly("config", &ClientManager::getCurrentConfig) - .def("get_client", [](const ClientManager& cm, const std::string& name) { - return cm.getClient(name); - }, - "name"_a) - .def("get_client", [](const ClientManager& cm, size_t index) { - return cm.getClient(index); - }, - "index"_a) - .def_property_readonly("num_clients", &ClientManager::numClients) - .def("remove_client", [](ClientManager& cm, const std::string& name) { - return cm.removeClient(name); - }, - "name"_a) - .def("remove_client", [](ClientManager& cm, size_t index) { - return cm.removeClient(index); - }, - "index"_a) - .def("get_client_or_create", &ClientManager::getOrCreateAnonymous, - "type"_a) - .def("add_client", &ClientManager::addClientFromJSON, - "description"_a) + py11::class_(m, "Provider") + .def(py11::init()) ; -#endif } diff --git a/spack.yaml b/spack.yaml index a0d2189..0f9d184 100644 --- a/spack.yaml +++ b/spack.yaml @@ -3,6 +3,7 @@ spack: - cmake - pkgconfig - mochi-margo + - mochi-thallium - json-c - mochi-bedrock - py-pybind11 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8524c2c..9396032 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -76,6 +76,12 @@ set_target_properties (flock-bedrock-module SOVERSION ${FLOCK_VERSION_MAJOR}) endif () +add_library (flock-cxx-headers INTERFACE) +add_library (flock::headers ALIAS flock-cxx-headers) +target_link_libraries (flock-cxx-headers + INTERFACE PkgConfig::margo thallium flock-client flock-server) +target_include_directories (flock-cxx-headers INTERFACE $) + # installation stuff (packaging and install commands) write_basic_package_version_file ( "flock-config-version.cmake" @@ -101,7 +107,7 @@ configure_file ("flock-client.pc.in" "flock-client.pc" @ONLY) configure_file ("config.h.in" "config.h" @ONLY) # "make install" rules -install (TARGETS flock-server flock-client +install (TARGETS flock-server flock-client flock-cxx-headers EXPORT flock-targets ARCHIVE DESTINATION lib LIBRARY DESTINATION lib) diff --git a/tests/spack.yaml b/tests/spack.yaml index 74adbb7..de35b49 100644 --- a/tests/spack.yaml +++ b/tests/spack.yaml @@ -3,6 +3,7 @@ spack: - cmake - pkgconfig - mochi-margo ^mercury~boostsys~checksum ^libfabric fabrics=tcp,rxm + - mochi-thallium - json-c - mochi-bedrock - mpich