Commit e465cfa7 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas
Browse files

implement fake serialized communicator

parent 9ae5baaa
......@@ -15,18 +15,39 @@
#include "dtkDistributedCommunicator.h"
// #include <dtk/dtkGlobal.h>
// /////////////////////////////////////////////////////////////////
// dtkDistributedCommunicatorPrivate
// /////////////////////////////////////////////////////////////////
dtkDistributedCommunicator::dtkDistributedCommunicator(void) : QObject()
class dtkDistributedCommunicatorPrivate
{
public:
QMap<qlonglong, void *> buffer_map;
public:
qlonglong id;
public:
bool initialized;
};
// /////////////////////////////////////////////////////////////////
// dtkDistributedCommunicator
// /////////////////////////////////////////////////////////////////
dtkDistributedCommunicator::dtkDistributedCommunicator(void) : QObject(), d(new dtkDistributedCommunicatorPrivate)
{
d->id = 0;
d->initialized = false;
}
dtkDistributedCommunicator::~dtkDistributedCommunicator(void)
{
// delete d;
delete d;
// d = NULL;
d = NULL;
}
dtkDistributedCommunicator::dtkDistributedCommunicator(const dtkDistributedCommunicator& other)
......@@ -42,41 +63,45 @@ dtkDistributedCommunicator& dtkDistributedCommunicator::operator = (const dtkDis
void dtkDistributedCommunicator::initialize(void)
{
// DTK_DEFAULT_IMPLEMENTATION;
d->initialized = true;
}
bool dtkDistributedCommunicator::initialized(void)
{
// DTK_DEFAULT_IMPLEMENTATION;
return false;
return d->initialized;
}
void dtkDistributedCommunicator::uninitialize(void)
{
// DTK_DEFAULT_IMPLEMENTATION;
d->initialized = false;
}
int dtkDistributedCommunicator::pid(void)
{
// DTK_DEFAULT_IMPLEMENTATION;
return 0;
}
int dtkDistributedCommunicator::size(void)
{
// DTK_DEFAULT_IMPLEMENTATION;
return 1;
}
qlonglong dtkDistributedCommunicator::allocate(qlonglong count, qlonglong size, void *buffer)
{
return -1;
buffer = malloc(size*count);
d->buffer_map.insert(d->id, buffer);
d->id ++;
}
void dtkDistributedCommunicator::get(qint32 from, qlonglong position, void *array, qlonglong buffer_id)
{
if (d->buffer_map.contains(buffer_id)) {
void *buffer = d->buffer_map[buffer_id];
memcpy ( array, buffer+position*sizeof(qlonglong), sizeof(qlonglong) );
} else {
qDebug() << "unknown buffer" << buffer_id;
}
}
QByteArray dtkDistributedCommunicator::get(qint32 from, qlonglong position, qlonglong size, qlonglong buffer_id)
......@@ -86,6 +111,11 @@ QByteArray dtkDistributedCommunicator::get(qint32 from, qlonglong position, qlon
void dtkDistributedCommunicator::put(qint32 dest, qlonglong position, void *data, qlonglong buffer_id)
{
if (d->buffer_map.contains(buffer_id)) {
void *buffer = d->buffer_map[buffer_id];
memcpy ( buffer+position*sizeof(qlonglong), data, sizeof(qlonglong) );
} else {
qDebug() << "unknown buffer" << buffer_id;
}
}
......@@ -17,7 +17,7 @@
#include <QtCore>
// class dtkDistributedCommunicatorPrivate;
class dtkDistributedCommunicatorPrivate;
class dtkDistributedCommunicator : public QObject
{
......@@ -54,4 +54,7 @@ public:
virtual qint32 pid(void);
virtual qint32 size(void);
public:
dtkDistributedCommunicatorPrivate *d;
};
......@@ -3,9 +3,9 @@
* Author: Thibaud Kloczko
* Created: Tue Feb 5 14:12:49 2013 (+0100)
* Version:
* Last-Updated: lun. févr. 11 13:53:13 2013 (+0100)
* Last-Updated: lun. févr. 11 15:19:25 2013 (+0100)
* By: Nicolas Niclausse
* Update #: 182
* Update #: 183
*/
/* Change Log:
......@@ -44,8 +44,8 @@ template<typename T> dtkDistributedContainer<T>::~dtkDistributedContainer(void)
template<typename T> void dtkDistributedContainer<T>::allocate(void)
{
m_buffer_size = m_mapper->count(m_comm->pid());
m_buffer = new T[m_buffer_size];
// m_buffer_id = m_comm->allocate(m_mapper->count(m_comm->pid()), sizeof(T), m_buffer);
// m_buffer = new T[m_buffer_size];
m_buffer_id = m_comm->allocate(m_mapper->count(m_comm->pid()), sizeof(T), m_buffer);
};
template <typename T> qlonglong dtkDistributedContainer<T>::size(void) const
......
Supports Markdown
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