Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/vis15/src/compiler/target-cpu/fragments/par-main.in
ViewVC logotype

View of /branches/vis15/src/compiler/target-cpu/fragments/par-main.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4651 - (download) (annotate)
Wed Sep 28 16:21:56 2016 UTC (2 years, 11 months ago) by jhr
File size: 3512 byte(s)
working on merge: fix grammar of message
using namespace @PREFIX@;

//! Main function for standalone parallel C target
//
int main (int argc, const char **argv)
{
    bool        timingFlg = false;      //! true if timing computation
    uint32_t    stepLimit = 0;          //! limit on number of execution steps (0 means unlimited)
    std::string printFile = "-";        //! file to direct printed output into

  // create the world
    world *wrld = new (std::nothrow) world();
    if (wrld == nullptr) {
        std::cerr << "unable to create world" << std::endl;
        exit (1);
    }

#ifndef DIDEROT_NO_INPUTS
  // initialize the default values for the inputs
    cmd_line_inputs inputs;
    init_defaults (&inputs);
#endif

  // handle command-line options
    {
        diderot::options<@REALTY@,@INTTY@> *opts = new diderot::options<@REALTY@,@INTTY@> ();
        uint32_t np = wrld->_sched->_numWorkers;
        opts->addFlag ("v,verbose", "enable runtime-system messages", &(wrld->_verbose));
        opts->addFlag ("t,timing", "enable execution timing", &timingFlg);
        opts->add ("n,nworkers", "specify number of worker threads", &np, true);
        opts->add ("l,limit", "specify limit on number of super-steps (0 means unlimited)",
            &stepLimit, true);
        opts->add ("print", "specify where to direct printed output", &printFile, true);
#ifndef DIDEROT_NO_INPUTS
      // register options for setting global inputs
        register_inputs (&inputs, opts);
#endif
        register_outputs (opts);
        opts->process (argc, argv);
        delete opts;
        wrld->_sched->_numWorkers = np;
    }

  // redirect printing (if necessary)
    if (printFile.compare("-") != 0) {
        wrld->_printTo = new std::ofstream (printFile);
        if (wrld->_printTo->fail()) {
            std::cerr << "Error opening print file" << std::endl;
            exit(1);
        }
    }

  // initialize scheduler stuff
    if (wrld->_verbose) {
        std::cerr << "initializing world ..." << std::endl;
    }
    if (wrld->init()) {
        std::cerr << "Error initializing world:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
        exit(1);
    }

#ifndef DIDEROT_NO_INPUTS
  // initialize the input globals
    if (init_inputs (wrld, &inputs)) {
        std::cerr << "Error initializing inputs:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
        exit(1);
    }
#endif

  // run the generated global initialization code
    if (wrld->_verbose) {
        std::cerr << "initializing globals and creating strands ...\n";
    }
    if (wrld->create_strands()) {
        std::cerr << "Error in global initialization:\n"
            << biffMsgStrGet(wrld->_errors) << std::endl;
        exit(1);
    }

    uint32_t nSteps = wrld->run (stepLimit);

    if (wrld->_errors->errNum > 0) {
        std::cerr << "Error during execution:\n" << biffMsgStrGet(wrld->_errors) << std::endl;
        exit(1);
    }

    if (wrld->_verbose) {
        std::cerr << "done: " << nSteps << " steps, in " << wrld->_run_time << " seconds"
            << std::endl;
    }
    else if (timingFlg) {
        std::cout << "usr=" << wrld->_run_time << std::endl;
    }

#ifdef DIDEROT_HAS_STRAND_DIE
  // check that there are strands that have output
    if (wrld->_strands.num_stable() == 0) {
        std::cerr << "Error: no stable strands at program termination, so no output was produced."
	    << std::endl;
	return 1;
    }
#endif

  // output the final strand states
    write_output (wrld);

    delete wrld;

    return 0;

} // main

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0