Commit c1f0447c authored by Matthieu Dorier's avatar Matthieu Dorier

started commenting classes

parent 94fdc267
......@@ -7,6 +7,6 @@
#include <thallium/endpoint.hpp>
#include <thallium/remote_procedure.hpp>
#include <thallium/callable_remote_procedure.hpp>
#include <thallium/resolved_bulk.hpp>
#include <thallium/remote_bulk.hpp>
#endif
......@@ -15,12 +15,17 @@
namespace thallium {
class engine;
class resolved_bulk;
class remote_bulk;
/**
* @brief bulk objects represent abstractions of memory
* segments exposed by a process for RDMA operations. A bulk
* object can be serialized to be sent over RPC to another process.
*/
class bulk {
friend class engine;
friend class resolved_bulk;
friend class remote_bulk;
private:
......@@ -28,12 +33,26 @@ private:
hg_bulk_t m_bulk;
bool m_is_local;
/**
* @brief Constructor. Made private as bulk objects
* are instanciated by engine::expose (for example),
* not directory by users.
*
* @param e Reference to the engine instance creating the object.
* @param b Mercury bulk handle.
* @param local Whether the bulk handle referes to memory that is
* local to this process.
*/
bulk(engine& e, hg_bulk_t b, bool local)
: m_engine(&e), m_bulk(b), m_is_local(local) {}
/**
* @brief The bulk_segment class represents a portion
* (represented by offset and size) of a bulk object.
*/
class bulk_segment {
friend class resolved_bulk;
friend class remote_bulk;
std::size_t m_offset;
std::size_t m_size;
......@@ -41,39 +60,101 @@ private:
public:
/**
* @brief Constructor. By default the size of the segment will be
* that of the underlying bulk object, and the offset is 0.
*
* @param b Reference to the bulk object from which the segment is taken.
*/
bulk_segment(const bulk& b)
: m_offset(0), m_size(b.size()), m_bulk(b) {}
/**
* @brief Constructor.
*
* @param b Reference to the bulk object from which the segment is taken.
* @param offset Offset at which the segment starts.
* @param size Size of the segment.
*/
bulk_segment(const bulk& b, std::size_t offset, std::size_t size)
: m_offset(offset), m_size(size), m_bulk(b) {}
/**
* @brief Copy constructor is deleted.
*/
bulk_segment(const bulk_segment&) = delete;
/**
* @brief Move constructor is default.
*/
bulk_segment(bulk_segment&&) = default;
/**
* @brief Destructor is default.
*/
~bulk_segment() = default;
resolved_bulk on(const endpoint& ep) const;
std::size_t operator>>(const resolved_bulk& b) const;
std::size_t operator<<(const resolved_bulk& b) const;
/**
* @brief Associates the bulk segment with an endpoint to represent
* a remote_bulk object.
*
* @param ep Endpoint where the bulk object has bee created.
*
* @return a remote_bulk object.
*/
remote_bulk on(const endpoint& ep) const;
/**
* @brief Pushes data from the left operand (bulk_segment)
* to the right operand (remote_bulk). If the size of the
* segments don't match, the smallest size is used.
*
* @param b remote_bulk object towards which to push data.
*
* @return the size of data transfered.
*/
std::size_t operator>>(const remote_bulk& b) const;
/**
* @brief Pulls data from the right operand (remote_bulk)
* to the right operand (bulk_segment). If the size of the
* segments don't match, the smallest size is used.
*
* @param b remote_bulk object from which to pull data.
*
* @return the size of data transfered.
*/
std::size_t operator<<(const remote_bulk& b) const;
};
public:
/**
* @brief Default constructor, defined so that one can have a bulk
* object as class member and associate it later with an actual bulk.
*/
bulk()
: m_engine(nullptr), m_bulk(HG_BULK_NULL), m_is_local(false) {}
/**
* @brief Copy constructor.
*/
bulk(const bulk& other)
: m_engine(other.m_engine), m_bulk(other.m_bulk), m_is_local(other.m_is_local) {
margo_bulk_ref_incr(m_bulk);
}
/**
* @brief Move constructor.
*/
bulk(bulk&& other)
: m_engine(other.m_engine), m_bulk(other.m_bulk), m_is_local(std::move(other.m_is_local)) {
other.m_bulk = HG_BULK_NULL;
}
/**
* @brief Copy-assignment operator.
*/
bulk& operator=(const bulk& other) {
if(this == &other) return *this;
if(m_bulk != HG_BULK_NULL) {
......@@ -88,6 +169,9 @@ public:
return *this;
}
/**
* @brief Move-assignment operator.
*/
bulk& operator=(bulk&& other) {
if(this == &other) return *this;
if(m_bulk != HG_BULK_NULL) {
......@@ -100,12 +184,20 @@ public:
return *this;
}
/**
* @brief Destructor.
*/
~bulk() {
if(m_bulk != HG_BULK_NULL) {
margo_bulk_free(m_bulk);
}
}
/**
* @brief Returns the size of the data exposed by the bulk object.
*
* @return size of data exposed by the bulk object.
*/
std::size_t size() const {
if(m_bulk != HG_BULK_NULL)
return margo_bulk_get_size(m_bulk);
......@@ -113,29 +205,89 @@ public:
return 0;
}
/**
* @brief Indicates whether the bulk handle is null.
*
* @return true if the bulk handle is null, false otherwise.
*/
bool is_null() const {
return m_bulk == HG_BULK_NULL;
}
resolved_bulk on(const endpoint& ep) const;
/**
* @brief Builds a remote_bulk object by associating it with an endpoint.
*
* @param ep endpoint with which the bulk object should be associated.
*
* @return a remote_bulk instance.
*/
remote_bulk on(const endpoint& ep) const;
/**
* @brief Creates a bulk_segment object by selecting a given portion
* of the bulk object given an offset and a size.
*
* @param offset Offset at which the segment starts.
* @param size Size of the segment.
*
* @return a bulk_segment object.
*/
bulk_segment select(std::size_t offset, std::size_t size) const;
bulk_segment operator()(std::size_t offset, std::size_t size) const;
std::size_t operator>>(const resolved_bulk& b) const;
std::size_t operator<<(const resolved_bulk& b) const;
/**
* @see bulk::select
*/
bulk_segment operator()(std::size_t offset, std::size_t size) const;
/**
* @brief Pushes data from the left operand (entire bulk object)
* to the right operand (remote_bulk). If the size of the
* segments don't match, the smallest size is used.
*
* @param b remote_bulk object towards which to push data.
*
* @return the size of data transfered.
*/
std::size_t operator>>(const remote_bulk& b) const;
/**
* @brief Pulls data from the right operand (remote_bulk)
* to the left operand (bulk). If the size of the
* segments don't match, the smallest size is used.
*
* @param b remote_bulk object from which to pull data.
*
* @return the size of data transfered.
*/
std::size_t operator<<(const remote_bulk& b) const;
/**
* @brief Function that serializes a bulk object into an archive.
*
* @tparam A Archive type.
* @param ar Input archive.
*/
template<typename A>
void save(A& ar) {
hg_size_t s = margo_bulk_get_serialize_size(m_bulk, HG_TRUE);
std::vector<char> buf(s);
margo_bulk_serialize(&buf[0], s, HG_TRUE, m_bulk);
// XXX check return values
ar & buf;
if(m_bulk == HG_BULK_NULL) {
std::vector<char> buf;
ar & buf;
} else {
hg_size_t s = margo_bulk_get_serialize_size(m_bulk, HG_TRUE);
std::vector<char> buf(s);
margo_bulk_serialize(&buf[0], s, HG_TRUE, m_bulk);
// XXX check return values
ar & buf;
}
}
/**
* @brief Deserializes a bulk object from an output archive.
*
* @tparam A Archive type.
* @param ar Output archive.
*/
template<typename A>
void load(A& ar);
......@@ -149,12 +301,17 @@ namespace thallium {
template<typename A>
void bulk::load(A& ar) {
if(!is_null()) {
*this = bulk(); // reset
}
std::vector<char> buf;
ar & buf;
m_engine = &(ar.get_engine());
margo_bulk_deserialize(m_engine->m_mid, &m_bulk, &buf[0], buf.size());
// XXX check return value
m_is_local = false;
if(buf.size() > 0) {
m_engine = &(ar.get_engine());
margo_bulk_deserialize(m_engine->m_mid, &m_bulk, &buf[0], buf.size());
// XXX check return value
m_is_local = false;
}
}
}
......
......@@ -14,14 +14,14 @@ namespace thallium {
class engine;
class request;
class resolved_bulk;
class remote_bulk;
class endpoint {
friend class engine;
friend class request;
friend class callable_remote_procedure;
friend class resolved_bulk;
friend class remote_bulk;
private:
......
......@@ -21,7 +21,7 @@ namespace thallium {
class bulk;
class endpoint;
class resolved_bulk;
class remote_bulk;
class remote_procedure;
class engine {
......@@ -29,7 +29,7 @@ class engine {
friend class request;
friend class bulk;
friend class endpoint;
friend class resolved_bulk;
friend class remote_bulk;
friend class remote_procedure;
friend class callable_remote_procedure;
......
......@@ -3,8 +3,8 @@
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __THALLIUM_RESOLVED_BULK_HPP
#define __THALLIUM_RESOLVED_BULK_HPP
#ifndef __THALLIUM_REMOTE_BULK_HPP
#define __THALLIUM_REMOTE_BULK_HPP
#include <cstdint>
#include <string>
......@@ -14,7 +14,7 @@
namespace thallium {
class resolved_bulk {
class remote_bulk {
friend class bulk;
......@@ -23,7 +23,7 @@ private:
const bulk::bulk_segment& m_segment;
endpoint m_endpoint;
resolved_bulk(const bulk::bulk_segment& b, const endpoint& ep)
remote_bulk(const bulk::bulk_segment& b, const endpoint& ep)
: m_segment(b), m_endpoint(ep) {}
public:
......
......@@ -9,7 +9,7 @@ set(thallium-src bulk.cpp
engine.cpp
remote_procedure.cpp
request.cpp
resolved_bulk.cpp
remote_bulk.cpp
callable_remote_procedure.cpp
proc_buffer.cpp)
......
......@@ -4,7 +4,7 @@
* See COPYRIGHT in top-level directory.
*/
#include <thallium/bulk.hpp>
#include <thallium/resolved_bulk.hpp>
#include <thallium/remote_bulk.hpp>
namespace thallium {
......@@ -16,27 +16,27 @@ bulk::bulk_segment bulk::operator()(std::size_t offset, std::size_t size) const
return select(offset, size);
}
resolved_bulk bulk::bulk_segment::on(const endpoint& ep) const {
return resolved_bulk(*this, ep);
remote_bulk bulk::bulk_segment::on(const endpoint& ep) const {
return remote_bulk(*this, ep);
}
resolved_bulk bulk::on(const endpoint& ep) const {
return resolved_bulk(*this, ep);
remote_bulk bulk::on(const endpoint& ep) const {
return remote_bulk(*this, ep);
}
std::size_t bulk::bulk_segment::operator>>(const resolved_bulk& b) const {
std::size_t bulk::bulk_segment::operator>>(const remote_bulk& b) const {
return b << *this;
}
std::size_t bulk::bulk_segment::operator<<(const resolved_bulk& b) const {
std::size_t bulk::bulk_segment::operator<<(const remote_bulk& b) const {
return b >> *this;
}
std::size_t bulk::operator>>(const resolved_bulk& b) const {
std::size_t bulk::operator>>(const remote_bulk& b) const {
return b << (this->select(0,size()));
}
std::size_t bulk::operator<<(const resolved_bulk& b) const {
std::size_t bulk::operator<<(const remote_bulk& b) const {
return b >> (this->select(0,size()));
}
}
......@@ -4,11 +4,11 @@
* See COPYRIGHT in top-level directory.
*/
#include <thallium/bulk.hpp>
#include <thallium/resolved_bulk.hpp>
#include <thallium/remote_bulk.hpp>
namespace thallium {
std::size_t resolved_bulk::operator>>(const bulk::bulk_segment& dest) const {
std::size_t remote_bulk::operator>>(const bulk::bulk_segment& dest) const {
margo_instance_id mid = m_segment.m_bulk.m_engine->m_mid;
hg_bulk_op_t op = HG_BULK_PULL;
......@@ -28,7 +28,7 @@ std::size_t resolved_bulk::operator>>(const bulk::bulk_segment& dest) const {
return size;
}
std::size_t resolved_bulk::operator<<(const bulk::bulk_segment& src) const {
std::size_t remote_bulk::operator<<(const bulk::bulk_segment& src) const {
margo_instance_id mid = m_segment.m_bulk.m_engine->m_mid;
hg_bulk_op_t op = HG_BULK_PUSH;
......
......@@ -21,7 +21,7 @@ int server() {
seg[0].first = (void*)(&v[0]);
seg[0].second = v.size();
tl::bulk local = margo.expose(seg, tl::bulk_mode::write_only);
b(1,5).on(ep) >> local;
b.on(ep) >> local;
std::cout << "Server received bulk: ";
for(auto c : v) std::cout << c;
std::cout << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment