Exemplo n.º 1
0
// Syntax (typical):
//   computeLocalSolutions case=<ecl_case_prefix> step=<report_number>
int main(int argc, char* argv[])
try {
    example::Setup setup(argc, argv);
    auto& fdTool = setup.toolbox;

    {
        const auto inj = injectors(setup);
        const auto fwd = fdTool.computeInjectionDiagnostics(inj);

        runAnalysis(inj, fwd.fd, true);
    }

    {
        const auto prod = producers(setup);
        const auto rev  = fdTool.computeProductionDiagnostics(prod);

        runAnalysis(prod, rev.fd, false);
    }
}
catch (const std::exception& e) {
    std::cerr << "Caught exception: " << e.what() << '\n';
}
Exemplo n.º 2
0
void test_malloc_speed()
{
    int Nprod = 1;
    int Ncons = 1;
    int Ntask = 128;
    int Npipelines = 20;
    int NconsQsize = 1024*1024;

    int sizeBegin = 1;
    int sizeRep = 1000*100;
    int sizeCount = 10;
    TimePoint t0 = Now(), t1;

    std::vector<AllocateTaskPtr> allocTasks(Ntask);
    for(int i=0; i<Ntask; ++i) {
        allocTasks[i].reset(new AllocateTask(sizeBegin, sizeRep, sizeCount));
    }

    //--- pipeline model
#ifdef TEST_PIPLELINE
    printf("pipelines:%d, tasks:%d, size:%d->%d, sizeRep:%d\n", Npipelines, Ntask, sizeBegin, sizeBegin<<sizeCount, sizeRep);
    {
        std::vector<ThreadPoolPtr> pipelines(Npipelines);
        for(int i=0; i<Npipelines; ++i) {
            pipelines[i].reset(new ThreadPool(AllocateTask::allocate_and_free, 1, NconsQsize));
        }
        t0 = Now();
        for(int i=0; i<Npipelines; ++i) {
            for(int j=0; j<Ntask; ++j)
                pipelines[i]->post(allocTasks[j].get());
        }
        for(;;) {  // wait for all tasks completion
            int n=0;
            for(int i=0; i<Npipelines; ++i) {
                n += pipelines[i]->task_count();     // pending tasks
                n += pipelines[i]->working_count();  // working tasks
            }
            if( n == 0 ) break; // no working threads or tasks.
            Sleep(10);
        }
        t1 = Now();
        printf("pipeline time:%dms\n", ToMilli(t1-t0));
    }
  #endif

    //--- produce-consume model
 #ifdef TEST_PROD_CONSUME
    printf("producers:%d, consumers:%d, tasks:%d, size:%d->%d, sizeRep:%d\n", Nprod, Ncons, Ntask, sizeBegin, sizeBegin<<sizeCount, sizeRep);

    {
        ThreadPoolPtr producers(new ThreadPool(AllocateTask::dowork, Nprod, Ntask));
        ThreadPoolPtr consumers(new ThreadPool(DeallocateTask::dowork, Ncons, NconsQsize));

        t0 = Now();
        for(int i=0; i<Ntask; ++i) {
            //allocTasks[i]->operator()();
            allocTasks[i]->sink = consumers;
            if(!producers->post(allocTasks[i].get())) {
                printf("Failed to post to producer");
            }
        }

        for(;;) {  // wait for all tasks completion
            int n=0;
                n += producers->task_count();     // pending tasks
                n += producers->working_count();  // working tasks
                n += consumers->task_count();     // pending tasks
                n += consumers->working_count();  // working tasks
            if( n == 0 ) break; // no working threads or tasks.
            Sleep(10);
        }
        t1 = Now();
        printf("produce-consume time:%dms\n", ToMilli(t1-t0));
    }
#endif
}