Rapid accelerator simulation multiple times

7 次查看(过去 30 天)
I am simulating very large dataset.
The model itself is small but the dataset is large. So, the model will be simulated for million times. It would increase if i reduce the simulation frequency which i would need to do later.
I am already using rapid accelerator mode with RapidAcceleratorUpToDateCheck to off.
But the execution is still slower because of the large dataset. I can try to run on multiple matlab instances as i can see the CPU is not used much, unfortunately i cannot use the parallel computing toolbox.
I would like to focus on the below part and maybe i am thinking this can be improved.
The dataset has chunk of groups. My final goal is to have the results for each group.
Currently the setup is as below.
  1. In main matlab script find group of chunk in dataset and call another matlab function.
  2. In 2nd matlab function, create arrays to hold output data for all datas in the group dataset, iterate through this group of data.
  3. Create the timeseries inputs for the feed in the simulink model.(only for the 1 data in dataset)
  4. The timeseries inputs are calculated based on the current 1 data and the previous output of the simulink model.
  5. Set the timeseries in SimIn and then call the sim command with rapid accelerator.
  6. Get the output results and assign it in the arrays created in point 2.
  7. Once the iterations are complete return to point 1 and save the output results in .mat file for analyzing later.
I think the point 5 & 6 are more time consuming and should be optimizied. So, i want to move the step 4 in the simulink model only as an m-function(closed loop). As a result, the point 3 would now have timeseries for all the datas in the group dataset and there would be only one call to the sim command and get all the result back.
But this work might be time consuming because step 3 is complicated and maynot be able to easily replicate in the simulink model. So, before restructring want to know whether there would be any performance improvement ?
I cannot optimize point 7 for storing data into .mat because many times due to working on other stuff matlab crashes and then loose all the results. Also, want to see output of in real time to stop if something very wrong happening on the simulation.

采纳的回答

vivek patel
vivek patel 2025-3-27
Answering the question for future references.
I did the optimization of point 5&6 and it improved the execution time very highly. Previously it was around 5-6 hours but now just 15mins.
I knew that simulink does some optimizations for running the timeseries data input but was not aware that it can reduce the time this much.
There can be below three points which improved the execution time.
  1. Previouls simulink rapid accelerator launched multiple times, so overhead of that is now reduced as only one launch.
  2. The data sharing between the m script and the simulink rapid accelerator is time consuming. Previously many outputs from the simulink output where queried.
  3. The time of copying the data is reduced. Previously the output of the simulink was copied into one big array for consolidating the outputs. Now instead the input timeseries is created into one big array.
  4. I reduced the amount of signals logged at the end of simulation, would add them later so will get to know if that is the issue.
  5. Moved from matlab 2020b to 2022b.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Manual Performance Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by