use of gov.sandia.n2a.execenvs.HostSystem in project n2a by frothga.
the class PanelRun method delete.
public void delete() {
TreePath[] paths = tree.getSelectionPaths();
if (paths.length < 1)
return;
boolean nextSelectionIsParent = false;
NodeBase firstSelection = (NodeBase) paths[0].getLastPathComponent();
NodeBase lastSelection = (NodeBase) paths[paths.length - 1].getLastPathComponent();
NodeBase nextSelection = (NodeBase) lastSelection.getNextSibling();
if (nextSelection == null)
nextSelection = (NodeBase) firstSelection.getPreviousSibling();
if (nextSelection == null) {
nextSelection = (NodeBase) firstSelection.getParent();
nextSelectionIsParent = true;
}
for (TreePath path : paths) {
final NodeBase node = (NodeBase) path.getLastPathComponent();
model.removeNodeFromParent(node);
if (displayNode == node) {
synchronized (displayText) {
displayText.setText("");
}
if (displayPane.getViewport().getView() != displayText)
displayPane.setViewportView(displayText);
}
new Thread("PanelRun Delete") {
public void run() {
if (node instanceof NodeJob) {
NodeJob job = (NodeJob) node;
synchronized (running) {
running.remove(job);
}
MDoc doc = (MDoc) job.source;
HostSystem env = HostSystem.get(doc.getOrDefault("$metadata", "host", "localhost"));
String jobName = doc.key();
try {
if (job.complete < 1)
job.stop();
env.deleteJob(jobName);
} catch (Exception e) {
}
doc.delete();
} else if (node instanceof NodeFile) {
((NodeFile) node).path.delete();
}
}
}.start();
}
if (nextSelectionIsParent) {
if (nextSelection.getChildCount() > 0)
tree.setSelectionPath(new TreePath(((NodeBase) nextSelection.getChildAt(0)).getPath()));
else if (nextSelection != root)
tree.setSelectionPath(new TreePath(nextSelection.getPath()));
} else {
tree.setSelectionPath(new TreePath(nextSelection.getPath()));
}
tree.paintImmediately(treePane.getViewport().getViewRect());
}
use of gov.sandia.n2a.execenvs.HostSystem in project n2a by frothga.
the class UIController method prepareAndSubmitRunEnsemble.
public boolean prepareAndSubmitRunEnsemble(Component parentComponent, MNode model) throws Exception {
// Set up simulators.
List<ExtensionPoint> simEP = PluginManager.getExtensionsForPoint(Backend.class);
Backend[] simulators = new Backend[simEP.size()];
int s = 0;
for (ExtensionPoint ep : simEP) {
simulators[s++] = (Backend) ep;
}
// Set up execution environments.
// Hack to suppress errors in this outdated code.
HostSystem[] envs = new HostSystem[0];
// TODO: Fix this with appropriate interfaces.
String name = (String) ReflectionUtil.invoke("getName", model);
String owner = (String) ReflectionUtil.invoke("getOwner", model);
CreateRunEnsembleDialog dlg = new CreateRunEnsembleDialog((JFrame) SwingUtilities.getRoot(parentComponent), // TODO change from -1
-1, /*TEMP*/
name, owner, 12342347483L, /*TEMP until appropriate interfaces*/
model, simulators, simulators[0], envs, HostSystem.get("localhost"), false);
dlg.setVisible(true);
if (dlg.getResult() == CreateRunEnsembleDialog.CREATE) {
String label = dlg.getLabel();
HostSystem env = dlg.getEnvironment();
Backend simulator = dlg.getSimulator();
ParameterSpecGroupSet groups = dlg.getParameterSpecGroupSet();
ParameterSpecGroupSet simHandledGroups;
try {
// next line modifies groups to remove any that the Simulator will handle
simHandledGroups = divideEnsembleParams(model, groups, simulator);
} catch (RuntimeException e) {
Dialogs.showDetails(MainFrame.instance, "could not create run ensemble", e);
return false;
}
List<String> outputExpressions = dlg.getSelectedOutputExpressions();
/*
int runNum = 0;
for(ParameterSet set : groups.generateAllSetsFromSpecs(false)) {
ParameterSet modelParamSet = set.subset("Model");
ParameterSet simParamSet = set.subset("Simulator");
modelParamSet.sliceKeyPathKeys();
simParamSet.sliceKeyPathKeys();
Run run = model.addRun(modelParamSet, re);
re.addRun(run);
Simulation simulation = simulator.createSimulation();
ParameterDomain domain = new ParameterDomain(simParamSet);
simulation.setSelectedParameters(domain);
try {
RunState runState;
logger.debug(System.currentTimeMillis() + " before execute for run " +
runNum++);
// quick and dirty attempt at batch script version of doing ensemble
runState = simulation.prepare(run, simHandledGroups, env);
// runState = simulation.execute(run, simHandledGroups, env);
run.setState(XStreamWrapper.writeToString(runState));
run.save();
} catch(Exception e1) {
UMF.handleUnexpectedError(null, e1, "Could not create the run. An error occurred.");
return false;
}
}
env.submitBatch(re);
*/
return true;
}
return false;
}
use of gov.sandia.n2a.execenvs.HostSystem in project n2a by frothga.
the class XyceBackend method canRunNow.
@Override
public boolean canRunNow(MNode job) {
HostSystem execEnv = HostSystem.get(job.getOrDefault("$metadata", "host", "localhost"));
// if not, assume we have space for one
try {
Set<Long> procs = execEnv.getActiveProcs();
int numRunning = procs.size();
if (numRunning == 0) {
System.out.println("resourcesAvailable: numRunning=0");
return true;
}
// check CPU usage
// assume n2a processes are responsible for all current load;
// evaluate whether there's room for another process of size load/numRunning
System.out.println("num procs: " + numRunning);
double cpuLoad = execEnv.getProcessorLoad();
int cpuTotal = execEnv.getProcessorTotal();
double cpuPerProc = cpuLoad / numRunning;
boolean cpuAvailable = (cpuTotal - cpuLoad) > cpuPerProc;
System.out.println("cpuLoad: " + cpuLoad + "; cpuPerProc: " + cpuPerProc + "; cpuAvailable: " + cpuAvailable);
// Memory estimates using approach above thrown off by N2A using a lot of memory
// Instead, ask system for memory usage per proc
// TODO - use this approach for CPU usage also?
long maxMem = -1;
for (Long procNum : procs) {
long procMem = execEnv.getProcMem(procNum);
if (procMem > maxMem) {
maxMem = procMem;
}
}
long memLoad = execEnv.getMemoryPhysicalTotal() - execEnv.getMemoryPhysicalFree();
double memPerProc;
if (maxMem > 0) {
System.out.println("using individual process memory estimate");
memPerProc = maxMem;
} else {
System.out.println("processor memory usage negative; using memLoad/numRunning");
memPerProc = memLoad / numRunning;
}
boolean memAvailable = execEnv.getMemoryPhysicalFree() > memPerProc;
System.out.println("memLoad: " + memLoad + "; memPerProc: " + memPerProc + "; memAvailable: " + memAvailable);
return memAvailable && cpuAvailable;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
Aggregations