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

add array constructor with qVector

parent 6f4e36be
/* dtkDistributedArray.h ---
*
*
* Author: Thibaud Kloczko
* Created: Fri Mar 8 15:06:15 2013 (+0100)
* Version:
* Last-Updated: Fri Mar 8 16:08:12 2013 (+0100)
* By: Julien Wintz
* Update #: 25
*/
/* Change Log:
*
*
*/
#pragma once
#include "dtkDistributedMapper.h"
#include "dtkDistributedWorker.h"
#include "dtkDistributedWork.h"
// /////////////////////////////////////////////////////////////////
// dtkDistributedContainer
......@@ -41,7 +37,8 @@ public:
class iterator;
public:
inline dtkDistributedArray(const qlonglong& count, dtkDistributedWorker *worker);
inline dtkDistributedArray(const qlonglong& count, dtkDistributedWork *work);
inline dtkDistributedArray(const QVector<T> & vector, dtkDistributedWork *work);
inline ~dtkDistributedArray(void);
#pragma mark -
......
......@@ -15,13 +15,22 @@
#include "dtkDistributed.h"
#include "dtkDistributedCommunicator.h"
#include "dtkDistributedMapper.h"
#include "dtkDistributedWork.h"
#include "dtkDistributedWorker.h"
template<typename T> dtkDistributedArray<T>::dtkDistributedArray(const qlonglong& count, dtkDistributedWorker *worker) : m_handler(0), m_local_handler(*this), m_global_handler(*this), m_wid(worker->wid()), m_count(count), m_mapper(new dtkDistributedMapper), m_worker(worker), m_comm(worker->communicator())
template<typename T> dtkDistributedArray<T>::dtkDistributedArray(const qlonglong& count, dtkDistributedWork *work) : m_handler(0), m_local_handler(*this), m_global_handler(*this), m_wid(work->worker()->wid()), m_count(count), m_mapper(new dtkDistributedMapper), m_worker(work->worker()), m_comm(work->worker()->communicator())
{
this->initialize();
}
template<typename T> dtkDistributedArray<T>::dtkDistributedArray(const QVector<T> & qvector , dtkDistributedWork *work) : m_handler(0), m_local_handler(*this), m_global_handler(*this), m_wid(work->worker()->wid()), m_count(qvector.count()), m_mapper(new dtkDistributedMapper), m_worker(work->worker()), m_comm(work->worker()->communicator())
{
this->initialize();
for (qlonglong i = 0; i < m_local_handler.buffer_count ; ++i)
m_local_handler.buffer[i] = qvector.at(localToGlobal(i));
}
template<typename T> dtkDistributedArray<T>::~dtkDistributedArray(void)
{
m_comm->deallocate(m_wid, buffer_id);
......
......@@ -20,6 +20,31 @@
#include <dtkDistributed/dtkDistributedWorker.h>
#include <dtkDistributed/dtkDistributedWorkerManager.h>
class qvectorWork : public dtkDistributedWork
{
qvectorWork *clone(void) { return new qvectorWork(*this); };
void run(void)
{
QTime time;
qlonglong N = 101;
QVector<qlonglong> myvector(N);
for (qlonglong i = 0; i < N; ++i)
myvector[i] = i;
dtkDistributedArray<qlonglong> array(myvector, this);
DTK_DISTRIBUTED_BEGIN_GLOBAL;
QVERIFY(myvector.at(1) == array.at(1));
QVERIFY(myvector.at(N-1) == array.at(N-1));
DTK_DISTRIBUTED_END_GLOBAL;
}
};
class containerWork : public dtkDistributedWork
{
containerWork *clone(void) { return new containerWork(*this); };
......@@ -27,7 +52,7 @@ class containerWork : public dtkDistributedWork
void run(void)
{
QTime time;
dtkDistributedArray<qlonglong> array(11, dtkDistributedWork::worker());
dtkDistributedArray<qlonglong> array(11, this);
// ---
DTK_DISTRIBUTED_BEGIN_LOCAL;
......@@ -90,9 +115,7 @@ void randomWork::run(void)
{
qlonglong N = 20;
dtkDistributedArray<qlonglong> c(N, dtkDistributedWork::worker());
dtkDistributedCommunicator *comm = dtkDistributedWork::worker()->communicator();
dtkDistributedArray<qlonglong> c(N, this);
QTime time, maintime;
maintime.start();
......@@ -112,7 +135,7 @@ void randomWork::run(void)
dtkDistributedArray<qlonglong>::const_iterator itb = c.cbegin();
dtkDistributedArray<qlonglong>::const_iterator ite = c.cend();
while(it != ite)
qDebug() << it-itb << *it++;
qDebug() << it-itb << *it++;
DTK_DISTRIBUTED_END_GLOBAL;
}
......@@ -132,7 +155,7 @@ void sumWork::run(void)
{
qDebug()<< "run!!!!";
qlonglong N = 500000001;
qlonglong N = 50000001;
qlonglong sum = 0;
for (qlonglong i = 0; i < N; ++i)
......@@ -144,9 +167,9 @@ void sumWork::run(void)
qlonglong check_sum = 0;
dtkDistributedArray<qlonglong> c(N, dtkDistributedWork::worker());
dtkDistributedArray<qlonglong> c(N, this);
dtkDistributedArray<qlonglong> partial_sum(wct(), dtkDistributedWork::worker() );
dtkDistributedArray<qlonglong> partial_sum(wct(), this);
QVERIFY(N == c.count());
......@@ -229,9 +252,10 @@ void dtkDistributedContainerTestCase::testAll(void)
policy.addHost("localhost");
dtkDistributedWorkerManager manager;
sumWork *work = new sumWork();
randomWork *work2 = new randomWork();
sumWork *work = new sumWork();
randomWork *work2 = new randomWork();
containerWork *work3 = new containerWork();
qvectorWork *work4 = new qvectorWork();
manager.setPolicy(&policy);
qDebug() << "spawn";
......@@ -242,6 +266,8 @@ void dtkDistributedContainerTestCase::testAll(void)
manager.exec(work3);
manager.exec(work4);
manager.unspawn();
qDebug() << "parallel section is over";
......
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