Search in sources :

Example 6 with Remote

use of gov.sandia.n2a.host.Remote in project n2a by frothga.

the class JobSTACS method run.

public void run() {
    localJobDir = Host.getJobDir(Host.getLocalResourceDir(), job);
    Path errPath = localJobDir.resolve("err");
    try {
        Backend.err.set(new PrintStream(new FileOutputStream(errPath.toFile(), true), false, "UTF-8"));
    } catch (Exception e) {
    }
    try {
        Files.createFile(localJobDir.resolve("started"));
        MNode model = NodeJob.getModel(job);
        env = Host.get(job);
        // remote or local
        Path resourceDir = env.getResourceDir();
        // Unlike localJobDir (which is created by MDir), this may not exist until we explicitly create it.
        jobDir = Host.getJobDir(resourceDir, job);
        // digestModel() might write to a remote file (params), so we need to ensure the dir exists first.
        Files.createDirectories(jobDir);
        digestedModel = new EquationSet(model);
        InternalBackend.digestModel(digestedModel);
        String duration = digestedModel.metadata.get("duration");
        if (!duration.isEmpty())
            job.set(duration, "duration");
        seed = model.getOrDefault(System.currentTimeMillis(), "$metadata", "seed");
        job.set(seed, "seed");
        int cores = 1;
        if (!(env instanceof Remote))
            cores = env.getProcessorTotal();
        cores = job.getOrDefault(cores, "host", "cores");
        int nodes = job.getOrDefault(1, "host", "nodes");
        processes = cores * nodes;
        generateConfigs();
        // The simulator could append to the same error file, so we need to close the file before submitting.
        PrintStream ps = Backend.err.get();
        if (ps != System.err) {
            ps.close();
            Backend.err.remove();
            job.set(Host.size(errPath), "errSize");
        }
        List<List<String>> commands = new ArrayList<List<String>>();
        List<String> charmrun = new ArrayList<String>();
        charmrun.add("charmrun");
        charmrun.add("+p" + processes);
        List<String> command = new ArrayList<String>(charmrun);
        command.add(env.config.getOrDefault("genet", "backend", "stacs", "genet"));
        command.add("config.yml");
        commands.add(command);
        command = new ArrayList<String>(charmrun);
        command.add(env.config.getOrDefault("stacs", "backend", "stacs", "stacs"));
        command.add("config.yml");
        commands.add(command);
        env.submitJob(job, true, commands);
    } catch (Exception e) {
        if (!(e instanceof AbortRun))
            e.printStackTrace(Backend.err.get());
        try {
            Files.copy(new ByteArrayInputStream("failure".getBytes("UTF-8")), localJobDir.resolve("finished"));
        } catch (Exception f) {
        }
    }
    // If an exception occurred, the error file will still be open.
    PrintStream ps = Backend.err.get();
    if (ps != System.err)
        ps.close();
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) EquationSet(gov.sandia.n2a.eqset.EquationSet) ArrayList(java.util.ArrayList) Remote(gov.sandia.n2a.host.Remote) MNode(gov.sandia.n2a.db.MNode) IOException(java.io.IOException) AbortRun(gov.sandia.n2a.plugins.extpoints.Backend.AbortRun) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Remote (gov.sandia.n2a.host.Remote)6 Host (gov.sandia.n2a.host.Host)5 MNode (gov.sandia.n2a.db.MNode)4 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 Backend (gov.sandia.n2a.plugins.extpoints.Backend)3 Date (java.util.Date)3 MDoc (gov.sandia.n2a.db.MDoc)2 NodeJob (gov.sandia.n2a.ui.jobs.NodeJob)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 TreePath (javax.swing.tree.TreePath)2 InternalBackend (gov.sandia.n2a.backend.internal.InternalBackend)1 EquationSet (gov.sandia.n2a.eqset.EquationSet)1 MPart (gov.sandia.n2a.eqset.MPart)1 Factory (gov.sandia.n2a.host.Host.Factory)1 FactoryRemote (gov.sandia.n2a.host.Host.FactoryRemote)1 UnitValue (gov.sandia.n2a.language.UnitValue)1 ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)1