Effacer les filtres
Effacer les filtres

Using parsim with SIMULINK model containing c-mex s-functions

10 vues (au cours des 30 derniers jours)
Fawad Farooq Ashraf
Fawad Farooq Ashraf le 3 Fév 2022
Commenté : Chintan le 19 Juil 2024 à 18:12
I have a simulation with multiple S-functions (level 2 written in c++). I want to run a Monte-Carlo analysis for my problem and to speed up the process, I want to run the simulations in parallel using the parsim command. There's a parameter for the S-functions "DX" which would be different for every simulation.
model = 'my_model';
load_system(model);
numSims = 10;
for i = 1:numSims
in(i) = Simulink.SimulationInput(model);
in(i) = in(i).setVariable('DX',my_data(:,i));
end
simOut = parsim(in);
According to my understanding, this should work but it gives me errors.
My c++ S-functions is supposed to load and read some DAT files in order to run and they are in a different folder. The path to access the files is written inside the code. I have added an exception in the code that it should give error "Data could not be loaded" in case the code fails to load and read the files. I get this error when I try to run the simulation using "parsim" command. However, it works fine using the "sim" command.
What could I be doing wrong here? Am I missing something? Any help would be highly appreciated.
  9 commentaires
Gabriel Geiger
Gabriel Geiger le 29 Mai 2024
Modifié(e) : Gabriel Geiger le 29 Mai 2024
Following up on this threat to see if OP has found anything on this topic. I'm running into a nearly identical issue. I've added the search paths to the parallel workers for the files the S-function tries to refer to, and no luck. I've also tried to use addAttachedFiles() to the parallel pool to add the files needed, but this also does not work. Any updates?
Chintan
Chintan le 19 Juil 2024 à 18:12
@Fawad Farooq Ashraf: we are facing a similar issue with using an FMU with dependencies in the parsim context. Were you able to resolve this issue?

Connectez-vous pour commenter.

Réponses (1)

Benjamin Thompson
Benjamin Thompson le 14 Fév 2022
Alternatively, you can read data from a binary file using fopen and fread in an M file in MATLAB. Read each dataset into the MATLAB workspace and use a Simulink foreach subsystem to pass data to the sin function in Simulink.
  1 commentaire
Fawad Farooq Ashraf
Fawad Farooq Ashraf le 14 Fév 2022
Like I mentioned that my actual simulation consists of a lot of files and doing this would be cumbersome. I do not want to change my validated code which is working perfectly with the sim command.

Connectez-vous pour commenter.

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by