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 3118 - (download) (annotate)
Mon Mar 23 18:05:45 2015 UTC (4 years, 2 months ago) by jhr
File size: 2680 byte(s)
  working on OpenCL issues
//! Main function for standalone parallel C target
//
int main (int argc, const char **argv)
{
    bool        timingFlg = false;      //! true if timing computation
    bool        printOutputFlg = false; //! true if output is in text format

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

#ifndef DIDEROT_NO_INPUTS
  // initialize the default values for the inputs
    @PREFIX@Inputs_t inputs;
    InitDefaults (&inputs);
#endif

  // 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_OptAddFlag (opts, "T,text", "enable text output", &printOutputFlg);
	Diderot_OptAddUInt (opts, "n,nworkers", "specify number of worker threads", &np, true);
#ifndef DIDEROT_NO_INPUTS
      // register options for setting global inputs
	RegisterGlobalOpts (&inputs, opts);
#endif
	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));
        exit(1);
    }

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

  // 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));
        exit(1);
    }

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

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

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

    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
    if (printOutputFlg)
        PrintOutput (wrld);
    else
        WriteOutput (wrld);
    
    @PREFIX@Shutdown (wrld);

    return 0;

} // main

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