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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1719 - (download) (annotate)
Mon Mar 12 20:12:34 2012 UTC (7 years, 7 months ago) by jhr
File size: 1772 byte(s)
  Add fragments for sequential and parallel main functions, which will be used
  to generate standalone executables
//! Main function for 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@Init();
    if (wrld == 0) {
        fprintf(stderr, "unable to create world\n");
        exit (1);
    }

    CPUInfo_t cpuInfo;
    if (! GetNumCPUs (&cpuInfo)) {
        fprintf(stderr, "unable to get number of processors\n");
        exit (1);
    }

    Diderot_int_t np = cpuInfo.numHWCores;

  // handle command-line options
    Diderot_Options_t *opts = Diderot_OptNew ();

    Diderot_OptAddFlag (opts, "timing", "enable execution timing", &timingFlg);
    Diderot_OptAddFlag (opts, "nrrd", "enable nrrd output", &printOutputFlg);
    Diderot_OptAddInt (opts, "np", "specify number of worker threads", &np, true);
    RegisterGlobalOpts (wrld, opts);

    Diderot_OptProcess (opts, argc, argv);
    Diderot_OptFree (opts);

  // run the generated global initialization code
    if (wrld->verboseFlg)
        fprintf (stderr, "initializing globals ...\n");
    @PREFIX@Initially (wrld);

    if (wrld->verboseFlg)
        fprintf(stderr, "run with %d strands ...\n", wrld->numStrands);
    double t0 = airTime();
    uint32_t nSteps = @PREFIX@Run (wrld, 0);
    double totalTime = airTime() - t0;

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

  // 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