// execute the garbage collector
System.gc();
try {
println("Memory (): " + Runtime.getRuntime().totalMemory() + " : "
+ Runtime.getRuntime().freeMemory());
StopWatch sw = new StopWatch();
sw.start();
IModel model = createModel();
sw.stop();
result.modelCreation = sw.elapsedSeconds();
println("Seconds needed for creating the model: " + sw.elapsedSeconds());
println("Memory (model - [total:free]): "
+ Runtime.getRuntime().totalMemory() + " : "
+ Runtime.getRuntime().freeMemory());
println("Simulation started at "
+ new SimpleDateFormat().format(new Date()));
ISimulationRun simulation = null;
sw.reset();
sw.start();
if (parameters.useMasterServer()) {
// TODO master server deactivated, January, 2009 - model should be
// created on the exec. host, not here!
// System.out.println("The simulation will be executed on the server: "
// + parameters.getMasterServerName());
// simulation = parameters.getMasterServer().createSimulation(
// model,
// new SimulationConfiguration(1, null, null, parameters
// .getParameterBlock())).getSimulation();
} else { // if we don't use a server we create a simulation on our own
TaskConfiguration config =
new TaskConfiguration(1, null, null, parameters.getParameterBlock());
SimulationRunConfiguration srConfig =
(SimulationRunConfiguration) config
.newComputationTaskConfiguration(new ComputationTaskIDObject());
simulation = new SimulationRun("SimRun", model, srConfig, null);
}
if (simulation == null) {
SimSystem.report(Level.SEVERE, "Simulation creation failed!!!");
}
sw.stop();
result.simulationCreation = sw.elapsedSeconds();
println("Seconds needed for creating the simulation: "
+ sw.elapsedSeconds());
println("Memory (model + simulation - [total:free]): "
+ Runtime.getRuntime().totalMemory() + " : "
+ Runtime.getRuntime().freeMemory());
sw.reset();
sw.start();
if (parameters.useMasterServer()) {
int tries = 0;
boolean retry = true;
while (retry) {
retry = false;
try {
parameters.getMasterServer().execute(
simulation.getUniqueIdentifier(), null);
} catch (Exception e) {
SimSystem.report(Level.SEVERE,
"Error occured while trying to launch the model on the server");
tries++;
if (tries == 3) {
SimSystem.report(Level.SEVERE,
" - stop retrying ... something seems to be wrong with the server "
+ parameters.getMasterServerName());
throw e; // rethrow exception
}
retry = true;
SimSystem.report(Level.INFO,
" - now retrying ... waiting some seconds ...");
// parameters.findServer(name); refind the server????
Thread.sleep(2000); // wait two seconds
SimSystem.report(Level.INFO,
" resetting stopwatch ... restarting simulation ...");
sw.reset();
sw.start();
}
}
} else { // if we don't use a server we create a simlation on our own
simulation.start();
}
sw.stop();
result.simulationRun = sw.elapsedSeconds();
println("Seconds needed for running the simulation: "
+ sw.elapsedSeconds());
// simulation.stop();
} catch (Exception e) {
SimSystem.report(e);
throw new RuntimeException(e.getMessage(), e);
}