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

SCM Repository

[diderot] View of /branches/vis12-cl/src/compiler/c-target/fragments/par-main.in
ViewVC logotype

View of /branches/vis12-cl/src/compiler/c-target/fragments/par-main.in

Parent Directory Parent Directory | Revision Log Revision Log

Revision 3178 - (download) (annotate)
Mon Mar 30 15:18:21 2015 UTC (4 years ago) by jhr
File size: 2697 byte(s)
  Increased GRAB_SZ for OpenCL target; added step limit command-line option.
//! 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)

  // create the world
    @PREFIX@World_t *wrld = @PREFIX@New();
    if (wrld == 0) {
        fprintf(stderr, "unable to create world\n");
        exit (1);

  // initialize the default values for the inputs
    @PREFIX@Inputs_t inputs;
    InitDefaults (&inputs);

  // handle command-line options
	Diderot_Options_t *opts = Diderot_OptNew ();
	Diderot_uint_t np = wrld->sched->numWorkers;
	Diderot_OptAddFlag (opts, "v,verbose", "enable runtime-system messages", &(wrld->verboseFlg));
	Diderot_OptAddFlag (opts, "t,timing", "enable execution timing", &timingFlg);
	Diderot_OptAddUInt (opts, "n,nworkers", "specify number of worker threads", &np, true);
	Diderot_OptAddUInt (opts, "l,limit", "specify limit on number of super-steps (0 means unlimited)",
            &stepLimit, true);
      // register options for setting global inputs
	RegisterGlobalOpts (&inputs, opts);
	RegisterOutputOpts (opts);
	Diderot_OptProcess (opts, argc, argv);
	Diderot_OptFree (opts);
	wrld->sched->numWorkers = np;

  // initialize scheduler stuff
    if (wrld->verboseFlg)
        fprintf (stderr, "initializing world ...\n");
    if (@PREFIX@Init (wrld)) {
        fprintf(stderr, "Error initializing world:\n%s\n", biffMsgStrGet(wrld->errors));

  // initialize the input globals
    if (InitInputs (wrld, &inputs)) {
	fprintf(stderr, "Error initializing inputs:\n%s\n", biffMsgStrGet(wrld->errors));

  // run the generated global initialization code
    if (wrld->verboseFlg)
        fprintf (stderr, "initializing globals ...\n");
    if (@PREFIX@Initially (wrld)) {
        fprintf(stderr, "Error in global initialization:\n%s\n", biffMsgStrGet(wrld->errors));

    if (wrld->verboseFlg)
        fprintf(stderr, "run with %d strands ...\n", wrld->numStrands);

    uint32_t nSteps = @PREFIX@Run (wrld, stepLimit);

    if (wrld->errors->errNum > 0) {
        fprintf(stderr, "Error during execution:\n%s\n", biffMsgStrGet(wrld->errors));

    if (wrld->verboseFlg)
        fprintf (stderr, "done: %d steps, in %f seconds\n", nSteps, wrld->runTime);
    else if (timingFlg)
        printf ("usr=%f\n", wrld->runTime);

  // output the final strand states
    WriteOutput (wrld);
    @PREFIX@Shutdown (wrld);

    return 0;

} // main

ViewVC Help
Powered by ViewVC 1.0.0