Parfor Loop & EnergyPlus Co-Simulation

4 views (last 30 days)
Hello everyone,
I'm trying to run a parfor loop to run the EnergyPlus toolbox co-simulation a bit faster (EnergyPlus Co-Simulation). I tried a lot but I'm getting an error that I'm unable to solve.
Below is my code:
ep=[];
tStart = tic;
i=0;
HVACEnergy = array2table(zeros(25,8));
Blg_Electricity = array2table(zeros(25,8));
Total_Energy = array2table(zeros(25,8));
parfor c=1:8
%%
t = getCurrentTask();
d = fullfile(tempdir, sprintf('worker_%d', t.ID));
if ~exist(d, 'dir'), mkdir(d); end
%%
ep = mlep;
ep.workDir = d;
% Building simulation file
ep.idfFile = 'C:\Users\mak19\Desktop\UBC_PhD\Trial_Two\6-Modeling\1-Trial_One\4-IHDX\DD_Winter_EE.idf';
% Weather file
ep.epwFile = 'C:\Users\mak19\Desktop\UBC_PhD\Trial_Two\6-Modeling\1-Trial_One\4-IHDX\CAN_BC_Kamloops.718870_CWEC.epw';
% Initialize
ep.initialize;
% Simulation length
endTime = 1*24*60*60; %[s]
% Logging
VN = ep.outputSigName;
VN{3} = 'HVAC_Energy';
VN{4} = 'Total_Building_Electricity';
VN{5} = 'Total_Electricity';
logTable = table('Size',[0, 1 + ep.nOut],...
'VariableTypes',repmat({'double'},1,1 + ep.nOut),...
'VariableNames',[{'Time'}; VN]);
% Start co-simulation
ep.start;
iLog = 1;
%%
% The simulation loop
t = 0;
while t < endTime
% Prepare inputs (possibly from last outputs)
u = [20 24 1 1 1 1 1 1 1];
% Get outputs from EnergyPlus
[y, t] = ep.read;
% Send inputs to EnergyPlus
ep.write(u,t);
% Log
logTable(iLog, :) = num2cell([t y(:)']);
iLog = iLog + 1;
i=i+1;
end
% Stop co-simulation process
%%
ep.stop;
%%
delete(ep)
%
HVACEnergy(:,c) = logTable(:,4);
Blg_Electricity(:,c)=logTable(:,5);
Total_Energy(:,c)=logTable(:,6);
end
TotalTime = toc(tStart);
And this is the error I'm getting:
Error using mlep/acceptSocket (line 1144)
Java exception occurred:
java.net.SocketTimeoutException: Accept timed out
at java.net.DualStackPlainSocketImpl.waitForNewConnection(Native Method)
at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:135)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
Error in mlep/start (line 289)
obj.acceptSocket;
Many thanks in advance.
Mohamad

Accepted Answer

Raymond Norris
Raymond Norris on 18 Jun 2021
I would suggest trying this first with a pool size of 1. If it works, then my guess is that mlep only allows one connection at a time.
  9 Comments
Mohamad Khalil
Mohamad Khalil on 20 Jun 2021
It seems it has something to do with the "socket.cfg"! Although I'm doing as the answer in this post: https://www.mathworks.com/matlabcentral/answers/443270-parfor-energyplus-co-simulation-toolbox, I'm still getting an error. Your support means a lot for me. Thanks.
Mohamad Khalil
Mohamad Khalil on 21 Jun 2021
Is it possible to copy the "mlep" function to the multiple workers in a way that each worker has its own "mlep" function?. I feel might be better rather than all of the workers are using the same "mlep", which might not be supporting the "parfor" loop? Thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!