HPC with Matlab no performance improvement
17 次查看(过去 30 天)
显示 更早的评论
I have access to a 32 cores computera and to a 3000 cores Cluster.
But when I launch my Matlab code I have similar performances as on my older computer with only 4 cores.
Could you please give me some hints or small examples about uusing Matlab with HPC (MPI like or GPGPU like).
Thanks
0 个评论
采纳的回答
Michael Croucher
2020-11-2
编辑:Michael Croucher
2020-11-2
This is a huge topic which has entire Master's level courses devoted to it but I'll try to give an oversimplifed view.
TL;DR : Making effective use of HPC systems is highly problem dependent and often quite difficult. MATLAB has a bunch of tools that can help you out but you need to do a lot of work yourself.
HPC/cloud is not a magic bullet
What you have experienced is not just limited to MATLAB on HPC systems but to any program written in any programming language on HPC systems. I sometimes give a talk to HPC folk that discusses the problems users such as yourself face https://mikecroucher.github.io/HPC_for_everyone/.
MATLAB is smart and can automatically use multiple cores and other HPC technlogy such as SIMD (Single Instruction Multiple Data) in many situations. Many linear algebra routines such as eig, svd and matrix multiply for example along with a bunch of stuff from the image processing toolbox. So called 'multithreaded' routines can be found in many places in MATLAB and you'll benefit from them with no extra work at all. However, to see an improvement from your 4 core laptop to a 32 core HPC system, they would have to form the dominant part of your calculation.
But what if this is not the case? What if your code doesn't make use of this free and easy form of parallelism? Well...you might even see a drop in performance when you move to HPC! As core count goes up, the CPU frequncy tends to come down (essentially for electrical power reasons) meaning that if your code is predominantly single threaded, you might find it goes faster on your laptop.
Other reasons for poor performance might be because you think you're running on all of a 32 core node but maybe your HPC job submission script has only asked for 1 core. You might be sharing that node with up to 31 other users!
Where is your code taking all of its time?
The first thing you need to do is work out where your code is taking all of its time and to do that you should run the profiler. https://uk.mathworks.com/help/matlab/matlab_prog/profiling-for-improving-performance.html
Once you have found out what's making your code slow, you need to ask yourself 'How can I do this part differently to make it faster?'. There are potentially a huge number of answers to this question, many of which won't have anything to do with a HPC system. The book 'Accelerating MATLAB Performance' (https://www.amazon.co.uk/Accelerating-MATLAB-Performance-speed-programs/dp/1482211297) has almost 800 pages!
If potential answers to this question include 'offload to a GPU' or 'split up and make use of multiple CPUs' then you may have a case for HPC.
How to make use of a HPC system?
There are many ways forward but here are 3 common scenarios:
job arrays (aka run lots of MATLABs): One potentially useful (and easy!) way of making use of a HPC system is when you need to run the same program many times but with different input parameters, input data etc. Learn how to submit 'Job arrays' (A term used by the HPC scheduler you system uses) to your cluster and run as many simultaneous instances as your sysadmin will allow you. It's like having 100+ laptops, each with its own install of MATLAB running an instance of your program (as an aside...I've seen people do this in University computing labs!).
Parallel Computing Toolbox: Within MATLAB itself, you might be able to make use of the Parallel Computing Toolbox for GPU and multicore/multinode programming. The page at https://uk.mathworks.com/products/parallel-computing.html has some nice links to get you started.
Go parallel in C or Fortran (For the hardcore!): Another way to exploit parallelism would be to write an OpenMP mex file. Doing this by hand would require knowledge of C or Fortran along with OpenMP itself. OpenMP alone is a topic that has entire courses/books devoted to it but a (probably out of date) demonstration for MATLAB is on my blog at https://walkingrandomly.com/?p=1795. MATLAB can help you out here in a lot of cases too though - The MATLAB Coder (https://uk.mathworks.com/products/matlab-coder.html) can generate parallel mex files for you and a great tutorial is at https://uk.mathworks.com/help/coder/ug/acceleration-of-matlab-algorithms-using-parallel-for-loops-parfor.html
3 个评论
Michael Croucher
2020-11-2
The parallel computing toolbox is probably your best best then. Until recently I would have said that the CPU part of it was essentially MPI-like in that it only allowed multi-process parallelisation but 2020b has added explicit support for thread based parallel pools. https://uk.mathworks.com/help/parallel-computing/choose-between-thread-based-and-process-based-environments.html#mw_6bbf0761-74c0-404e-9db6-77b82c7c138c
As far as I can tell, this can allow you to scale in a way similar to hyrid MPI/OpenMP but with the added bonus of only having to worry about a single API.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!