main.cpp 2.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* main.cpp ---
 *
 * Author: Nicolas Niclausse
 * Copyright (C) 2014 - Nicolas Niclausse, Inria.
 * Created: 2014/10/28 12:45:34
 */

/* Commentary:
 *
 */

/* Change log:
 *
 */



18 19 20

#include <dtkDistributed>
#include <dtkComposer>
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

#include <QtConcurrent>

int main(int argc, char **argv)
{


    bool useGUI = false;

    QApplication application(argc, argv, useGUI);
    application.setApplicationName("dtkComposerEvaluator");
    application.setApplicationVersion("1.0.0");
    application.setOrganizationName("inria");
    application.setOrganizationDomain("fr");

    // plugins
    dtkDistributedSettings settings;
    settings.beginGroup("communicator");
    qDebug() << "initialize plugin manager "<< settings.value("plugins").toString();
    dtkDistributed::communicator::pluginManager().initialize(settings.value("plugins").toString());
    qDebug() << "initialization done ";
    settings.endGroup();

    qDebug() << dtkDistributed::communicator::pluginManager().plugins();
    qDebug() << dtkDistributed::communicator::pluginFactory().keys();

    QStringList args = QCoreApplication::arguments();
    if(args.count() < 2) {
        qDebug() << "argv" << args;
        qDebug() << "Usage: " << argv[0] << "--spawn | [-pg] <composition> ";
        return 0;
    }

54
    dtkComposerNodeFactory *factory = new dtkComposerNodeFactory;
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

    if (args[1] == "--spawn") {

        // FIXME: don't hardcode plugin
        dtkDistributedPolicy policy;
        dtkDistributedWorkerManager manager;
        policy.setType("mpi3");
        manager.setPolicy(&policy);

        dtkComposerEvaluatorProcess p;

        QStringList hosts;
        // dtkDistributedCommunicator *comm = manager.spawn();
        dtkDistributedCommunicator *comm ;
        manager.spawn();

        p.setInternalCommunicator(comm);
        p.setParentCommunicator(policy.communicator());
        p.setFactory(factory);
        p.setApplication("dtkComposerEvaluator");

        int value;
        do  { value = p.exec(); } while (value  == 0);

        return value;
    }

    dtkComposerScene *scene = new dtkComposerScene;
    dtkComposerStack *stack = new dtkComposerStack;
    dtkComposerGraph *graph = new dtkComposerGraph;
    dtkComposerEvaluator *evaluator = new dtkComposerEvaluator;;

    scene->setFactory(factory);
    scene->setStack(stack);
    scene->setGraph(graph);

    evaluator->setGraph(graph);

    dtkComposerReader *reader;
    reader = new dtkComposerReader;
    reader->setFactory(factory);
    reader->setScene(scene);
    reader->setGraph(graph);

    int index= 1;

    if (args[1] == "-pg") {
        index = 2;
        evaluator->setProfiling(true);
    }


    if (!reader->read(argv[index])) {
        qDebug() << "read failure for " << argv[index];
        return 1;
    } else {

        QObject::connect(evaluator,SIGNAL(evaluationStopped()),&application, SLOT(quit()));
        QtConcurrent::run(evaluator, &dtkComposerEvaluator::run_static, false);
        application.exec();
        // dtkPluginManager::instance()->uninitialize();
    }
}