<commit_before>/* dtkDistributedContainerTest.cpp --- 
 * 
 * Author: <NAME>
 * Created: 2013 Mon Feb  4 15:37:54 (+0100)
 */

/* Commentary: 
 * 
 */

/* Change log:
 * 
 */

#include "dtkDistributedContainerTest.h"
#include <dtkDistributed>
#include <dtkDistributed/dtkDistributedPolicy.h>
#include <dtkDistributed/dtkDistributedWork.h>
#include <dtkDistributed/dtkDistributedWorker.h>
#include <dtkDistributed/dtkDistributedWorkerManager.h>

class myWork : public dtkDistributedWork
{
    myWork *clone(void) {return new myWork(*this); };

    void run(void)
        {
            qDebug()<< "run!!!!";
            qlonglong N = 2000000;

            qlonglong sum = 0;
            for (qlonglong i = 0; i < N; ++i)
                sum += 2*i;

            dtkDistributedCommunicator *comm = dtkDistributedWork::worker()->communicator();

            dtkDistributedContainer<qlonglong>& c = *(new dtkDistributedContainer<qlonglong>(N,dtkDistributedWork::worker() ));

            QVERIFY(N == c.size());

            QTime time, maintime;
            maintime.start();
            time.start();
            dtkDistributed::setMode(dtkDistributed::Global);
            comm->barrier();
            if (dtkDistributedWork::worker()->master()) {
                qDebug() << "first barrier " <<  time.elapsed() << "ms";
                time.restart();
            }
            dtkDistributedIterator<qlonglong>& it  = c.iterator();

            if (dtkDistributedWork::worker()->wid() == 0) {

                while(it.hasNext()) {
                    c.set(it.index(), it.index());
                    it.next();
                }
            }
            comm->barrier();

            if (dtkDistributedWork::worker()->master()) {
                qDebug() << "global section:" <<  time.elapsed() << "ms";
                time.restart();
            }
            dtkDistributed::setMode(dtkDistributed::Local);
            it.toFront();

            while(it.hasNext()) {
                c.setLocal(it.index(),  2 * it.peekNext() );
                it.next();
            }

            it.toFront();
            while(it.hasNext()) {
//                qDebug() << dtkDistributedWork::worker()->wid() << it.index() << it.peekNext();
                it.next();
            }


            comm->barrier();
            if (dtkDistributedWork::worker()->master()) {
                qDebug() << "local section:" <<  time.elapsed() << "ms";
                time.restart();
            }
            dtkDistributed::setMode(dtkDistributed::Global);

            qlonglong check_sum = 0;

            it.toFront();

            while(it.hasNext()) {
                check_sum += c.at(it.index());
//                qDebug() << it.index() << it.peekNext();
                it.next();
            }


            if (dtkDistributedWork::worker()->master()) {
                qDebug() << "global section:" <<  time.elapsed() << "ms";
                qDebug() << "TOTAL SUM" << check_sum << maintime.elapsed() << "ms";
                QVERIFY(sum == check_sum);
            }


            comm->barrier();
            delete &c;
            comm->barrier();

        }
};

void dtkDistributedContainerTestCase::initTestCase(void)
{
    dtkDistributed::communicator::pluginManager().initialize();
}

void dtkDistributedContainerTestCase::init(void)
{

}

void dtkDistributedContainerTestCase::testGlobalLocal(void)
{<commit_msg>remove useless if statement + minor fix<commit_after>/* dtkDistributedContainerTest.cpp --- 
 * 
 * Author: <NAME>
 * Created: 2013 Mon Feb  4 15:37:54 (+0100)
 */

/* Commentary: 
 * 
 */

/* Change log:
 * 
 */

#include "dtkDistributedContainerTest.h"
#include <dtkDistributed>
#include <dtkDistributed/dtkDistributedPolicy.h>
#include <dtkDistributed/dtkDistributedWork.h>
#include <dtkDistributed/dtkDistributedWorker.h>
#include <dtkDistributed/dtkDistributedWorkerManager.h>

class myWork : public dtkDistributedWork
{
    myWork *clone(void) {return new myWork(*this); };

    void run(void)
        {
            qDebug()<< "run!!!!";
            qlonglong N = 2000000;

            qlonglong sum = 0;
            for (qlonglong i = 0; i < N; ++i)
                sum += 2*i;

            dtkDistributedCommunicator *comm = dtkDistributedWork::worker()->communicator();

            dtkDistributedContainer<qlonglong>& c = *(new dtkDistributedContainer<qlonglong>(N,dtkDistributedWork::worker() ));

            QVERIFY(N == c.size());

            QTime time, maintime;
            maintime.start();
            time.start();
            dtkDistributed::setMode(dtkDistributed::Global);
            comm->barrier();
            if (dtkDistributedWork::worker()->master()) {
                qDebug() << "first barrier " <<  time.elapsed() << "ms";
                time.restart();
            }
            dtkDistributedIterator<qlonglong>& it  = c.iterator();

            while(it.hasNext()) {
                c.set(it.index(), it.index());
                it.next();
            }

            comm->barrier();

            if (dtkDistributedWork::worker()->master()) {
                qDebug() << "global section:" <<  time.elapsed() << "ms";
                time.restart();
            }
            dtkDistributed::setMode(dtkDistributed::Local);
            it.toFront();

            while(it.hasNext()) {
                c.setLocal(it.index(),  2 * it.peekNext() );
                it.next();
            }

            it.toFront();
            while(it.hasNext()) {
//                qDebug() << dtkDistributedWork::worker()->wid() << it.index() << it.peekNext();
                it.next();
            }


            comm->barrier();
            if (dtkDistributedWork::worker()->master()) {
                qDebug() << "local section:" <<  time.elapsed() << "ms";
                time.restart();
            }
            dtkDistributed::setMode(dtkDistributed::Global);

            qlonglong check_sum = 0;

            it.toFront();

            while(it.hasNext()) {
                check_sum += c.at(it.index());
//                qDebug() << it.index() << it.peekNext();
                it.next();
            }


            if (dtkDistributedWork::worker()->master()) {
                qDebug() << "global section:" <<  time.elapsed() << "ms";
                qDebug() << "TOTAL SUM" << check_sum << maintime.elapsed() << "ms";
                comm->barrier();
                QVERIFY(sum == check_sum);
            } else
                comm->barrier();

            delete &c;

        }
};

void dtkDistributedContainerTestCase::initTestCase(void)
{
    dtkDistributed::communicator::pluginManager().initialize();
}

void dtkDistributedContainerTestCase::init(void)
{

}

void dtkDistributedContainerTestCase::testGlobalLocal(void)
{
{'fraction_non_alphanumeric': 0.15424278137890396, 'fraction_numerical': 0.008102533883323512, 'mean_word_length': 1.850125944584383, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4148081', 'n_tokens_mistral': 2085, 'n_tokens_neox': 1940, 'n_words': 319}