6

My workplace use MATLAB and sub-products Simulink, Realtime workshop (RTW), RTW Embedded Coder. We have a large simulink model that is compiled to C then to an object file for loading onto the embedded target. The whole compilation process takes ~3h which is quite long, it's mostly the compilation and linking of the C files produced from the simulink model.

Removing one particular subsystem reduces the compilation time down to 30mins, and since this subsystem doesn't change very often I plan to code this in C and then into MEX and use the MEX file in the main model.

Will the technique reduce the compilation time? Is there another technique I should be looking into?

EDIT: I think the solution will be roughly: Generate C from the offending subsystem Compile this to some kind of object, library Include this in the model (but I'm not interested in simulation, it has inputs only) Include this in the build process, presumably linking after compiling the rest of the code

Craig
  • 890
  • 13
  • 27

2 Answers2

3

You could try to put the offending subsystem into another model and use Model Reference. You can convert a subsystem to a Model block using Simulink.SubSystem.convertToModelReference.

Model Reference has incremental code generation, so as long as the model doesn't change, Simulink won't regenerate or recompile the code for the referenced model.

MikeT
  • 1,624
  • 8
  • 11
  • this sounds very promising, just what I'm looking for in fact! I'll try it out next week. – Craig Aug 12 '11 at 15:50
0

I don't think what you suggest will reduce compilation time, since you seem to imply that the majority of the time is spent compiling the generated source files i.e. it is the C compiler that's slowing things down, not Simulink.

If you create a mex file (S-Function) from that subsystem your options are to either make an inlined S-Function or a non-inlined one. Unless the subsystem you're converting is fairly trivial (and I'm guessing it's not) you'll want to choose the former option, since the latter is severely limited. However, in both cases, your C compiler will still have compile source files. In the inlined case these will be source files spit out by the TLC you've written, and in the other it'll be the source files you compiled to created the S-Function itself.

A solution I can think of is to duplicate the functionality of the offending subsystem in C and use the embedded target's compiler to generate a static library. Also, create an inlined S-Function that mimics this subsystem in simulation. In the TLC file for this S-Function you would just ask Simulink to include the appropriate header file for the static library and then make function calls that reference the library. This saves the compiler from having to recompile the source during every model build.

You'll also need to figure out how to pass the linker a directive to link to the static library when building the model (assuming the code generation process automatically invokes the embedded compiler to build the code).

Praetorian
  • 100,267
  • 15
  • 224
  • 307
  • @P I was under the impression that using the mex in simulink would simply link an additional object and forego having to compile the C for it each time. I'm not interested in simulating this subsystem so that may simplify things. – Craig Aug 11 '11 at 07:43
  • @P Can you explain further about the inlined s-function? According the the help s-functions can be C, M, ada, fortran. I'm not seeing anything about libraries here. – Craig Aug 11 '11 at 07:58