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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2739 - (download) (annotate)
Sat Sep 27 17:23:34 2014 UTC (4 years, 10 months ago) by jhr
File size: 3141 byte(s)
  Working on OpenCL
//! Main function for standalone alone OpenCL 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
    char	*devName;		//! specifies index of OpenCL device as a string

  // create the world
    @PREFIX@World_t *wrld = @PREFIX@New();
    if (wrld == 0)
        exit (1);

  // get default OpenCL device
    Diderot_DeviceInfo_t *clDevice = Diderot_DefaultCLDevice (wrld->clinfo);
    if (clDevice == 0) {
	fprintf (stderr, "unable to get OpenCL default device\n");
	exit (1);
    }

  // name the default device by its index
    char defaultDevName[16];
    snprintf (defaultDevName, sizeof(defaultDevName), "%d.%d",
	clDevice->index[0], clDevice->index[1]);
    devName = defaultDevName;

  // handle command-line options
    {
	Diderot_Options_t *opts = Diderot_OptNew ();
	@PREFIX@Inputs_t inputs;
	InitDefaults (&inputs);
	Diderot_OptAddFlag (opts, "verbose", "enable runtime-system messages", &(wrld->verboseFlg));
	Diderot_OptAddFlag (opts, "timing", "enable execution timing", &timingFlg);
	Diderot_OptAddFlag (opts, "text", "enable text output", &printOutputFlg);
	Diderot_OptAddString (opts, "device", "OpenCL device index", &devName, true);
	RegisterGlobalOpts (&inputs, opts);
	Diderot_OptProcess (opts, argc, argv);
	Diderot_OptFree (opts);
      // determine the OpenCL device
	if (devName != defaultDevName) {
	    unsigned int platIdx, devIdx;
	    if (sscanf(devName, "%u.%u", &platIdx, &devIdx) != 2) {
		fprintf (stderr, "badly formatted device-index specification\n");
		exit (1);
	    }
	    clDevice = Diderot_GetDeviceByIndex(clinfo, platIdx, devIdx);
	    if (clDevice == 0) {
		fprintf (stderr, "specified device %d.%d does not exist\n", platIdx, devIdx);
		exit (1);
	    }
	}
      // initialize the input globals
	if (InitInputs (wrld, &inputs)) {
	    fprintf(stderr, "Error initializing inputs:\n%s\n", biffMsgStrGet(wrld->errors));
	    exit(1);
	}
    }

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

  // 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);
    double t0 = airTime();
    uint32_t nSteps = @PREFIX@Run (wrld, 0);
    double totalTime = airTime() - t0;

    if (wrld->verboseFlg)
        fprintf (stderr, "done: %d steps, in %f seconds\n", 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