Commit 562e4e88 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Enhance of ArrayItem.

parent 3a5f8724
......@@ -19,6 +19,8 @@ set(${PROJECT_NAME}_HEADERS
dtkDistributed.h
dtkDistributedArray.h
dtkDistributedArray.tpp
dtkDistributedArrayHandler.h
dtkDistributedArrayHandler.tpp
dtkDistributedArrayItem.h
dtkDistributedCommunicator.h
dtkDistributedContainer.h
......
......@@ -55,7 +55,7 @@ public:
inline T last(void) const;
public:
inline dtkDistributedItem<T> operator [] (const qlonglong& index);
inline dtkDistributedArrayItem<T> operator [] (const qlonglong& index);
public:
inline dtkDistributedIterator<T> iterator(void);
......
......@@ -15,6 +15,7 @@
//#prama once
#include "dtkDistributed.h"
#include "dtkDistributedArrayItem.h"
class dtkDistributedCommunicator;
......@@ -83,9 +84,9 @@ template<typename T> T dtkDistributedArray<T>::last(void) const
return m_handler->last();
}
template<typename T> dtkDistributedItem<T> dtkDistributedArray<T>::operator [] (const qlonglong& index)
template<typename T> dtkDistributedArrayItem<T> dtkDistributedArray<T>::operator [] (const qlonglong& index)
{
return dtkDistributedItem<T>(new dtkDistributedArrayItem<T>(const_cast<dtkDistributedArray<T>*>(this), index));
return dtkDistributedArrayItem<T>(this, index);
}
template<typename T> dtkDistributedIterator<T> dtkDistributedArray<T>::iterator(void)
......
......@@ -141,7 +141,7 @@ template<typename T> class dtkDistributedIteratorArrayPrivate : public dtkDistri
public:
dtkDistributedArrayHandler<T>& h;
qlonglong id;
public:
inline dtkDistributedIteratorArrayPrivate(dtkDistributedArrayHandler<T>& handler) : h(handler), id(0) {;}
inline ~dtkDistributedIteratorArrayPrivate(void) {;}
......
......@@ -14,32 +14,41 @@
#pragma once
#include "dtkDistributedItem.h"
// /////////////////////////////////////////////////////////////////
//
// dtkDistributedArrayItem interface and implementation
// /////////////////////////////////////////////////////////////////
template <typename T> class dtkDistributedArrayItem : public dtkDistributedContainerItem<T>
template <typename T> class dtkDistributedArrayItem
{
public:
inline dtkDistributedArrayItem(dtkDistributedArray<T> *array, const qlonglong& index) : m_index(index), m_array(array) {;}
inline dtkDistributedArrayItem(const dtkDistributedArrayItem<T>& other) : m_index(other.m_index), m_array(other.m_array) {;}
public:
inline ~dtkDistributedArrayItem(void) { m_index = -1; m_array = 0; }
public:
inline void assign(const T& value) { m_array->set(m_index, value); }
inline dtkDistributedArrayItem& operator = (const dtkDistributedArrayItem<T>& other) { m_index = other.m_index; m_array = other.m_array; }
public:
inline dtkDistributedArrayItem& operator = (const T& value) { m_array->set(m_index, value); return *this; }
inline dtkDistributedArrayItem& operator += (const T& value) { m_array->set(m_index, m_array->at(m_index) + value); return *this; }
inline dtkDistributedArrayItem& operator -= (const T& value) { m_array->set(m_index, m_array->at(m_index) - value); return *this; }
inline void increment(const T& value) { m_array->set(m_index, m_array->at(m_index) + value); }
inline void decrement(const T& value) { m_array->set(m_index, m_array->at(m_index) - value); }
inline dtkDistributedArrayItem& operator *= (const T& value) { m_array->set(m_index, m_array->at(m_index) * value); return *this; }
inline dtkDistributedArrayItem& operator /= (const T& value) { m_array->set(m_index, m_array->at(m_index) / value); return *this; }
inline void multiply(const T& value) { m_array->set(m_index, m_array->at(m_index) * value); }
inline void divide(const T& value) { m_array->set(m_index, m_array->at(m_index) / value); }
private:
dtkDistributedArrayItem& operator ++ (void) { return *this; }
dtkDistributedArrayItem& operator -- (void) { return *this; }
dtkDistributedArrayItem& operator ++ (int) { return *this; }
dtkDistributedArrayItem& operator -- (int) { return *this; }
public:
inline T value(void) const { return m_array->at(m_index); }
public:
private:
qlonglong m_index;
dtkDistributedArray<T> *m_array;
......
/* dtkDistributedItem.h ---
*
* Author: Thibaud Kloczko
* Created: 2013 Wed Feb 27 23:11:32 (+0100)
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#pragma once
// /////////////////////////////////////////////////////////////////
// dtkDistributedContainerItem interface
// /////////////////////////////////////////////////////////////////
template <typename T> class dtkDistributedContainerItem
{
public:
virtual ~dtkDistributedContainerItem(void) {;}
public:
virtual void assign(const T& value) = 0;
virtual void increment(const T& value) = 0;
virtual void decrement(const T& value) = 0;
virtual void multiply(const T& value) = 0;
virtual void divide(const T& value) = 0;
public:
virtual T value(void) const = 0;
};
// /////////////////////////////////////////////////////////////////
// dtkDistributedItem interface
// /////////////////////////////////////////////////////////////////
template <typename T> class dtkDistributedItem
{
public:
inline dtkDistributedItem(dtkDistributedContainerItem<T> *d_ptr);
public:
inline ~dtkDistributedItem(void);
public:
inline dtkDistributedItem& operator = (const T& value);
inline dtkDistributedItem& operator += (const T& value);
inline dtkDistributedItem& operator -= (const T& value);
inline dtkDistributedItem& operator *= (const T& value);
inline dtkDistributedItem& operator /= (const T& value);
public:
inline T value(void) const;
private:
dtkDistributedContainerItem<T> *d;
private:
friend class dtkDistributedArray<T>;
};
// /////////////////////////////////////////////////////////////////
template <typename T> dtkDistributedItem<T>::dtkDistributedItem(dtkDistributedContainerItem<T> *d_ptr) : d(d_ptr)
{
}
template <typename T> dtkDistributedItem<T>::~dtkDistributedItem(void)
{
if (d) {
delete d;
}
d = NULL;
}
template <typename T> dtkDistributedItem<T>& dtkDistributedItem<T>::operator = (const T& value)
{
d->assign(value);
return (*this);
}
template <typename T> dtkDistributedItem<T>& dtkDistributedItem<T>::operator += (const T& value)
{
d->increment(value);
return (*this);
}
template <typename T> dtkDistributedItem<T>& dtkDistributedItem<T>::operator -= (const T& value)
{
d->decrement(value);
return (*this);
}
template <typename T> dtkDistributedItem<T>& dtkDistributedItem<T>::operator *= (const T& value)
{
d->multiply(value);
return (*this);
}
template <typename T> dtkDistributedItem<T>& dtkDistributedItem<T>::operator /= (const T& value)
{
d->divide(value);
return (*this);
}
template <typename T> T dtkDistributedItem<T>::value(void) const
{
return d->value();
}
......@@ -144,7 +144,7 @@ void sumWork::run(void)
{
qDebug()<< "run!!!!";
qlonglong N = 1000001;
qlonglong N = 100000001;
qlonglong sum = 0;
for (qlonglong i = 0; i < N; ++i)
......@@ -176,7 +176,7 @@ void sumWork::run(void)
// Fill the container in parallel
while(it.hasNext()) {
c.set(it.index(), c.localToGlobal(it.index()));
c[it.index()] = c.localToGlobal(it.index());
it.toNext();
}
......@@ -285,9 +285,9 @@ void dtkDistributedContainerTestCase::testAll(void)
manager.spawn();
manager.exec(work);
manager.exec(work2);
//manager.exec(work2);
manager.exec(work3);
//manager.exec(work3);
manager.unspawn();
......
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