Beispiel #1
0
int main(int argc, char *argv[])
{
    try {
        tbb::tick_count mainStartTime = tbb::tick_count::now();
        RunOptions options = ParseCommandLine(argc,argv);
        SeismicVideo video(u,options.numberOfFrames,options.threads.last,options.parallel);

        // video layer init
        if(video.init_window(u.UniverseWidth, u.UniverseHeight)) {
            video.calc_fps = true;
            video.threaded = options.threads.first > 0;
            // video is ok, init Universe
            u.InitializeUniverse(video);
            // main loop
            video.main_loop();
        }
        else if(video.init_console()) {
            // do console mode
            for(int p = options.threads.first;  p <= options.threads.last; ++p ) {
                tbb::tick_count xwayParallelismStartTime = tbb::tick_count::now();
                u.InitializeUniverse(video);
                int numberOfFrames = options.numberOfFrames;
#if __TBB_MIC
                drawing_memory dmem = video.get_drawing_memory();
                char *pMem = dmem.get_address();
                size_t memSize = dmem.get_size();

#pragma offload target(mic) in(u, numberOfFrames, p, dmem), out(pMem:length(memSize))
                {
                    // It is necessary to update the pointer on mic
                    // since the address spaces on host and on target are different
                    dmem.set_address(pMem);
                    u.SetDrawingMemory(dmem);
#endif // __TBB_MIC
                    if (p==0) {
                        //run a serial version
                        for( int i=0; i<numberOfFrames; ++i ) {
                            u.SerialUpdateUniverse();
                        }
                    } else {
                        tbb::task_scheduler_init init(p);
                        for( int i=0; i<numberOfFrames; ++i ) {
                            u.ParallelUpdateUniverse();
                        }
                    }
#if __TBB_MIC
                }
#endif // __TBB_MIC

                if (!options.silent) {
                    double fps =  options.numberOfFrames/((tbb::tick_count::now()-xwayParallelismStartTime).seconds());
                    std::cout<<fps<<" frame per sec with ";
                    if (p==0) {
                        std::cout<<"serial code\n";
                    } else {
                        std::cout<<p<<" way parallelism\n";
                    }
                }
            }
        }
        video.terminate();
        utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
        return 0;
    } catch(std::exception& e) {
        std::cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n";
        return 1;
    }
}