1#ifndef FPMAS_DISTRIBUTED_ID_H
2#define FPMAS_DISTRIBUTED_ID_H
4#include "hedley/hedley.h"
32 #define FPMAS_ID_TYPE std::uint_fast32_t
36#include <nlohmann/json.hpp>
42 std::is_integral<FPMAS_ID_TYPE>::value,
43 "FPMAS_ID_TYPE must be an unsigned integer."
46 std::is_unsigned<FPMAS_ID_TYPE>::value,
47 "FPMAS_ID_TYPE must be unsigned."
51namespace fpmas {
namespace api {
namespace graph {
55namespace fpmas {
namespace api {
namespace communication {
74namespace fpmas {
namespace api {
namespace graph {
80namespace fpmas {
namespace api {
namespace graph {
127 : _rank(mpi_id.
rank), _id(mpi_id.
id) {}
190 if(this->_rank==other._rank)
191 return this->_id < other._id;
192 if(this->_rank < other._rank)
204 return *
this < other;
214 return (other._rank == this->_rank) && (other._id == this->_id);
224 return (other._rank != this->_rank) || (other._id != this->_id);
232 HEDLEY_DEPRECATED(1.1)
235 operator std::
string()
const {
236 return "[" + std::to_string(_rank) +
":" + std::to_string(_id) +
"]";
245 return std::hash<FPMAS_ID_TYPE>()(_id);
269 std::string
to_string(
const api::graph::DistributedId&
id);
272namespace fpmas {
namespace api {
namespace communication {
277 inline static void createMpiTypes() {
278 MPI_Datatype types[2] = {MPI_INT, MPI_UNSIGNED_LONG_LONG};
279 int block[2] = {1, 1};
284 MPI_Type_create_struct(2, block, disp, types, &DistributedId::mpiDistributedIdType);
285 MPI_Type_commit(&DistributedId::mpiDistributedIdType);
291 inline static void freeMpiTypes() {
292 MPI_Type_free(&DistributedId::mpiDistributedIdType);
329 template<
typename JsonType>
342 template<
typename JsonType>
344 id._rank = j[0].template get<int>();
345 id._id = j[1].template get<FPMAS_ID_TYPE>();
355 template<
typename Value,
typename Hash,
typename Equal,
typename Alloc>
356 struct adl_serializer<std::unordered_map<DistributedId, Value, Hash, Equal, Alloc>> {
357 typedef std::unordered_map<DistributedId, Value, Hash, Equal, Alloc> Map;
358 static void to_json(json& j,
const Map& map) {
360 j[json(item.first).dump()] = json(item.second);
362 static void from_json(
const json& j, Map& map) {
363 for(
auto item : j.items()) {
366 item.value().get<Value>()});
Definition: distributed_id.h:89
bool operator<(const DistributedId &other) const
Definition: distributed_id.h:189
DistributedId(int rank, FPMAS_ID_TYPE id)
Definition: distributed_id.h:150
DistributedId operator++(int)
Definition: distributed_id.h:174
DistributedId(int rank)
Definition: distributed_id.h:141
FPMAS_ID_TYPE id() const
Definition: distributed_id.h:166
DistributedId()
Definition: distributed_id.h:132
std::size_t hash() const
Definition: distributed_id.h:244
int rank() const
Definition: distributed_id.h:157
bool operator<=(const DistributedId &other) const
Definition: distributed_id.h:201
static MPI_Datatype mpiDistributedIdType
Definition: distributed_id.h:119
bool operator!=(const DistributedId &other) const
Definition: distributed_id.h:223
DistributedId(const MpiDistributedId &mpi_id)
Definition: distributed_id.h:126
bool operator==(const DistributedId &other) const
Definition: distributed_id.h:213
static int max_rank
Definition: distributed_id.h:100
static FPMAS_ID_TYPE max_id
Definition: distributed_id.h:111
#define FPMAS_ID_TYPE
Definition: distributed_id.h:32
std::ostream & operator<<(std::ostream &os, const DistributedId &id)
Definition: distributed_id.cpp:13
std::string to_string(const api::graph::DistributedId &id)
Definition: distributed_id.cpp:4
Definition: distributed_id.h:62
FPMAS_ID_TYPE id
Definition: distributed_id.h:70
int rank
Definition: distributed_id.h:66
Definition: distributed_id.h:322
static void from_json(const JsonType &j, DistributedId &id)
Definition: distributed_id.h:343
static void to_json(JsonType &j, const DistributedId &value)
Definition: distributed_id.h:330
std::size_t operator()(DistributedId const &id) const noexcept
Definition: distributed_id.h:306