Commit d0382055 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Merge branch 'master' into thibaud

Conflicts:
	tst/dtkDistributed/dtkDistributedContainerTest.cpp
parents 98ec03b4 dbb3e7fe
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Fri Feb 8 16:49:52 2013 (+0100)
## Version:
## Last-Updated: Tue Feb 26 14:58:04 2013 (+0100)
## By: Julien Wintz
## Update #: 15
## Last-Updated: 2013 Thu Feb 28 14:27:21 (+0100)
## By: Thibaud Kloczko
## Update #: 17
######################################################################
##
### Change Log:
......@@ -19,6 +19,8 @@ project(dtkCore)
## #################################################################
set(${PROJECT_NAME}_HEADERS
dtkCorePluginFactory.h
dtkCorePluginFactory.tpp
dtkCorePluginManager.h
dtkCoreSettings.h)
......
#include "dtkCorePluginFactory.h"
/* dtkCorePluginFactory.h ---
*
* Author: Thibaud Kloczko
* Created: 2013 Thu Feb 28 14:13:28 (+0100)
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#pragma once
#include <QtCore>
//template <typename T> class dtkCorePluginFactoryPrivate;
template <typename T> class dtkCorePluginFactory : public QObject
{
public:
typedef T *(*creator) (void);
public:
dtkCorePluginFactory(void);
~dtkCorePluginFactory(void);
public:
T *create(const QString& key);
public:
QStringList keys(void);
public:
void record(QString key, creator func);
private:
QHash<QString, creator> creators;
//dtkCorePluginFactoryPrivate<T> *d;
};
#include "dtkCorePluginFactory.tpp"
/* dtkCorePluginFactory.tpp ---
*
* Author: Julien Wintz
* Created: Fri Feb 8 16:20:47 2013 (+0100)
* Version:
* Last-Updated: 2013 Thu Feb 28 14:47:18 (+0100)
* By: Thibaud Kloczko
* Update #: 54
*/
/* Change Log:
*
*/
#pragma once
// template <typename X> class dtkCorePluginFactoryPrivate
// {
// public:
// dtkCorePluginFactory<X>::creator toto;
// QHash<QString, dtkCorePluginFactory<X>::creator> creators;
// };
template <typename T> dtkCorePluginFactory<T>::dtkCorePluginFactory(void)
{
}
template <typename T> dtkCorePluginFactory<T>::~dtkCorePluginFactory(void)
{
}
template <typename T> T *dtkCorePluginFactory<T>::create(const QString& key)
{
Q_ASSERT(this->creators.contains(key));
return this->creators.value(key)();
}
template <typename T> QStringList dtkCorePluginFactory<T>::keys(void)
{
return this->creators.keys();
}
template <typename T> void dtkCorePluginFactory<T>::record(QString key, creator func)
{
this->creators.insert(key, func);
}
......@@ -77,11 +77,14 @@ void dtkDistributedCommunicator::uninitialize(void)
d->initialized = false;
}
void dtkDistributedCommunicator::spawn(QStringList hostnames, qlonglong np, dtkDistributedWorker worker)
void dtkDistributedCommunicator::spawn(QStringList hostnames, qlonglong np, dtkDistributedWorker& worker)
{
}
void dtkDistributedCommunicator::unspawn(void)
{
}
void dtkDistributedCommunicator::exec(void)
void dtkDistributedCommunicator::exec(dtkDistributedWork *work)
{
}
......
......@@ -17,6 +17,7 @@
#include <QtCore>
class dtkDistributedWork;
class dtkDistributedWorker;
class dtkDistributedCommunicatorPrivate;
......@@ -48,16 +49,15 @@ public:
public:
virtual void get(qint32 from, qlonglong position, void *array, qlonglong buffer_id);
virtual void put(qint32 dest, qlonglong position, void *data, qlonglong buffer_id);
public:
virtual void put(qint32 dest, qlonglong position, void *data, qlonglong buffer_id);
virtual void spawn(QStringList hostnames, qlonglong np, dtkDistributedWorker& worker);
virtual void exec(dtkDistributedWork *work);
public:
virtual void spawn(QStringList hostnames, qlonglong np, dtkDistributedWorker worker);
virtual void exec();
virtual void barrier();
virtual void unspawn(void);
virtual void barrier(void);
public:
virtual qint32 pid(void);
......
......@@ -3,15 +3,17 @@
* Author: Julien Wintz
* Created: Fri Feb 8 16:20:47 2013 (+0100)
* Version:
* Last-Updated: 2013 Tue Feb 12 14:24:43 (+0100)
* Last-Updated: 2013 Thu Feb 28 14:30:28 (+0100)
* By: Thibaud Kloczko
* Update #: 27
* Update #: 28
*/
/* Change Log:
*
*/
#if 0
#include "dtkDistributedCommunicator.h"
#include "dtkDistributedCommunicatorPluginFactory.h"
......@@ -49,3 +51,6 @@ void dtkDistributedCommunicatorPluginFactory::record(QString key, creator func)
{
d->creators.insert(key, func);
}
#endif
......@@ -3,9 +3,9 @@
* Author: Julien Wintz
* Created: Fri Feb 8 16:17:21 2013 (+0100)
* Version:
* Last-Updated: 2013 Tue Feb 12 14:23:41 (+0100)
* Last-Updated: 2013 Thu Feb 28 14:43:48 (+0100)
* By: Thibaud Kloczko
* Update #: 39
* Update #: 49
*/
/* Change Log:
......@@ -14,6 +14,14 @@
#pragma once
#include <dtkCore/dtkCorePluginFactory.h>
#include "dtkDistributedCommunicator.h"
class dtkDistributedCommunicatorPluginFactory : public dtkCorePluginFactory<dtkDistributedCommunicator> {};
#if 0
#include <QtCore>
class dtkDistributedCommunicator;
......@@ -42,3 +50,5 @@ public:
private:
dtkDistributedCommunicatorPluginFactoryPrivate *d;
};
#endif
......@@ -46,13 +46,18 @@ dtkDistributedWorker::dtkDistributedWorker(void) : QRunnable(), d(new dtkDistrib
{
d->comm = NULL;
d->work = NULL;
d->wid = -1;
d->wct = 0;
d->wid = -1;
d->wct = 0;
d->container_id = 0;
this->setAutoDelete(false);
}
dtkDistributedWorker::~dtkDistributedWorker(void)
{
if (d->work)
delete d->work;
delete d;
d = NULL;
......@@ -63,8 +68,8 @@ dtkDistributedWorker::dtkDistributedWorker(const dtkDistributedWorker& other): Q
d->wid = other.d->wid;
d->wct = other.d->wct;
d->comm = other.d->comm;
d->work = other.d->work->clone();
d->work->setWorker(this);
d->work = NULL;
this->setAutoDelete(false);
d->container_id = 0; // do not share containers id
}
......@@ -73,8 +78,6 @@ dtkDistributedWorker& dtkDistributedWorker::operator = (const dtkDistributedWork
d->wid = other.d->wid;
d->wct = other.d->wct;
d->comm = other.d->comm;
d->work = other.d->work->clone();
d->work->setWorker(this);
d->container_id = 0; // do not share containers id
return (*this);
}
......@@ -111,7 +114,10 @@ qlonglong dtkDistributedWorker::containerId(void)
void dtkDistributedWorker::setWork(dtkDistributedWork *work)
{
d->work = work;
if (!work)
return;
d->work = work->clone();
d->work->setWorker(this);
}
......
......@@ -38,9 +38,11 @@ public:
public:
void setWid(qlonglong wid);
void setWct(qlonglong wct);
void setCommunicator(dtkDistributedCommunicator *comm);
void setWork(dtkDistributedWork *work);
public:
void setCommunicator(dtkDistributedCommunicator *comm);
public:
qlonglong wid(void);
qlonglong wct(void);
......
......@@ -27,12 +27,16 @@ public:
dtkDistributedPolicy *policy;
dtkDistributedWorker worker;
public:
bool spawned;
};
dtkDistributedWorkerManager::dtkDistributedWorkerManager(void) : QObject(), d(new dtkDistributedWorkerManagerPrivate)
{
d->comm = NULL;
d->policy = NULL;
d->comm = NULL;
d->policy = NULL;
d->spawned = false;
}
dtkDistributedWorkerManager::~dtkDistributedWorkerManager(void)
......@@ -62,26 +66,26 @@ void dtkDistributedWorkerManager::setPolicy(dtkDistributedPolicy *policy)
d->comm = policy->communicator();
}
void dtkDistributedWorkerManager::setWork(dtkDistributedWork *work)
{
d->worker.setWork(work);
}
void dtkDistributedWorkerManager::spawn(void)
{
if (d->spawned)
return;
d->worker.setCommunicator(d->comm);
QStringList hosts = d->policy->hosts();
d->comm->spawn(hosts, hosts.count(), d->worker);
d->spawned = true;
}
void dtkDistributedWorkerManager::exec(void)
void dtkDistributedWorkerManager::exec(dtkDistributedWork *work)
{
d->comm->exec();
d->comm->exec( work );
}
void dtkDistributedWorkerManager::unspawn(void)
{
d->comm->uninitialize();
d->comm->unspawn();
d->spawned = false;
}
......@@ -37,11 +37,10 @@ public:
public:
void setCommunicator(dtkDistributedCommunicator *comm);
void setPolicy(dtkDistributedPolicy *policy);
void setWork(dtkDistributedWork *Work);
public:
void spawn(void);
void exec(void);
void exec(dtkDistributedWork *work);
void unspawn(void);
public:
......
......@@ -73,12 +73,70 @@ class containerWork : public dtkDistributedWork
}
};
class sumWork : public dtkDistributedWork
class randomWork : public dtkDistributedWork
{
sumWork *clone(void);
void run(void);
randomWork *clone(void);
void run(void);
};
int randInt(int max)
{
return double(qrand()) / RAND_MAX * max;
}
randomWork *randomWork::clone(void)
{
return new randomWork(*this);
}
void randomWork::run(void)
{
qlonglong N = 20;
dtkDistributedArray<qlonglong> c(N, dtkDistributedWork::worker());
c.m_handler->setGlobalMode();
dtkDistributedCommunicator *comm = dtkDistributedWork::worker()->communicator();
QTime time, maintime;
maintime.start();
time.start();
DTK_DISTRIBUTED_BEGIN_LOCAL
dtkDistributedIterator<qlonglong> it = c.iterator();
qsrand(dtkDistributedWork::worker()->wid());
while(it.hasNext()) {
c.set(it.index(), randInt(N));
it.toNext();
}
qlonglong np = dtkDistributedWork::worker()->wct();
DTK_DISTRIBUTED_END_LOCAL
DTK_DISTRIBUTED_BEGIN_GLOBAL
dtkDistributedIterator<qlonglong> it = c.iterator();
it.toFirst();
while(it.hasNext()) {
qDebug() << it.index() << it.current();
it.toNext();
}
DTK_DISTRIBUTED_END_GLOBAL
}
class sumWork : public dtkDistributedWork
{
public:
sumWork *clone(void);
void run(void);
};
sumWork *sumWork::clone(void)
......@@ -176,9 +234,6 @@ void sumWork::run(void)
QVERIFY(sum == check_sum);
DTK_DISTRIBUTED_END_GLOBAL
// delete &c;
// delete &partial_sum;
}
void dtkDistributedContainerTestCase::initTestCase(void)
......@@ -191,7 +246,7 @@ void dtkDistributedContainerTestCase::init(void)
}
void dtkDistributedContainerTestCase::testSum(void)
void dtkDistributedContainerTestCase::testAll(void)
{
dtkDistributedPolicy policy;
......@@ -222,52 +277,22 @@ void dtkDistributedContainerTestCase::testSum(void)
policy.addHost("localhost");
dtkDistributedWorkerManager manager;
sumWork *work = new sumWork();
sumWork *work = new sumWork();
randomWork *work2 = new randomWork();
containerWork *work3 = new containerWork();
manager.setPolicy(&policy);
manager.setWork(work);
qDebug() << "spawn";
manager.spawn();
manager.exec();
manager.unspawn();
}
void dtkDistributedContainerTestCase::testContainer(void)
{
dtkDistributedPolicy policy;
QByteArray numprocs = qgetenv("DTK_NUM_THREADS");
QByteArray policyEnv = qgetenv("DTK_DISTRIBUTED_POLICY");
int np = 2;
policy.setType(dtkDistributedPolicy::MP);
if (!numprocs.isEmpty()) {
np = numprocs.toInt();
qDebug() << "got num procs from env" << np;
}
if (!policyEnv.isEmpty()) {
qDebug() << "got policy from env" << policyEnv;
if (QString(policyEnv) == "MT"){
policy.setType(dtkDistributedPolicy::MT);
} else if (QString(policyEnv) == "MP") {
policy.setType(dtkDistributedPolicy::MP);
} else {
qDebug() << "unknown policy" << policyEnv;
}
}
manager.exec(work);
for (int i=0; i < np; ++i)
policy.addHost("localhost");
manager.exec(work2);
dtkDistributedWorkerManager manager;
containerWork *work = new containerWork();
manager.exec(work3);
manager.setPolicy(&policy);
manager.setWork(work);
qDebug() << "spawn";
manager.spawn();
manager.exec();
manager.unspawn();
qDebug() << "parallel section is over";
}
void dtkDistributedContainerTestCase::cleanupTestCase(void)
......
......@@ -25,8 +25,7 @@ private slots:
void init(void);
private slots:
void testSum(void);
void testContainer(void);
void testAll(void);
private slots:
void cleanupTestCase(void);
......
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