generated from mochi-hpc/margo-microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,095 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
SCRIPT_DIR=$(dirname "$0") | ||
cmake .. -DENABLE_TESTS=ON -DENABLE_BEDROCK=ON -DENABLE_EXAMPLES=ON -DENABLE_MPI=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | ||
cmake .. -DENABLE_TESTS=ON -DENABLE_BEDROCK=ON -DENABLE_EXAMPLES=ON -DENABLE_MPI=ON -DENABLE_PYTHON=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | ||
make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* (C) 2024 The University of Chicago | ||
* | ||
* See COPYRIGHT in top-level directory. | ||
*/ | ||
#ifndef __FLOCK_CLIENT_HPP | ||
#define __FLOCK_CLIENT_HPP | ||
|
||
#include <flock/flock-client.h> | ||
#include <flock/flock-group.h> | ||
#include <flock/cxx/exception.hpp> | ||
#include <flock/cxx/group.hpp> | ||
|
||
namespace flock { | ||
|
||
class Client { | ||
|
||
public: | ||
|
||
Client() = default; | ||
|
||
Client(margo_instance_id mid, ABT_pool pool = ABT_POOL_NULL) { | ||
auto err = flock_client_init(mid, pool, &m_client); | ||
FLOCK_CONVERT_AND_THROW(err); | ||
} | ||
|
||
~Client() { | ||
if(m_client != FLOCK_CLIENT_NULL) { | ||
flock_client_finalize(m_client); | ||
} | ||
} | ||
|
||
Client(Client&& other) | ||
: m_client(other.m_client) { | ||
other.m_client = FLOCK_CLIENT_NULL; | ||
} | ||
|
||
Client(const Client&) = delete; | ||
|
||
Client& operator=(const Client&) = delete; | ||
|
||
Client& operator=(Client&& other) { | ||
if(this == &other) return *this; | ||
if(m_client != FLOCK_CLIENT_NULL) { | ||
flock_client_finalize(m_client); | ||
} | ||
m_client = other.m_client; | ||
other.m_client = FLOCK_CLIENT_NULL; | ||
return *this; | ||
} | ||
|
||
GroupHandle makeGroupHandle( | ||
hg_addr_t addr, | ||
uint16_t provider_id, | ||
uint32_t mode = 0) const { | ||
flock_group_handle_t gh; | ||
auto err = flock_group_handle_create( | ||
m_client, addr, provider_id, mode, &gh); | ||
FLOCK_CONVERT_AND_THROW(err); | ||
return GroupHandle(gh, false); | ||
} | ||
|
||
auto handle() const { | ||
return m_client; | ||
} | ||
|
||
operator flock_client_t() const { | ||
return m_client; | ||
} | ||
|
||
private: | ||
|
||
flock_client_t m_client = FLOCK_CLIENT_NULL; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* (C) 2024 The University of Chicago | ||
* | ||
* See COPYRIGHT in top-level directory. | ||
*/ | ||
#ifndef __FLOCK_EXCEPTION_HPP | ||
#define __FLOCK_EXCEPTION_HPP | ||
|
||
#include <flock/flock-common.h> | ||
#include <exception> | ||
|
||
namespace flock { | ||
|
||
class Exception : public std::exception { | ||
|
||
public: | ||
|
||
Exception(flock_return_t code) | ||
: m_code(code) {} | ||
|
||
const char* what() const noexcept override { | ||
#define X(__err__, __msg__) case __err__: return __msg__; | ||
switch(m_code) { | ||
FLOCK_RETURN_VALUES | ||
} | ||
#undef X | ||
return "Unknown error"; | ||
} | ||
|
||
auto code() const { | ||
return m_code; | ||
} | ||
|
||
private: | ||
|
||
flock_return_t m_code; | ||
}; | ||
|
||
#define FLOCK_CONVERT_AND_THROW(__err__) do { \ | ||
if((__err__) != FLOCK_SUCCESS) { \ | ||
throw ::flock::Exception((__err__)); \ | ||
} \ | ||
} while(0) | ||
|
||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* (C) 2024 The University of Chicago | ||
* | ||
* See COPYRIGHT in top-level directory. | ||
*/ | ||
#ifndef __FLOCK_GROUP_VIEW_HPP | ||
#define __FLOCK_GROUP_VIEW_HPP | ||
|
||
#include <flock/flock-group.h> | ||
#include <flock/cxx/exception.hpp> | ||
#include <memory> | ||
#include <map> | ||
#include <vector> | ||
#include <string> | ||
#include <functional> | ||
|
||
namespace flock { | ||
|
||
class GroupHandle; | ||
class Provider; | ||
|
||
class GroupView { | ||
|
||
friend class GroupHandle; | ||
friend class Provider; | ||
|
||
public: | ||
|
||
struct Member { | ||
uint64_t rank; | ||
uint16_t provider_id; | ||
std::string address; | ||
}; | ||
|
||
GroupView() = default; | ||
|
||
GroupView(flock_group_view_t view) { | ||
FLOCK_GROUP_VIEW_MOVE(&view, &m_view); | ||
} | ||
|
||
~GroupView() { | ||
flock_group_view_clear(&m_view); | ||
} | ||
|
||
GroupView(GroupView&& other) { | ||
FLOCK_GROUP_VIEW_MOVE(&other.m_view, &m_view); | ||
} | ||
|
||
GroupView& operator=(GroupView&& other) { | ||
if(this == &other) return *this; | ||
flock_group_view_clear(&m_view); | ||
FLOCK_GROUP_VIEW_MOVE(&other.m_view, &m_view); | ||
return *this; | ||
} | ||
|
||
auto digest() const { | ||
return m_view.digest; | ||
} | ||
|
||
void lock() { | ||
FLOCK_GROUP_VIEW_LOCK(&m_view); | ||
} | ||
|
||
void unlock() { | ||
FLOCK_GROUP_VIEW_UNLOCK(&m_view); | ||
} | ||
|
||
void clear() { | ||
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}; | ||
} | ||
|
||
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<Member> members() const { | ||
std::vector<Member> 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<std::string, std::string> metadata() const { | ||
std::map<std::string, std::string> result; | ||
for(size_t i = 0; i < m_view.metadata.size; ++i) { | ||
result.insert( | ||
std::make_pair<const std::string, std::string>( | ||
m_view.metadata.data[i].key, | ||
m_view.metadata.data[i].value)); | ||
} | ||
return result; | ||
} | ||
|
||
std::string toString(margo_instance_id mid, uint64_t credentials = 0) const { | ||
std::string result; | ||
flock_return_t ret = flock_group_view_serialize( | ||
mid, credentials, &m_view, | ||
[](void* ctx, const char* content, size_t size) { | ||
auto str = static_cast<decltype(&result)>(ctx); | ||
str->assign(content, size); | ||
}, static_cast<void*>(&result)); | ||
if(ret != FLOCK_SUCCESS) throw Exception{ret}; | ||
return result; | ||
} | ||
|
||
private: | ||
|
||
flock_group_view_t m_view = FLOCK_GROUP_VIEW_INITIALIZER; | ||
}; | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.