Showing results for 
Search instead for 
Did you mean: 

Multi-Tasking CoSimulation

Hi there,

I am pretty new to TBB or any threading libraries, so forgive me if my question might seem quite naive to you guys. I am currently developing a model based co-simulation platform. Basically, I want to run all of the models concurrently in order to minimize run time.

Here's my idea,

1) I wrap each model with my own C++ API, and then export them as dynamic linked libraries. e.g. M1.dll, M2.dll. Each dll has the same set of API functions. e.g. Initialize(), DoStep(), Terminate() etc.

2) I then load these dlls into my CoSim platform during run time.

3) I push each model object into a vector collection, e.g. std::vector<Model> models = {M1, M2};

4) When I run a simulation with several models, the platform will call several functions, e.g. M1.DoStep(), M2.DoStep() at a very high frequency(1000 times per second).

Here're my questions,

1) Is it worthwhile to call those DoStep() functions concurrently if the size of vector<Model> is pretty small (less than 10)? Keep in mind that these do step functions are called at every millisecond. 

2) If it's worth it, then should I use parallel_for? parallel_invoke? parallel_for_each? From the manual, it seems that I should used parallel_invoke, but this method seems that I need to know the size of the methods in advance. This vector<Model> is of course dynamic, so I guess should I use parallel_for or creating my own tasks? 

3) Currently, I could not think of a way to handle load balance due to how people develop their models, e.g. M1 might be quite math heavy, but M2 might just be a simple light weight calculation. Is there a way to handle this condition? 

Thanks ahead for your answers, any comments on this topic are welcomed as well. 

Contact me if you want to have further discussions: yuhang.code at gmail dot com









0 Kudos
1 Reply
Black Belt

Is each model completely independent? (other than read only data)

Do all models need to be kept in phase?

Is each model run with serial or with parallel code, and if parallel which paradigm?

Will new models arrive while processing earlier models?

Do all models run the same number of steps?

Jim Dempsey