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;

  // 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 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);
      // register options for setting global inputs
	RegisterGlobalOpts (&inputs, opts);
	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));

  // 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, 0);

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

    return 0;

} // main

ViewVC Help
Powered by ViewVC 1.0.0