MATLAB Answers

Using parfor and external program via network

1 view (last 30 days)
J B on 24 Feb 2021
Answered: Raymond Norris on 24 Feb 2021
I'm using a simulation program (it's called "Gecko Circuits") to carry out a large number of simulations in loop. The program is running on java and is accessed via a network port. The steps I have to carry out are the following:
javaaddpath 'Some\path\on\the\machine\GeckoCIRCUITS.jar';
startGui(PortNumber); % After this line, the GUI of the program opens
openFile([SimFolder, SimFile, '.ipes']); % This loads the simulation file
for j=1:100
for k=1:1000
connectToGecko(PortNumber); % Functions from the gecko package
setParameter(Some, Arguments);
% Read back results and store them
res(j,k) = ...
This is working fine so far, however, it takes too long to carry out all the calculations in the loop. Therefore, I'd like parallel this (and run it locally on a server which provides suitable resources). To achieve this, I tried this:
javaaddpath 'Some\path\on\the\machine\GeckoCIRCUITS.jar';
jMax = 100
GeckoAddr = 43035 + (0:1:(jMax-1));
for j=1:jMax
openFile([SimFolder, SimFile, '.ipes']);
for j=1:100
parfor k=1:1000
gecko.GeckoRemote.setParameter(Some, Arguments);
% Read back results and store them
res(j,k) = ...
The parfor loop causes a lot of troubles now. First I had a long time to find out, that the inside the parfor loops, the functions of the gecko package are not known anymore (the "import('gecko.GeckoRemote')" statement was apparently without effect inside the parfor loop). For this reason I had to put "gecko.GeckoRemote." in front of all the instructions. This is not really an issue, I just don't get the reason behind it.
The much bigger problem seems to be, that the different instances of the parfor loop mess up each other because while one instance is accessing Gecko at one port, another instance connects to another port, disconnecting the former instance of Gecko and mixing up data and commands of different simulations.
Unfortunately I don't no a lot neither about java nor about network ports. Is there any way how I can avoid this and make Matlab access several Gecko instances in parallel without them interfering?

Answers (1)

Raymond Norris
Raymond Norris on 24 Feb 2021
The problem is that GeckoCIRCUITS must not allow for multiple running instances. I glanced through their doc, but don't see any mention of it. However, when I read through GeckMAGNETICS, it states
Note that only one connection is allowed at a time.
It's a bit of a reach, but I'm guessing the same applys to GeckoGIRCUITS.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by