Esempio n. 1
0
def run_pylith(appName, cfgfiles=[], dbClass=None, nprocs=1):
    """Helper function to generate spatial databases and run PyLith.
    """
    # Skip running if already run.
    if str(appName) in dir(run_pylith):
        return

    # Generate spatial databases if necessary.
    if not dbClass is None:
        db = dbClass()
        db.run()

    # Limit number of processes to number of local CPUs or maximum specified by environment.
    import os
    if "MAX_PYLITH_PROCS" in os.environ:
        appNumProcs = min(int(os.environ["MAX_PYLITH_PROCS"]), nprocs)
        if appNumProcs < nprocs:
            print(
                "WARNING: Detected environment with MAX_PYLITH_PROCS=%d. Reducing number of processes from %d to %d."
                % (appNumProcs, nprocs, appNumProcs))
    else:
        import pylith.utils.CollectVersionInfo
        import multiprocessing

        cpuCount = multiprocessing.cpu_count()
        mpiVersion = pylith.utils.CollectVersionInfo.CollectVersionInfo._collectVersionMPI(
        )
        if mpiVersion["implementation"] == "OpenMPI" and mpiVersion[
                "standard"].startswith("3"):
            cpuCount /= 2  # Assume hyperthreading is turned on and OpenMPI 3 doesn't allow oversubscribing

        appNumProcs = min(cpuCount, nprocs)
        if appNumProcs < nprocs:
            print(
                "WARNING: Detected %d CPUs. Reducing number of processes from %d to %d."
                % (appNumProcs, nprocs, appNumProcs))

    # Run Pylith
    app = PyLithApp()
    app.nodes = appNumProcs
    setattr(run_pylith, str(appName), True)
    app.run(argv=["pylith"] + cfgfiles)
    return
Esempio n. 2
0
    def _run_pylith(self, filename, arguments):
        """Run PyLith simulation using given arguments.

        Args:
            filename (str)
                Path to simulation parameter file.
            arguments (list of str)
                Command line arguments.
        """
        workdir = filename.parent
        cwd = os.getcwd()

        args = " ".join(arguments)
        if workdir.name:
            os.chdir(workdir)
            print(f"RUNNING {workdir} - pylith {args}...")
        else:
            print(f"RUNNING: pylith {args}...")

        app = PyLithApp()
        app.run(argv=["pylith"] + arguments)
        os.chdir(cwd)
Esempio n. 3
0
 def test_constructor(self):
     app = PyLithApp()