/* Read project preferences and command line arguments */
static int parseParameters(int argc, const char** argv, SeparationFlags* sfOut)
{
    poptContext context;
    int argRead;
    static int version = FALSE;
    static int copyright = FALSE;
    static unsigned int numParams = 0;
    static int serverParams = 0;
    static const char** rest = NULL;
    static SeparationFlags sf;

    static const struct poptOption options[] =
        {
            {
                "astronomy-parameter-file", 'a',
                POPT_ARG_STRING, &sf.ap_file,
                0, "Astronomy parameter file", NULL
            },

            {
                "star-points-file", 's',
                POPT_ARG_STRING, &sf.star_points_file,
                0, "Star points files", NULL
            },

            {
                "output", 'o',
                POPT_ARG_STRING, &sf.separation_outfile,
                0, "Output file for separation (enables separation)", NULL
            },

            {
                "seed", 'e',
                POPT_ARG_INT, &sf.separationSeed,
                SEED_ARGUMENT, "Seed for random number generator", NULL
            },

            {
                "ignore-checkpoint", 'i',
                POPT_ARG_NONE, &sf.ignoreCheckpoint,
                0, "Ignore the checkpoint file", NULL
            },

            {
                "cleanup-checkpoint", 'c',
                POPT_ARG_NONE, &sf.cleanupCheckpoint,
                0, "Delete checkpoint on successful", NULL
            },

            {
                "debug-boinc", 'g',
                POPT_ARG_NONE, &sf.debugBOINC,
                0, "Init BOINC with debugging. No effect if not built with BOINC_APPLICATION", NULL
            },

            {
                "process-priority", 'b',
                POPT_ARG_INT, &sf.processPriority,
                0, "Set process priority. Set priority 0 (lowest) to 4 (highest)", NULL
            },

            {
                "device", 'd',
                POPT_ARG_INT, &sf.useDevNumber,
                0, "Device number passed by BOINC to use", NULL
            },

            {
                "non-responsive", 'r',
                POPT_ARG_NONE, &sf.nonResponsive,
                0, "Do not care about display responsiveness (use with caution)", NULL
            },

            {
                "gpu-target-frequency", 'q',
                POPT_ARG_DOUBLE, &sf.targetFrequency,
                0, "Target frequency for GPU tasks" , NULL
            },

            {
                "gpu-wait-factor", 'w',
                POPT_ARG_DOUBLE, &sf.waitFactor,
                0, "Wait correction factor when using high CPU workarounds" , NULL
            },

            {
                "gpu-polling-mode", 'm',
                POPT_ARG_INT, &sf.pollingMode,
                0, "Interval for polling GPU: (-2 (default): Use mode -1 unless working around high CPU driver issue.  -1: use clWaitForEvents(). 0: Use clWaitForEvents() with initial wait, >= 1: sets manual interval polling in ms)" , NULL
            },

            {
                "gpu-disable-checkpointing", 'k',
                POPT_ARG_NONE, &sf.disableGPUCheckpointing,
                0, "Disable checkpointing with GPUs" , NULL
            },

            {
                "platform", 'l',
                POPT_ARG_INT, &sf.usePlatform,
                0, "CL platform index to use", NULL
            },

            {
                "platform-vendor", '\0',
                POPT_ARG_STRING, &sf.preferredPlatformVendor,
                0, "CL Platform vendor name to try to use", NULL
            },

            {
                "verbose", '\0',
                POPT_ARG_NONE, &sf.verbose,
                0, "Print some extra debugging information", NULL
            },

            {
                "force-no-opencl", '\0',
                POPT_ARG_NONE, &sf.forceNoOpenCL,
                0, "Use regular CPU path instead of OpenCL if available", NULL
            },

            {
                "force-no-il-kernel", '\0',
                POPT_ARG_NONE, &sf.forceNoILKernel,
                0, "Do not use AMD IL replacement kernels if available", NULL
            },

            {
                "force-no-intrinsics", '\0',
                POPT_ARG_NONE, &sf.forceNoIntrinsics,
                0, "Use old default path", NULL
            },

            {
                "force-x87", '\0',
                POPT_ARG_NONE, &sf.forceX87,
                0, "Force to use x87 path (ignored if x86_64)", NULL
            },

            {
                "force-sse2", '\0',
                POPT_ARG_NONE, &sf.forceSSE2,
                0, "Force to use SSE2 path", NULL
            },

            {
                "force-sse3", '\0',
                POPT_ARG_NONE, &sf.forceSSE3,
                0, "Force to use SSE3 path", NULL
            },

            {
                "force-sse4.1", '\0',
                POPT_ARG_NONE, &sf.forceSSE41,
                0, "Force to use SSE4.1 path", NULL
            },

            {
                "force-avx", '\0',
                POPT_ARG_NONE, &sf.forceAVX,
                0, "Force to use AVX path", NULL
            },

            {
                "p", 'p',
                POPT_ARG_NONE, &serverParams,
                0, "Unused dummy argument to satisfy primitive arguments the server sends", NULL
            },

            {
                "np", '\0',
                POPT_ARG_INT | POPT_ARGFLAG_ONEDASH, &numParams,
                0, "Unused dummy argument to satisfy primitive arguments the server sends", NULL
            },

            {
                "version", 'v',
                POPT_ARG_NONE, &version,
                0, "Print version information", NULL
            },

            {
                "copyright", '\0',
                POPT_ARG_NONE, &copyright,
                0, "Print copyright information and exit", NULL
            },

            POPT_AUTOHELP
            POPT_TABLEEND
        };

    setInitialFlags(&sf);

    context = poptGetContext(argv[0], argc, argv, options, POPT_CONTEXT_POSIXMEHARDER);
    if (!context)
    {
        mw_printf("Failed to get popt context\n");
        exit(EXIT_FAILURE);
    }

    if (argc < 2)
    {
        poptPrintUsage(context, stderr, 0);
        poptFreeContext(context);
        exit(EXIT_FAILURE);
    }

    argRead = mwReadArguments(context);
    if (argRead < 0)
    {
        poptFreeContext(context);
        freeSeparationFlags(&sf);
        exit(EXIT_FAILURE);
    }

    if (version)
    {
        printVersion(FALSE, sf.verbose);
    }

    if (copyright)
    {
        printCopyright();
    }

    if (version || copyright)
    {
        exit(EXIT_SUCCESS);
    }

    sf.setSeed = !!(argRead & SEED_ARGUMENT); /* Check if these flags were used */

    sf.do_separation = (sf.separation_outfile && strcmp(sf.separation_outfile, ""));
    if (sf.do_separation)
        prob_ok_init(sf.separationSeed, sf.setSeed);

    rest = poptGetArgs(context);
    sf.forwardedArgs = mwGetForwardedArguments(rest, &sf.nForwardedArgs);
    sf.numArgs = mwReadRestArgs(rest, sf.nForwardedArgs); /* Temporary */

    poptFreeContext(context);
    setDefaults(&sf);
    *sfOut = sf;

    return 0;
}
Esempio n. 2
0
/* Read the command line arguments, and do the inital parsing of the parameter file. */
static mwbool nbReadParameters(const int argc, const char* argv[], NBodyFlags* nbfOut)
{
    int argRead;
    poptContext context;
    const char** rest = NULL;   /* Leftover arguments */
    static int version = FALSE;
    static int copyright = FALSE;
    static NBodyFlags nbf = EMPTY_NBODY_FLAGS;
    static unsigned int numParams = 0, params = 0;

    /* FIXME: There's a small leak of the inputFile from use of
       poptGetNextOpt(). Some mailing list post suggestst that this
       is some kind of semi-intended bug to work around something or other */
    static const struct poptOption options[] =
    {
        {
            "input-file", 'f',
            POPT_ARG_STRING, &nbf.inputFile,
            0, "Input Lua file to read", NULL
        },

        {
            "histoout-file", 'z',
            POPT_ARG_STRING, &nbf.histoutFileName,
            0, "Output histogram file", NULL
        },

        {
            "histogram-file", 'h',
            POPT_ARG_STRING, &nbf.histogramFileName,
            0, "Histogram file", NULL
        },

        {
            "match-histogram", 's',
            POPT_ARG_STRING, &nbf.matchHistogram,
            0, "Only match this histogram against other histogram (requires histogram argument)", NULL
        },

        {
            "output-file", 'o',
            POPT_ARG_STRING, &nbf.outFileName,
            0, "Output file", NULL
        },

      #if 0
        {
            "binary-output", 'B',
            POPT_ARG_NONE, &nbf.outputBinary,
            0, "Write output dump as a binary", NULL
        },
      #endif

        {
            "output-cartesian", 'x',
            POPT_ARG_NONE, &nbf.outputCartesian,
            0, "Output Cartesian coordinates instead of lbR", NULL
        },

        {
            "timing", 't',
            POPT_ARG_NONE, &nbf.printTiming,
            0, "Print timing of actual run", NULL
        },

        {
            "verify-file", 'v',
            POPT_ARG_NONE, &nbf.verifyOnly,
            0, "Check that the input file is valid only; perform no calculation.", NULL
        },

        {
            "checkpoint", 'c',
            POPT_ARG_STRING, &nbf.checkpointFileName,
            0, "Checkpoint file to use", NULL
        },

        {
            "checkpoint-interval", 'w',
            POPT_ARG_INT, &nbf.checkpointPeriod,
            0, "Period (in seconds) to checkpoint. -1 to disable", NULL
        },

        {
            "gpu-disable-checkpointing", 'k',
            POPT_ARG_NONE, &nbf.disableGPUCheckpointing,
            0, "Disable checkpointing with GPUs" , NULL
        },

        {
            "debug-boinc", 'g',
            POPT_ARG_NONE, &nbf.debugBOINC,
            0, "Init BOINC with debugging. No effect if not built with BOINC_APPLICATION", NULL
        },

        {
            "lua-debug-libraries", 'a',
            POPT_ARG_NONE, &nbf.debugLuaLibs,
            0, "Load extra Lua libraries not normally allowed (e.g. io) ", NULL
        },

        {
            "visualizer", 'u',
            POPT_ARG_NONE, &nbf.visualizer,
            0, "Try to run N-body visualization", NULL
        },

        {
            "visualizer-args", '\0',
            POPT_ARG_STRING, &nbf.visArgs,
            0, "Command line to pass on to visualizer", NULL
        },

        {
            "visualizer-bin", '\0',
            POPT_ARG_STRING, &nbf.graphicsBin,
            0, "Path to visualize", NULL
        },

        {
            "ignore-checkpoint", 'i',
            POPT_ARG_NONE, &nbf.ignoreCheckpoint,
            0, "Ignore the checkpoint file", NULL
        },

        {
            "print-histogram", 'm',
            POPT_ARG_NONE, &nbf.printHistogram,
            0, "Print generated histogram to stderr", NULL
        },

        {
            "nthreads", 'n',
            POPT_ARG_INT, &nbf.numThreads,
            0, "BOINC argument for number of threads. No effect if built without OpenMP", NULL
        },

        {
            "p", 'p',
            POPT_ARG_NONE, &params,
            0, "Unused dummy argument to satisfy primitive arguments the server sends", NULL
        },

        {
            "np", '\0',
            POPT_ARG_INT | POPT_ARGFLAG_ONEDASH, &numParams,
            0, "Unused dummy argument to satisfy primitive arguments the server sends", NULL
        },

        {
            "seed", 'e',
            POPT_ARG_INT, &nbf.seed,
            SEED_ARGUMENT, "seed for PRNG", NULL
        },

        {
            "device", 'd',
            POPT_ARG_INT, &nbf.devNum,
            0, "OpenCL device number", NULL
        },

        {
            "platform", 'p',
            POPT_ARG_INT, &nbf.platform,
            0, "OpenCL platform", NULL
        },

        {
            "disable-opencl", '\0',
            POPT_ARG_NONE, &nbf.noCL,
            0, "Use normal CPU path instead of OpenCL. No effect if not built with OpenCL", NULL
        },

        {
            "non-responsive", 'r',
            POPT_ARG_NONE, &nbf.ignoreResponsive,
            0, "Do not care about display responsiveness (use with caution)", NULL
        },

        {
            "progress", 'P',
            POPT_ARG_NONE, &nbf.reportProgress,
            0, "Print verbose progress information, possibly with curses", NULL
        },

        {
            "no-clean-checkpoint", 'k',
            POPT_ARG_NONE, &nbf.noCleanCheckpoint,
            0, "Do not delete checkpoint on finish", NULL
        },

        {
            "verbose", '\0',
            POPT_ARG_NONE, &nbf.verbose,
            0, "Print some extra debugging information", NULL
        },

        {
            "version", 'v',
            POPT_ARG_NONE, &version,
            0, "Print version information", NULL
        },

        {
            "copyright", '\0',
            POPT_ARG_NONE, &copyright,
            0, "Print copyright information and exit", NULL
        },

        POPT_AUTOHELP
        POPT_TABLEEND
    };

    context = poptGetContext(argv[0], argc, argv, options, POPT_CONTEXT_POSIXMEHARDER);
    if (!context)
    {
        mw_printf("Failed to get popt context\n");
        exit(EXIT_FAILURE);
    }

    if (argc < 2)
    {
        poptPrintUsage(context, stderr, 0);
        poptFreeContext(context);
        return TRUE;
    }

    /* Check for invalid options, and must have the input file or a
     * checkpoint to resume from */
    argRead = mwReadArguments(context);
    if (argRead < 0)
    {
        mw_printf("Failed to read arguments\n");
        poptFreeContext(context);
        return TRUE;
    }

    if (version)
    {
        nbPrintVersion(FALSE, nbf.verbose);
    }

    if (copyright)
    {
        nbPrintCopyright();
    }

    if (version || copyright)
    {
        poptFreeContext(context);
        exit(EXIT_SUCCESS);
    }

    if (!nbf.inputFile && !nbf.checkpointFileName && !nbf.matchHistogram)
    {
        mw_printf("An input file, checkpoint, or matching histogram argument is required\n");
        poptFreeContext(context);
        return TRUE;
    }

    if (nbf.matchHistogram && !nbf.histogramFileName)
    {
        mw_printf("--match-histogram argument requires --histogram-file\n");
        poptFreeContext(context);
        return TRUE;
    }

    nbf.setSeed = !!(argRead & SEED_ARGUMENT);

    rest = poptGetArgs(context);
    if ((params || numParams) && !rest)
    {
        mw_printf("Expected arguments to follow, got 0\n");
    }
    else
    {
        nbSetForwardedArguments(&nbf, rest);
    }

    poptFreeContext(context);

    *nbfOut = nbf;

    return FALSE;
}
Esempio n. 3
0
/* Read the command line arguments, and do the inital parsing of the parameter file. */
static mwbool readParameters(const int argc, const char* argv[], NBodyFlags* nbf)
{
    int argRead;
    poptContext context;
    const char** rest = NULL;   /* Leftover arguments */
    mwbool failed = FALSE;

    unsigned int numParams = 0, params = 0;

    /* FIXME: There's a small leak of the inputFile from use of
       poptGetNextOpt(). Some mailing list post suggestst that this
       is some kind of semi-intended bug to work around something or other */
    const struct poptOption options[] =
    {
        {
            "input-file", 'f',
            POPT_ARG_STRING, &nbf->inputFile,
            0, "Input Lua file to read", NULL
        },

        {
            "histoout-file", 'z',
            POPT_ARG_STRING, &nbf->histoutFileName,
            0, "Output histogram file", NULL
        },

        {
            "histogram-file", 'h',
            POPT_ARG_STRING, &nbf->histogramFileName,
            0, "Histogram file", NULL
        },

        {
            "output-file", 'o',
            POPT_ARG_STRING, &nbf->outFileName,
            0, "Output file", NULL
        },

        {
            "output-cartesian", 'x',
            POPT_ARG_NONE, &nbf->outputCartesian,
            0, "Output Cartesian coordinates instead of lbR", NULL
        },

        {
            "timing", 't',
            POPT_ARG_NONE, &nbf->printTiming,
            0, "Print timing of actual run", NULL
        },

        {
            "verify-file", 'v',
            POPT_ARG_NONE, &nbf->verifyOnly,
            0, "Check that the input file is valid only; perform no calculation.", NULL
        },

        {
            "checkpoint", 'c',
            POPT_ARG_STRING, &nbf->checkpointFileName,
            0, "Checkpoint file to use", NULL
        },

        {
            "clean-checkpoint", 'k',
            POPT_ARG_NONE, &nbf->cleanCheckpoint,
            0, "Cleanup checkpoint after finishing run", NULL
        },

        {
            "checkpoint-interval", 'w',
            POPT_ARG_INT, &nbf->checkpointPeriod,
            0, "Period (in seconds) to checkpoint. -1 to disable", NULL
        },

        {
            "debug-boinc", 'g',
            POPT_ARG_NONE, &nbf->debugBOINC,
            0, "Init BOINC with debugging. No effect if not built with BOINC_APPLICATION", NULL
        },

        {
            "lua-debug-libraries", 'a',
            POPT_ARG_NONE, &nbf->debugLuaLibs,
            0, "Load extra Lua libraries not normally allowed (e.g. io) ", NULL
        },

        {
            "visualizer", 'u',
            POPT_ARG_NONE, &nbf->visualizer,
            0, "Try to run N-body visualization", NULL
        },

        {
            "visualizer-args", '\0',
            POPT_ARG_STRING, &nbf->visArgs,
            0, "Command line to pass on to visualizer", NULL
        },

        {
            "ignore-checkpoint", 'i',
            POPT_ARG_NONE, &nbf->ignoreCheckpoint,
            0, "Ignore the checkpoint file", NULL
        },

        {
            "print-bodies", 'b',
            POPT_ARG_NONE, &nbf->printBodies,
            0, "Print bodies", NULL
        },

        {
            "print-histogram", 'm',
            POPT_ARG_NONE, &nbf->printHistogram,
            0, "Print histogram", NULL
        },

      #ifdef _OPENMP
        {
            "nthreads", 'n',
            POPT_ARG_INT, &nbf->numThreads,
            0, "BOINC argument for number of threads", NULL
        },
      #endif /* _OPENMP */

        {
            "p", 'p',
            POPT_ARG_NONE, &params,
            0, "Unused dummy argument to satisfy primitive arguments the server sends", NULL
        },

        {
            "np", '\0',
            POPT_ARG_INT | POPT_ARGFLAG_ONEDASH, &numParams,
            0, "Unused dummy argument to satisfy primitive arguments the server sends", NULL
        },

        {
            "seed", 'e',
            POPT_ARG_INT, &nbf->setSeed,
            'e', "seed for PRNG", NULL
        },

        POPT_AUTOHELP
        POPT_TABLEEND
    };

    context = poptGetContext(argv[0], argc, argv, options, 0);

    if (argc < 2)
    {
        poptPrintUsage(context, stderr, 0);
        poptFreeContext(context);
        return TRUE;
    }

    /* Check for invalid options, and must have the input file or a
     * checkpoint to resume from */
    argRead = mwReadArguments(context);
    if (argRead < 0 || (!nbf->inputFile && !nbf->checkpointFileName))
    {
        poptPrintHelp(context, stderr, 0);
        failed = TRUE;
    }

    rest = poptGetArgs(context);
    if ((params || numParams) && !rest)
    {
        warn("Expected arguments to follow, got 0\n");
        failed = TRUE;
    }
    else
    {
        setForwardedArguments(nbf, rest);
    }

    poptFreeContext(context);

    return failed;
}