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();
}
Aggregations