I'm using Matlab coder for generating c++ code.
I see that Matlab uses an internal Matlab libraries (dlls and libs) like:
Which is any library in the following format:
Due to an overall system performance, I'd like not to use the tbb libraries of Matlab - How can I generate code that does that ? (Please consider that package command shall pack all the non tbb libraries)
I also searched on Matlab installation folder and found that for every tbb library there is a matching non tbb library.
Ashish Uthama suggestion:
start matlab with -singleCompThread doesn't chagne the generated code or dependent dlls from matlab coder.
I tried to replace the libraries between the tbb version to the non tbb version - however matlab have different functions signature to the tbb functions - therefor this endeavor didn't work.
First try continues:
I manually changed the code and used the non tbb functions, I linked against the non tbb libraries.
matlab code still runs in parallel.
From the thread that calls my matlab generated function in C++ , I executed the following commands:
Unfortunately the code still runs in parallel. It’s most likely that these code doesn’t change the execution for sealed matlab dll.
I run the coder one more time. Matlab doesn’t change the code, the code still uses matlab’s tbb functions.
I run the visual studio profiler, there was one line with a large portion of execution time:
kmp implicit barrier
I called off kmp by setting the environment variable
KMP_DEVICE_THREAD_LIMIT to 1
Now my matlab function doesn’t create extra superfluous threads
I don’t know what matlab are doing under the hood however setting this environment variable now makes my application run single threaded
Maybe someone from matlab would give a more detail explanation
Setting the environment variable changes the whole system behavior. If there are other processes that uses openMP I’d limit their number of threads too. How to apply this change only for single thread or a single process.
Any help would be highly appreciated