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 3132 - (download) (annotate)
Wed Mar 25 15:25:10 2015 UTC (4 years, 3 months ago) by jhr
File size: 3723 byte(s)
remember to initialize the number of workers
//! Main function for standalone 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) {
        fprintf(stderr, "unable to create world\n");
        exit (1);
    }

  // get default OpenCL device
    Diderot_DeviceInfo_t *clDevice = Diderot_DefaultCLDevice (wrld->oclInfo);
    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;

#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 nw = wrld->nWorkers;
	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_OptAddString (opts, "d,device", "OpenCL device index", &devName, true);
	Diderot_OptAddUInt (opts, "n,nworkers", "specify number of workers per compute unit", &nw, 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);
      // 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(wrld->oclInfo, platIdx, devIdx);
	    if (clDevice == 0) {
		fprintf (stderr, "specified device %d.%d does not exist\n", platIdx, devIdx);
		exit (1);
	    }
	    wrld->device = clDevice;
	}
	wrld->nWorkers = nw;
    }

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