Search in sources :

Example 1 with AbortRun

use of gov.sandia.n2a.plugins.extpoints.Backend.AbortRun in project n2a by frothga.

the class JobC method run.

public void run() {
    // assumes the MNode "job" is really an MDoc. In any case, the value of the node should point to a file on disk where it is stored in a directory just for it.
    jobDir = Paths.get(job.get()).getParent();
    try {
        Backend.err.set(new PrintStream(jobDir.resolve("err").toFile()));
    } catch (FileNotFoundException e) {
    }
    try {
        Files.createFile(jobDir.resolve("started"));
        HostSystem env = HostSystem.get(job.getOrDefault("$metadata", "host", "localhost"));
        Path resourceDir = Paths.get(AppData.properties.get("resourceDir"));
        gcc = Paths.get(AppData.state.getOrDefault("BackendC", "gcc", "g++"));
        runtimeDir = resourceDir.resolve("cruntime");
        runtime = runtimeDir.resolve("runtime.o");
        rebuildRuntime();
        model = new EquationSet(job);
        digestModel();
        model.determineDuration();
        String duration = model.getNamedValue("duration");
        if (!duration.isEmpty())
            job.set("$metadata", "duration", duration);
        model.setInit(0);
        System.out.println(model.dump(false));
        Path source = jobDir.resolve("model.cc");
        generateCode(source);
        String command = env.quotePath(build(source));
        // The C program will 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();
        }
        long pid = env.submitJob(job, command);
        job.set("$metadata", "pid", pid);
    } catch (AbortRun a) {
    } catch (Exception e) {
        e.printStackTrace(Backend.err.get());
    }
    // 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) FileNotFoundException(java.io.FileNotFoundException) HostSystem(gov.sandia.n2a.execenvs.HostSystem) AbortRun(gov.sandia.n2a.plugins.extpoints.Backend.AbortRun) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

EquationSet (gov.sandia.n2a.eqset.EquationSet)1 HostSystem (gov.sandia.n2a.execenvs.HostSystem)1 AbortRun (gov.sandia.n2a.plugins.extpoints.Backend.AbortRun)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintStream (java.io.PrintStream)1 Path (java.nio.file.Path)1