Compiled code with matlab compiler using singleCompThread uses more than 100 percent cpu
5 views (last 30 days)
Show older comments
I need to compile the code with singleCompThread. However, the resulted code when I run it using matlab runtime uses more than 100 percentage. This is limiting (reducing) the number of jobs I can submit because I have to allocate 2 cpus per job.
I have tried these to ways:
Using singleCompThred while compiling
mcc -m code_to_compile.m -R -singleCompThread
and using maxNumCompThreads(1) inside the code.
Please suggest a workaround!
0 Comments
Answers (1)
Shivani
on 26 Feb 2024
Edited: Shivani
on 26 Feb 2024
I understand that you would like to limit MATLAB to using just a single core on your machine.
Without using the -singleCompThread option, you may still be able to limit MATLAB's CPU usage by using the means provided by your operating system. For example, if you are working in a Linux environment, you can try using the taskset command within the shell to launch and pin an instance of MATLAB to a specific CPU core. The following command would launch MATLAB (assuming it is on the system path) and restrict it to using only the first logical CPU core:
$ taskset -c 0 matlab
Depending on your platform, there may be other commands that you can use to alter a program's CPU usage, such as that of MATLAB. Using taskset, the maxNumCompThreads(n) command does not return an error as it does when using the -singleCompThread flag. One thing to note, though, is that the taskset command in Linux requires you to specify the exact logical CPU core(s) on which MATLAB is to run.
For more information about taskset, you can consult the documentation provided by your Linux operating system by issuing the following command at a terminal prompt:
$ man taskset
Hope this helps!
0 Comments
See Also
Categories
Find more on C Shared Library Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!