Commit 7d521e86 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Merge branch 'master' into thibaud

Conflicts:
	test/dtkDistributed/dtkDistributedContainerTest.cpp
parents 824f0bac 96d9a2ee
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Mon Feb 4 10:17:21 2013 (+0100)
## Version:
## Last-Updated: Mon Feb 11 23:25:49 2013 (+0100)
## Last-Updated: Tue Feb 26 14:45:18 2013 (+0100)
## By: Julien Wintz
## Update #: 113
## Update #: 118
######################################################################
##
### Change Log:
......@@ -83,7 +83,7 @@ include_directories(${PROJECT_SOURCE_DIR}/src/dtkTest)
## ###################################################################
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(tst)
## ###################################################################
## Exporting
......
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Mon Feb 4 10:29:13 2013 (+0100)
## Version:
## Last-Updated: Mon Feb 11 20:31:57 2013 (+0100)
## Last-Updated: Tue Feb 26 14:58:29 2013 (+0100)
## By: Julien Wintz
## Update #: 7
## Update #: 10
######################################################################
##
### Change Log:
......@@ -17,3 +17,5 @@ add_subdirectory(dtkLog)
add_subdirectory(dtkCore)
add_subdirectory(dtkDistributed)
add_subdirectory(dtkTest)
export(TARGETS dtkLog dtkCore dtkDistributed APPEND FILE "${CMAKE_BINARY_DIR}/dtkDepends.cmake")
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Fri Feb 8 16:49:52 2013 (+0100)
## Version:
## Last-Updated: Mon Feb 11 12:44:11 2013 (+0100)
## Last-Updated: Tue Feb 26 14:58:04 2013 (+0100)
## By: Julien Wintz
## Update #: 13
## Update #: 15
######################################################################
##
### Change Log:
......@@ -56,9 +56,3 @@ install(TARGETS ${PROJECT_NAME}
DESTINATION lib
COMPONENT core
EXPORT dtkDepends)
## ###################################################################
## Export rules
## ###################################################################
export(TARGETS dtkCore APPEND FILE "${CMAKE_BINARY_DIR}/dtkDepends.cmake")
......@@ -83,9 +83,3 @@ install(TARGETS ${PROJECT_NAME}
DESTINATION lib
COMPONENT distributed
EXPORT dtkDepends)
## ###################################################################
## Export rules
## ###################################################################
export(TARGETS dtkDistributed APPEND FILE "${CMAKE_BINARY_DIR}/dtkDepends.cmake")
......@@ -81,6 +81,11 @@ void dtkDistributedCommunicator::spawn(QStringList hostnames, qlonglong np, dtkD
{
}
void dtkDistributedCommunicator::exec(void)
{
}
void dtkDistributedCommunicator::barrier(void)
{
......
......@@ -55,6 +55,8 @@ public:
public:
virtual void spawn(QStringList hostnames, qlonglong np, dtkDistributedWorker worker);
virtual void exec();
virtual void barrier();
public:
......
......@@ -34,7 +34,8 @@ dtkDistributedPolicy::dtkDistributedPolicy(void) : QObject(), d(new dtkDistribut
dtkDistributedPolicy::~dtkDistributedPolicy(void)
{
delete d;
d=NULL;
d = NULL;
}
dtkDistributedPolicy::dtkDistributedPolicy(const dtkDistributedPolicy& other)
......@@ -43,11 +44,13 @@ dtkDistributedPolicy::dtkDistributedPolicy(const dtkDistributedPolicy& other)
dtkDistributedPolicy& dtkDistributedPolicy::operator = (const dtkDistributedPolicy& other)
{
return (*this);
}
void dtkDistributedPolicy::addHost(QString host)
{
qDebug() << "add host " << host;
d->hosts.append(host);
}
......@@ -76,5 +79,3 @@ QStringList dtkDistributedPolicy::hosts(void)
{
return d->hosts;
}
......@@ -15,6 +15,7 @@
#include "dtkDistributedWorker.h"
#include <dtkDistributed/dtkDistributedCommunicator.h>
#include <dtkDistributed/dtkDistributedWork.h>
......@@ -69,8 +70,13 @@ dtkDistributedWorker::dtkDistributedWorker(const dtkDistributedWorker& other): Q
dtkDistributedWorker& dtkDistributedWorker::operator = (const dtkDistributedWorker& other)
{
return *this;
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);
}
void dtkDistributedWorker::setWid(qlonglong wid)
......@@ -121,7 +127,7 @@ dtkDistributedCommunicator *dtkDistributedWorker::communicator(void)
void dtkDistributedWorker::run(void)
{
qDebug() << "thread " << d->wid << "barrier" ;
qDebug() << "thread " << d->wid << "barrier";
d->comm->barrier();
qDebug() << "thread " << d->wid << "barrier released, run";
d->work->run();
......
......@@ -38,7 +38,8 @@ dtkDistributedWorkerManager::dtkDistributedWorkerManager(void) : QObject(), d(ne
dtkDistributedWorkerManager::~dtkDistributedWorkerManager(void)
{
delete d;
d=NULL;
d = NULL;
}
dtkDistributedWorkerManager::dtkDistributedWorkerManager(const dtkDistributedWorkerManager& other)
......@@ -47,6 +48,7 @@ dtkDistributedWorkerManager::dtkDistributedWorkerManager(const dtkDistributedWor
dtkDistributedWorkerManager& dtkDistributedWorkerManager::operator = (const dtkDistributedWorkerManager& other)
{
return (*this);
}
void dtkDistributedWorkerManager::setCommunicator(dtkDistributedCommunicator *comm)
......@@ -60,18 +62,26 @@ void dtkDistributedWorkerManager::setPolicy(dtkDistributedPolicy *policy)
d->comm = policy->communicator();
}
void dtkDistributedWorkerManager::spawn(dtkDistributedWork *work)
void dtkDistributedWorkerManager::setWork(dtkDistributedWork *work)
{
d->worker.setWork(work);
}
void dtkDistributedWorkerManager::spawn(void)
{
d->worker.setCommunicator(d->comm);
QStringList hosts = d->policy->hosts();
d->comm->spawn(hosts, hosts.count(), d->worker);
}
void dtkDistributedWorkerManager::exec(void)
{
d->comm->exec();
}
void dtkDistributedWorkerManager::unspawn(void)
{
d->comm->uninitialize();
}
......@@ -37,9 +37,11 @@ public:
public:
void setCommunicator(dtkDistributedCommunicator *comm);
void setPolicy(dtkDistributedPolicy *policy);
void setWork(dtkDistributedWork *Work);
public:
void spawn(dtkDistributedWork *Work);
void spawn(void);
void exec(void);
void unspawn(void);
public:
......
......@@ -3,9 +3,9 @@
## Author: Julien Wintz
## Created: Mon Feb 11 19:23:24 2013 (+0100)
## Version:
## Last-Updated: Wed Feb 13 15:22:23 2013 (+0100)
## Last-Updated: Tue Feb 26 14:58:42 2013 (+0100)
## By: Julien Wintz
## Update #: 21
## Update #: 22
######################################################################
##
### Change Log:
......@@ -55,9 +55,3 @@ install(TARGETS ${PROJECT_NAME}
DESTINATION lib
COMPONENT log
EXPORT dtkDepends)
## ###################################################################
## Export rules
## ###################################################################
export(TARGETS dtkLog APPEND FILE "${CMAKE_BINARY_DIR}/dtkDepends.cmake")
......@@ -3,9 +3,9 @@
* Author: Julien Wintz
* Created: Mon Feb 4 14:11:27 2013 (+0100)
* Version:
* Last-Updated: 2013 Tue Feb 12 14:34:04 (+0100)
* By: Thibaud Kloczko
* Update #: 103
* Last-Updated: Tue Feb 26 14:35:33 2013 (+0100)
* By: Julien Wintz
* Update #: 107
*/
/* Change Log:
......@@ -40,11 +40,9 @@ void dtkDistributedCommunicatorTestCase::testPlugin(void)
{
dtkDistributedCommunicator *communicator = dtkDistributed::communicator::pluginFactory().create("mpi");
communicator->initialize();
qDebug() << communicator->metaObject()->className();
qDebug() << communicator->pid();
qDebug() << communicator->size();
communicator->uninitialize();
delete communicator;
}
......
......@@ -18,8 +18,6 @@
#include <dtkDistributed/dtkDistributedWork.h>
#include <dtkDistributed/dtkDistributedWorker.h>
#include <dtkDistributed/dtkDistributedWorkerManager.h>
#include <dtkDistributed/dtkDistributedArray.h>
#include <dtkDistributed/dtkDistributedArrayHandler.h>
class containerWork : public dtkDistributedWork
{
......@@ -74,95 +72,107 @@ class containerWork : public dtkDistributedWork
}
};
class globalLocalWork : public dtkDistributedWork
class sumWork : public dtkDistributedWork
{
globalLocalWork *clone(void) { return new globalLocalWork(*this); };
void run(void)
{
sumWork *clone(void);
void run(void);
// qDebug()<< "run!!!!";
// qlonglong N = 10000000;
};
// qlonglong sum = 0;
// for (qlonglong i = 0; i < N; ++i)
// sum += 2*i;
sumWork *sumWork::clone(void)
{
return new sumWork(*this);
}
// dtkDistributedCommunicator *comm = dtkDistributedWork::worker()->communicator();
void sumWork::run(void)
{
qDebug()<< "run!!!!";
// QTime time, maintime;
// maintime.start();
// time.start();
qlonglong N = 10000000;
qlonglong sum = 0;
// dtkDistributedContainer<qlonglong>& c = *(new dtkDistributedContainer<qlonglong>(N,dtkDistributedWork::worker() ));
for (qlonglong i = 0; i < N; ++i)
sum += 2*i;
// QVERIFY(N == c.size());
dtkDistributedCommunicator *comm = dtkDistributedWork::worker()->communicator();
// qDebug()<< "allocation time:" <<time.elapsed() << "ms"; time.restart();
// DTK_DISTRIBUTED_BEGIN_LOCAL
QTime time, maintime;
maintime.start();
time.start();
// dtkDistributedLocalIterator<qlonglong>& it = c.localIterator();
dtkDistributedContainer<qlonglong>& c = *(new dtkDistributedContainer<qlonglong>(N,dtkDistributedWork::worker() ));
// // Fill the container in parallel
// while(it.hasNext()) {
// c.setLocal(it.index(), it.globalIndex());
// it.next();
// }
QVERIFY(N == c.size());
// comm->barrier();
qDebug()<< "allocation time:" <<time.elapsed() << "ms"; time.restart();
// it.toFront();
DTK_DISTRIBUTED_BEGIN_LOCAL
// // Do the computation in parallel
// while(it.hasNext()) {
// c.setLocal(it.index(), 2 * it.peekNext() );
// it.next();
// }
dtkDistributedLocalIterator<qlonglong>& it = c.localIterator();
// // it.toFront();
// // while(it.hasNext()) {
// // qDebug() << dtkDistributedWork::worker()->wid() << it.index() << it.peekNext();
// // it.next();
// // }
// Fill the container in parallel
while(it.hasNext()) {
c.setLocal(it.index(), it.globalIndex());
it.next();
}
// comm->barrier();
comm->barrier();
// qlonglong check_sum = 0;
it.toFront();
// dtkDistributedContainer<qlonglong>& partial_sum = *(new dtkDistributedContainer<qlonglong>(dtkDistributedWork::worker()->wct(), dtkDistributedWork::worker() ));
// Do the computation in parallel
while(it.hasNext()) {
c.setLocal(it.index(), 2 * it.peekNext() );
it.next();
}
// dtkDistributedIterator<qlonglong>& it_partial = partial_sum.iterator();
// comm->barrier();
// it.toFront();
// it.toFront();
// while(it.hasNext()) {
// qDebug() << dtkDistributedWork::worker()->wid() << it.index() << it.peekNext();
// it.next();
// }
// // Do the partial sum in parallel, and put the result in a parallel container (of size = number of process/threads)
// while(it.hasNext()) {
// check_sum += c.localAt(it.index());
// it.next();
// }
// partial_sum.setLocal(0,check_sum);
comm->barrier();
// DTK_DISTRIBUTED_END_LOCAL
qlonglong check_sum = 0;
// DTK_DISTRIBUTED_BEGIN_GLOBAL
dtkDistributedContainer<qlonglong>& partial_sum = *(new dtkDistributedContainer<qlonglong>(dtkDistributedWork::worker()->wct(), dtkDistributedWork::worker() ));
// // Sum the partial sums in sequential mode
// check_sum = 0;
// while(it_partial.hasNext()) {
dtkDistributedIterator<qlonglong>& it_partial = partial_sum.iterator();
comm->barrier();
it.toFront();
// check_sum += partial_sum.at(it_partial.index());
// it_partial.next();
// }
// Do the partial sum in parallel, and put the result in a parallel container (of size = number of process/threads)
while(it.hasNext()) {
check_sum += c.localAt(it.index());
it.next();
}
partial_sum.setLocal(0,check_sum);
// qDebug() << "TOTAL SUM" << check_sum << sum << maintime.elapsed() << "ms";
// QVERIFY(sum == check_sum);
DTK_DISTRIBUTED_END_LOCAL
// DTK_DISTRIBUTED_END_GLOBAL
DTK_DISTRIBUTED_BEGIN_GLOBAL
// delete &c;
// delete &partial_sum;
}
};
// Sum the partial sums in sequential mode
check_sum = 0;
while(it_partial.hasNext()) {
check_sum += partial_sum.at(it_partial.index());
it_partial.next();
}
qDebug() << "TOTAL SUM" << check_sum << sum << maintime.elapsed() << "ms";
QVERIFY(sum == check_sum);
DTK_DISTRIBUTED_END_GLOBAL
delete &c;
delete &partial_sum;
}
void dtkDistributedContainerTestCase::initTestCase(void)
{
......@@ -174,11 +184,13 @@ void dtkDistributedContainerTestCase::init(void)
}
void dtkDistributedContainerTestCase::testGlobalLocal(void)
void dtkDistributedContainerTestCase::testSum(void)
{
dtkDistributedPolicy policy;
QByteArray numprocs = qgetenv("DTK_NUM_THREADS");
QByteArray policyEnv = qgetenv("DTK_DISTRIBUTED_POLICY");
int np = 2;
policy.setType(dtkDistributedPolicy::MP);
......@@ -187,6 +199,7 @@ void dtkDistributedContainerTestCase::testGlobalLocal(void)
np = numprocs.toInt();
qDebug() << "got num procs from env" << np;
}
if (!policyEnv.isEmpty()) {
qDebug() << "got policy from env" << policyEnv;
if (QString(policyEnv) == "MT"){
......@@ -202,11 +215,13 @@ void dtkDistributedContainerTestCase::testGlobalLocal(void)
policy.addHost("localhost");
dtkDistributedWorkerManager manager;
globalLocalWork *work = new globalLocalWork();
sumWork *work = new sumWork();
manager.setPolicy(&policy);
manager.setWork(work);
qDebug() << "spawn";
manager.spawn(work);
manager.spawn();
manager.exec();
manager.unspawn();
}
......@@ -241,8 +256,10 @@ void dtkDistributedContainerTestCase::testContainer(void)
containerWork *work = new containerWork();
manager.setPolicy(&policy);
manager.setWork(work);
qDebug() << "spawn";
manager.spawn(work);
manager.spawn();
manager.exec();
manager.unspawn();
}
......
......@@ -25,7 +25,7 @@ private slots:
void init(void);
private slots:
void testGlobalLocal(void);
void testSum(void);
void testContainer(void);
private slots:
......
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