Parallelization of independent computations to exploit 100% of multicore CPU (all cores)
4 次查看(过去 30 天)
显示 更早的评论
I have a Matlab code
SOL=my_code(INPUTS)
I wish to run my code by sweeping the INPUTS variables over a wide range of values.
My PC has 4 cores. When I run my code my task manager indicates that Matlab is using in the range of 20-23% of the CPU. This is normal, it means that my code is being run on one of the four cores, which is running not far from 100% of it's capacity.
To exploit the full power of my CPU I open four Matlab terminals. Just to be clear: the Matlab program is running four times on my PC, I have four Matlab terminal windows. Each Matlab session is used to run my function my_code(INPUTS) in parallel.
My task manager informs me that each Matlab session is using 20-23% of my CPU, indicating that each code is being run by a dedicated core of my processor, and my net simulation speed is increased four fold.
So instead of running the following code with a single Matlab session (which uses max. 25% of CPU) :
for i=1:4
SOL(i) = my_code( INPUTS(i) );
end
I run in parallel the four following computations, each of which exploits around 25% of CPU:
% in Matlab session 1
SOL1 = my_code( INPUTS1 );
----------------------------------------------
% in Matlab session 2
SOL2 = my_code( INPUTS2 );
----------------------------------------------
% in Matlab session 3
SOL3 = my_code( INPUTS3 );
----------------------------------------------
% in Matlab session 4
SOL4 = my_code( INPUTS4 );
This solution works well, but is far from being 'elegant', and opening up four Matlab sessions is a bit annoying, and I end up having a lot of active windows on my PC. I am sure there must be a way to exploit near 100% of my PC's CPU with a single Matlab session, any help would be greatly appreciated.
Thanks in advance,
F.-B.
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Manage Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!