运行 在并行模式下测试时如何解决冲突的 simulink 仿真加速 artificats 问题?

How to fix conflicting simulink simulation accelerated artificats issue when running test in parallel mode?

我的目标是优化 运行 一组模拟测试用例所需的时间。我在使用并行处理和加速模拟功能进行 运行ning 测试时遇到了问题。 https://www.mathworks.com/help/simulink/ug/how-the-acceleration-modes-work.html

上下文:

我有 29 个在参数化 Matlab 单元测试中调用的 Simulink 文件。 Simulink 文件有很多参考模型。在为每个 simulink 运行 进行 20 秒仿真之前,simulink 必须加载所有参考模型并在工作文件夹中创建大量仿真工件。许多参考模型在 simulink 项目之间共享。 simulink 项目有 64/187 参考模型,在加速模式下 运行。普通模式生成.mexw64,加速模式生成work文件夹下的.slxc和.mexw64

操作:

  1. 我运行1考一次。都是正常模式。 我的测试成功了
  2. 我运行29依次测试。都是正常模式。 我的测试成功了
  3. 我 运行 1 测试一次,然后我 运行 在正常模式下并行测试 29 clusters.All。我的测试成功了。 (**参见参考文献 #1)
  4. 我运行1测试一次,全部在加速器模式下。 我的测试成功了
  5. 我运行29依次测试。全部处于加速器模式。 我的测试成功了
  6. 我运行1测试一次,然后我运行并行集群测试29,都在加速器模式。我的测试失败

预期结果:

我希望我在 accelerator/parallel 模式下的模拟 运行ning 与 normal/parallel 模式具有相同的积极结果。但是:

  1. 我在使用共享资源时遇到 read/write/building 问题 parallel tread when I 运行 2 test in parallel.
  2. 当我尝试 运行 29 时,我的并行线程失败了 同时.

知道如何解决这个问题吗?

我在模拟和构建设置中尝试了不同的构建配置,我尝试减少加速目标的数量,并阅读在线资源。

错误:

#1

Building with 'Microsoft Visual C++ 2015 (C)'.
LINK : fatal error LNK1104: cannot open file 'D:\GIT\***\***\work\sim_artifacts\***_src_msf.mexw64'


NMAKE : fatal error U1077: 'C:\PROGRA~1\MATLAB\R2017b\bin\win64\mex.EXE' : return code '0xffffffff'
Stop.
The make command returned an error of 2
'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
operable program or batch file.

### Build procedure for model: '***_src' aborted due to an error.

#2

The client lost connection to worker 4. This might be due to network problems,
or the interactive communicating job might have errored.

参考:

  1. https://www.mathworks.com/help/simulink/gui/rebuild.html
  2. https://www.mathworks.com/help/simulink/ug/model-callbacks.html#
  3. https://www.mathworks.com/help/simulink/ug/reuse-simulation-builds-for-faster-simulations.html
  4. https://www.mathworks.com/help/matlab/ref/matlab.unittest.testrunner.runinparallel.html

我的问题是数据并发问题。 我找到了解决方案。

解法:

现在我运行在加速器模式下测试一次生成缓存文件夹(模拟目标和加速工件)。然后我将缓存文件夹复制了 29 次。然后我将每个文件夹分配给 1 个并行测试 运行 作为输入。因此,所有并行测试都在不同的文件夹中读取和写入,因此它们不再相互冲突。

参考:

  1. https://www.youtube.com/watch?v=cKK3qpBjixA
  2. https://www.mathworks.com/help/simulink/ug/model-reference-simulation-targets-1.html
  3. https://www.mathworks.com/help/simulink/ug/not-recommended-using-sim-function-within-parfor.html

you need to address any workspace access issues and data concurrency issues to produce useful results. Specifically, the simulations need to create separately named output files and workspace variables. Otherwise, each simulation overwrites the same workspace variables and files, or can have collisions trying to write variables and files simultaneously.

代码:

function setParCacheFolder()
%% get Simulink Files names
originalPath = path;
addpath(genpath('***\***\***\***')); 
file=getFileNames('FOOTEST_*.slx','***\***\***\***');
for i = 1:length(file)
    %% open/load simulink system
    [~,NAME,~]=fileparts(file(i));
    sys{i}=NAME;
    open_system(sys{i});
    %% copy Cache Folder
    copyfile(fullfile(pwd,'\***\work\sim_artifacts'), fullfile(pwd,strcat('\***\work\sim_artifacts',sys{i}{1})));
    %% get specific cache folder
    get_param(0, 'CacheFolder')
    %% set specific cache folder
    set_param(0, 'CacheFolder', fullfile(pwd,strcat('\***\work\sim_artifacts',sys{i}{1})));
    %% save simulink project
    save_system(sys{i}{1},[],'SaveDirtyReferencedModels','on','OverwriteIfChangedOnDisk',true);
    bdclose('all');
end
path(originalPath);
end