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