Parallel Simulation Error using parfor and parpool
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I try to perform a simulation using the parfor command. My Simulink file changes data every 0.04s up to 3.84s (96 times total). I try to make my simulation a bit faster using parfor and parpool using essentially a timestep of 0.04s. Yet an error, which I quite frankly cannot understand pops out. By the way the simulation without parallel works perfectly. This is the code I use:
% Define the time step and simulation end time
timeStep = 0.04; % Time step (in seconds)
endTime = 3.84; % End time (in seconds)
% Create a parallel pool if not already available
if isempty(gcp('nocreate'))
parpool; % Create a parallel pool
end
% Define a function for simulating the Simulink model for a given time range
simFunc = @(startTime, endTime) simulink_simulation(startTime, endTime);
% Perform parallel simulations
simTimes = 0:timeStep:endTime;
numSimulations = length(simTimes);
parfor i = 1:numSimulations
startTime = simTimes(i);
endTime = startTime + timeStep;
fprintf('Simulation %d: %.2f to %.2f seconds\n', i, startTime, endTime);
% Call the simulation function for the current time range
simFunc(startTime, endTime);
end
% Define the simulink_simulation function
function simulink_simulation(startTime, endTime)
% Load the Simulink model
model = 'zigzag_example_matlab';
load_system(model);
% Set the simulation time range
set_param(model, 'StartTime', num2str(startTime));
set_param(model, 'StopTime', num2str(endTime));
% Run the simulation
simOut = sim(model);
end
And this is the error that pops during simulation:
Simulation 2: 0.04 to 0.08 seconds
Simulation 6: 0.20 to 0.24 seconds
Simulation 8: 0.28 to 0.32 seconds
Simulation 4: 0.12 to 0.16 seconds
Warning: The file containing block diagram 'zigzag_example_matlab' has been changed on disk since it was loaded.
Warning: The file containing block diagram 'zigzag_example_matlab' has been changed on disk since it was loaded.
Warning: The file containing block diagram 'zigzag_example_matlab' has been changed on disk since it was loaded.
### Build procedure for zigzag_example_matlab aborted due to an error.
Build Summary
Top model rapid accelerator targets built:
Model Action Rebuild Reason
=================================================================================
zigzag_example_matlab Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Warning: The file containing block diagram 'zigzag_example_matlab' has been changed on disk since it was loaded.
### Build procedure for zigzag_example_matlab aborted due to an error.
Build Summary
Top model rapid accelerator targets built:
Model Action Rebuild Reason
=================================================================================
zigzag_example_matlab Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
### Build procedure for zigzag_example_matlab aborted due to an error.
Build Summary
Top model rapid accelerator targets built:
Model Action Rebuild Reason
=================================================================================
zigzag_example_matlab Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 16.512s
### Build procedure for zigzag_example_matlab aborted due to an error.
Build Summary
Top model rapid accelerator targets built:
Model Action Rebuild Reason
=================================================================================
zigzag_example_matlab Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Analyzing and transferring files to the workers ...done.
Simulation 8: 0.28 to 0.32 seconds
Simulation 6: 0.20 to 0.24 seconds
Warning: The file containing block diagram 'zigzag_example_matlab' has been changed on disk since it was loaded.
Simulation 4: 0.12 to 0.16 seconds
Simulation 2: 0.04 to 0.08 seconds
Warning: The file containing block diagram 'zigzag_example_matlab' has been changed on disk since it was loaded.
### Build procedure for zigzag_example_matlab aborted due to an error.
Build Summary
Top model rapid accelerator targets built:
Model Action Rebuild Reason
=================================================================================
zigzag_example_matlab Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Warning: The file containing block diagram 'zigzag_example_matlab' has been changed on disk since it was loaded.
Warning: The file containing block diagram 'zigzag_example_matlab' has been changed on disk since it was loaded.
### Build procedure for zigzag_example_matlab aborted due to an error.
Build Summary
Top model rapid accelerator targets built:
Model Action Rebuild Reason
=================================================================================
zigzag_example_matlab Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
### Build procedure for zigzag_example_matlab aborted due to an error.
Build Summary
Top model rapid accelerator targets built:
Model Action Rebuild Reason
=================================================================================
zigzag_example_matlab Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 3.7802s
### Build procedure for zigzag_example_matlab aborted due to an error.
Build Summary
Top model rapid accelerator targets built:
Model Action Rebuild Reason
=================================================================================
zigzag_example_matlab Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 3.7551s
Build duration: 0h 0m 3.8837s
Build duration: 0h 0m 3.886s
Error using Parallel_Simulation_Script>simulink_simulation
Unable to build a standalone executable to simulate the model 'zigzag_example_matlab' in rapid accelerator mode.
Error in Parallel_Simulation_Script>@(startTime,endTime)simulink_simulation(startTime,endTime) (line 11)
simFunc = @(startTime, endTime) simulink_simulation(startTime, endTime);
Error in Parallel_Simulation_Script (line 17)
parfor i = 1:numSimulations
Caused by:
Error using Parallel_Simulation_Script>simulink_simulation
Error due to multiple causes.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/Branch1' for parameter 'SampleTime'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'SampleTime' in 'zigzag_example_matlab/Branch1'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'time'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'time' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/Branch2' for parameter 'SampleTime'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'SampleTime' in 'zigzag_example_matlab/Branch2'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'time'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'time' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/Branch3' for parameter 'SampleTime'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'SampleTime' in 'zigzag_example_matlab/Branch3'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'time'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'time' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/Branch4' for parameter 'SampleTime'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'SampleTime' in 'zigzag_example_matlab/Branch4'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'time'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'time' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/Branch5' for parameter 'SampleTime'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'SampleTime' in 'zigzag_example_matlab/Branch5'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'time'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'time' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'SR888700131'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'SR888700131' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace1' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace1'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'SA888700131'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'SA888700131' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace10' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace10'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'R888700022'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'R888700022' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace11' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace11'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'Load888700022'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'Load888700022' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace2' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace2'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'R888700021'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'R888700021' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace3' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace3'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'Load888700021'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'Load888700021' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace4' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace4'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'R888700024'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'R888700024' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace5' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace5'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'Load888700024'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'Load888700024' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace6' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace6'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'R888700103'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'R888700103' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace7' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace7'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'Load888700103'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'Load888700103' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace8' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace8'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'R888700026'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'R888700026' has been deleted from base workspace.
Error using Parallel_Simulation_Script>simulink_simulation
Invalid setting in 'zigzag_example_matlab/From Workspace9' for parameter 'VariableName'.
Error using Parallel_Simulation_Script>simulink_simulation
Error evaluating parameter 'VariableName' in 'zigzag_example_matlab/From Workspace9'
Error using Parallel_Simulation_Script>simulink_simulation
Unrecognized function or variable 'Load888700026'.
Error using Parallel_Simulation_Script>simulink_simulation
Variable 'Load888700026' has been deleted from base workspace.
Does anyone have any idea what I need to do in order to fix it?
0 个评论
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!