How to Run the Same MATLAB Code Through Two Laptops?

I have a large data and my laptop takes probably a week to finish one run of my code. I'm thinking to reduce the amount of time by connecting my laptop with another one and use them both to run the same MATLAB code. Is this even possible?

2 Comments

Install and Configure MATLAB Parallel Server for Slurm
If you have a cluster with Slurm, follow these instructions to integrate MATLAB® with your scheduler using MATLAB Parallel Server™. If you do not have an existing scheduler in your cluster, see: Install and Configure MATLAB Parallel Server for MATLAB Job Scheduler and Network License Manager.
These instructions guide you through the following tasks:
After you integrate MATLAB with Slurm, you can access workers in your cluster from a desktop MATLAB client session with Parallel Computing Toolbox™. Workers are MATLAB computational engines that typically correspond to a core.
The setup in these steps uses the network license manager.
Thanks Chunru. Very detailed answer indeed. Thanks for your time as well. However, the solution presented looks a bit hard for me. I never heard of Slurm before and the steps appear to be technical for a novice guy like me.

Sign in to comment.

 Accepted Answer

Walter Roberson
Walter Roberson on 14 Apr 2022
Edited: Edric Ellis on 14 Apr 2022
If your code is designed to use Parallel Computing Toolbox, then you can distribute workers between multiple nodes or hosts. However this requires a MATLAB Parallel Server license. That toolbox is not available to Student licenses, and is moderately expensive for Standard licenses (but might be affordable for Academic licenses.)
If you were using Mac or Linux then you could potentially use ssh from one host to invoke matlab on the remote system, and give it a chunk of work to do.
If you were using Windows, then it just might be be possible to use the MATLAB Engine interface together with COM objects to request remote execution. MathWorks documentation about the execution engine does not list that as a possibility for Windows.
... Execution Engine for Mac and Linux does specifically say that you can request remote execution using that interface.

6 Comments

Hi Walter. Your answer looks more easier and doable to me. I'm using an academic licensed copy of MATLAB, so can I use this Parallel Computing Toolbox? What changes do I need to do in my codes to employ the toolbox? Are there useful videos for illustrations?
(Edited to change "Distributed Computing Toolbox" --> "MATLAB Parallel Server". The names of the products for parallel computing have gone through a bewildering array of names over the years - "Distributed Computing Toolbox" was the old name for what is now "Parallel Computing Toolbox"; "MATLAB Distributed Computing Engine" was the old name for what is now "MATLAB Parallel Server". There might have been other names along the way that I've forgotten about).
The first thing to do would be to fork a copy of the code, and modify it to use parfor or spmd or parfeval
  • parfor automatically analyzes your code and figures out which variables to copy and which parts to copy to which worker. parfor handles scheduling automatically. However, you have no control over the order that workers start executing, and if you happen to have a situation where some tasks can take much longer than other tasks, you can end up with one worker with several tasks queued while other workers are idle. Workers can send partial results back to the client without too much trouble; the client can send information to the worker but it is a bit clumsy to set up; workers can never directly communicate with each other.
  • parfeval() does not analyze your code; you have to manually pass the appropriate parts of variables to the workers. You have control over the order you add work to the queue. The next task on the queue is assigned to the next available worker, so you cannot end up in the situation where there are workers with multiple tasks queued while other workers are idle. Workers can send partial results back to the client without too much trouble; the client can send information to the worker but it is a bit clumsy to set up; workers can never directly communicate with each other.
  • spmd automatically analyzes your code and figures out which variables to copy to the workers. There isn't really any scheduling; all of the workers start at the same time and have to look at their worker number to figure out what they are intended to do. Workers can commuicate relatively easily between themselves, and can put up "barriers" to ensure that exclusive access to resources (you can run into serious difficulties that are very hard to debug if two workers write to the same part of a file at the same time.)
All of these options assume that you can divide the work into independently-executing sections that proceed by themselves and probably do not communicate all that much. None of these options are suitable for the case where you just have large matrices being operated on -- not unless you can find a way to partition the work into independent portions that can later be stitched together along the boundaries. None of these options are suitable for the case where you just have a lot of dependent iterations that cannot be separated out, and the real issue is just that you were hoping for the dependent iterations to execute faster.
In some situations, if your arrays are not overly large but you are doing a lot of hard mathematical work, the key is to instead use an NVIDIA GPU. You mention that you are using a laptop: most laptop NVIDIA GPUs are comparatively slow at doing double precision, much faster at single precision. Especially if your problem can be rewritten to use single precision, then there are cases where using a GPU can be much faster... if you are operating on entire arrays. (Deliberate indexing of arrays is a relatively slow operation on NVIDIA GPUs.) If you need double precision, then a fair bit of attention needs to be paid to exactly which model of NVIDIA GPU you use -- and "newer" does not always mean "faster for double precision" for this purpose. The model names ending with "Ti" tend to be the ones that are good for double precision... but they might need a wider bus or more cooling than is practical in a laptop.
@Walter Roberson This is very useful... I installed the toolbox and started to run it tonight, and I'm enjoying it already.
The Team who invented the Parallel Processing Toolbox should be rewarded. I just finished running a code using this toolbox in less than a day. That same code took more than 4 days before to run without the toolbox.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!