Main Content

Create a Function for Checking Multiple Systems in Parallel

Checking multiple systems in parallel reduces the processing time required by the Model Advisor to check multiple systems. If you have the Parallel Computing Toolbox™ license, you can check multiple systems in parallel on a multicore host machine.

The Parallel Computing Toolbox does not support 32-bit Windows® machines.

Each parallel process runs checks on one model at a time. In parallel mode, load the model data from the model workspace or data dictionary. The Model Advisor in parallel mode does not support model data in the base workspace.

Copy the Model and Configuration File to Your Current Directory

Copy the custom Model Advisor configuration file demoConfiguration.json, to your writeable directory.

  1. In MATLAB, set your current folder to a writeable directory.

  2. Enter this command in the MATLAB command prompt. MATLAB copies the file to your writeable directory.

    copyfile(fullfile(matlabroot,'examples','slcheck','main','prepare_cust_chk_code.m'),...'prepare_cust_chk_code.m','f');
    run('prepare_cust_chk_code.m');
  3. In the example files, notice demoConfiguration.json. This file defines the Model Advisor checks that are executed during the analysis. For more information about creating a custom configuration file, see Use the Model Advisor Configuration Editor to Create a Custom Model Advisor Configuration.

Define the Function to Programmatically Run Checks

  1. In the MATLAB® window, select New > Function.

  2. Save the file as run_fast_configuration.m.

  3. In the function, right-click on untitled and select Replace function name by file name. The function name is updated to run_fast_configuration

    function [outputArg1, outputArg2] = run_fast_configuration(inputArg1,inputArg2)
  4. Define the output and input arguments. For the output arguments, press Shift-Enter after entering each value to automatically update all instances in the function.

    • output_Arg1 as fail

    • output_Arg2 as warn

    • inputArg1, inputArg2 to SysList

    function [fail, warn] = run_fast_configuration(SysList)
    fail = inputArg1;
    warn = inputArg2;
    

  5. Inside the function, specify the Model Advisor configuration file and the system against which the analysis is ran:

    SysList={SysList={'AdvisorCustomizationExample/Amplifier',...
        'sldemo_auto_climatecontrol/Heater Control','rtwdemo_iec61508'};
    fileName = 'demoConfiguration.json';
    

  6. Call the ModelAdvisor.run function and set 'ParallelMode' to 'On'.

    SysResultObjArray = ModelAdvisor.run(SysList,'Configuration',fileName,...
        'ParallelMode','On');

  7. Determine the number of checks that return warnings and failures:

    fail = 0;
    warn = 0;
    
    for i=1:length(SysResultObjArray)
        fail = fail + SysResultObjArray{i}.numFail;
        warn = warn + SysResultObjArray{i}.numWarn;
    

    The function should now look like this:

    function [fail, warn] = run_fast_configuration(SysList)
    
    %RUN_FAST_CONFIGURATION Check systems in parallel with Model Advisor
    %   Return number of warnings and failures.
    
    SysList={'AdvisorCustomizationExample/Amplifier',...
        'sldemo_auto_climatecontrol/Heater Control','rtwdemo_iec61508'};
    fileName = 'demoConfiguration.json';
    
    % Run the Model Advisor.
    SysResultObjArray = ModelAdvisor.run(SysList,'Configuration',fileName,...
        'ParallelMode','On');
    fail = 0;
    warn = 0;
    
    for i=1:length(SysResultObjArray)
        fail = fail + SysResultObjArray{i}.numFail;
        warn = warn + SysResultObjArray{i}.numWarn;
    end
    
    
    
    

  8. Save the function.

  9. Test the function. In the MATLAB Command Window, run run_fast_configuration.

  10. Review the results. Click the Summary Report link to open the Model Advisor Command-Line Summary report.

See Also

|

Related Topics