Hi experts,
Disclaimer: I am just a Java developer and have no knowledge of Modelling and Simulations so forgive me if I ask dumb questions or do not understand what is being said about simulations.
I have this requirement where our Data Scientist designs a JaamSim model and this model is then used to run simulations in optimiser. The config file of a given model is used as a base config for all the runs. The simulations will be run for millions of records individually by changing the inputs accordingly. So I am looking at running them in parallel in multi threaded processes. Thanks to the new API released recently I have managed to run simulations in same JVM process. But when I try to run them in parallel I get following exception.
Unfortunately I cannot provide the model config file as it is proprietary work. I will try to reproduce this error with example files in your project.
com.jaamsim.events.ProcessError: Tried to schedule using an EventHandle already in use
at com.jaamsim.events.EventManager.scheduleTicks(EventManager.java:820)
at com.jaamsim.events.EventManager.scheduleTicks(EventManager.java:791)
at com.jaamsim.ProcessFlow.Device.startStep(Device.java:141)
at com.jaamsim.ProcessFlow.Device.restart(Device.java:65)
at com.jaamsim.ProcessFlow.Device.thresholdChanged(Device.java:379)
at com.jaamsim.Thresholds.Threshold$ThresholdChangedTarget.process(Threshold.java:134)
at com.jaamsim.events.EventManager.executeTarget(EventManager.java:172)
at com.jaamsim.events.EventManager.execute(EventManager.java:256)
at com.jaamsim.events.Process.run(Process.java:101)
I am running simulations using following code in multiple threads, some statements are removed for brevity
private void runTest(String item) throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
JaamSimModel sim = new JaamSimModel("test-" + item);
sim.autoLoad();
InputAgent.readResource(sim, "./test.cfg");
sim.setInput("Simulation", "PrintReport", "FALSE");
//Set some input for the run
EventTimeListener listener = new EventTimeListener() {
@Override
public void tickUpdate(long tick) {
}
@Override
public void timeRunning() {
if (EventManager.current().isRunning()) {
return;
}
countDownLatch.countDown();
}
@Override
public void handleError(Throwable t) {
log.error(t.getMessage(), t);
countDownLatch.countDown();
}
};
sim.setTimeListener(listener);
sim.start();
countDownLatch.await();
}I have encountered following other issues regarding running simulations in same JVM:
Thanks
Vikas
Resource1: Insufficient resource units: available=5, req'd=1
com.jaamsim.basicsim.ErrorException: Resource1: Insufficient resource units: available=5, req'd=1 at com.jaamsim.basicsim.Entity.error(Entity.java:613) ~[JaamSim.jar:na] at com.jaamsim.resourceObjects.Resource.seize(Resource.java:129) ~[JaamSim.jar:na] at com.jaamsim.ProcessFlow.Seize.seizeResources(Seize.java:221) ~[JaamSim.jar:na] at com.jaamsim.ProcessFlow.Seize.startNextEntity(Seize.java:155) ~[JaamSim.jar:na] at com.jaamsim.resourceObjects.AbstractResourceProvider.notifyResourceUsers(AbstractResourceProvider.java:132) ~[JaamSim.jar:na] at com.jaamsim.ProcessFlow.Seize.thresholdChanged(Seize.java:105) ~[JaamSim.jar:na] at com.jaamsim.Thresholds.Threshold$ThresholdChangedTarget.process(Threshold.java:134) ~[JaamSim.jar:na] at com.jaamsim.events.EventManager.executeTarget(EventManager.java:172) [JaamSim.jar:na] at com.jaamsim.events.EventManager.execute(EventManager.java:256) [JaamSim.jar:na] at com.jaamsim.events.Process.run(Process.java:101) [JaamSim.jar:na]
import com.jaamsim.basicsim.JaamSimModel;
import com.jaamsim.events.EventManager;
import com.jaamsim.events.EventTimeListener;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class JaamSimSimulator {
public static void main(String[] args) throws URISyntaxException, InterruptedException {
final JaamSimModel sim = new JaamSimModel("test");
// Load the autoload file
sim.autoLoad();
sim.configure(Paths.get("./test.cfg").toFile());
CountDownLatch countDownLatch = new CountDownLatch(1);
//Set some input for the run
EventTimeListener listener = new EventTimeListener() {
@Override
public void tickUpdate(long tick) {
}
@Override
public void timeRunning() {
if (EventManager.current().isRunning()) {
return;
}
countDownLatch.countDown();
}
@Override
public void handleError(Throwable t) {
System.out.println("Simulation Failed:");
t.printStackTrace();
countDownLatch.countDown();
}
};
sim.setTimeListener(listener);
sim.start();
boolean successful = countDownLatch.await(10, TimeUnit.MINUTES);
if (successful) {
System.out.println("Simulation finished successfully.");
} else {
System.out.println("TIMEOUT: simulation timed out");
}
}
}
--
You received this message because you are subscribed to the Google Groups "Jaamsim Users Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jaamsim-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/jaamsim-users/4d98ff26-98ef-4c1d-b7a7-5454ddbaaa9f%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jaamsi...@googlegroups.com.
I have this problem where when I use JaamSimModel.configure method to load the config file, it tries to create, delete the log file with the same name and the process fails as there are multiple threads trying to work on the same log file. So to get myself up and running I added apiMode flag to JaamSimModel which does not create and open log file.
Also GUIFrame and DisplayModel classes need GUI toolkit which spawns GUI thread and that is stopping the main process to be shutdown gracefully.
i) Does the multithreading you're talking about mean two JaamSim models working together and running on different machines? If so, how do you deal with time coordination/synchronisation?ii) How does the API ("unit test 'testAPI' in com.jaamsim.basicsim") help in this process?iii) Could this API be used to interface JaamSim code with a Java external application-specific code?
i) Does the multithreading you're talking about mean two JaamSim models working together and running on different machines? If so, how do you deal with time coordination/synchronisation?
ii) How does the API ("unit test 'testAPI' in com.jaamsim.basicsim") help in this process?
iii) Could this API be used to interface JaamSim code with a Java external application-specific code?