Reduce Time to Results with MATLAB Using Parallel Computing - MATLAB
Video Player is loading.
Current Time 0:00
Duration 4:59
Loaded: 0.78%
Stream Type LIVE
Remaining Time 4:59
 
1x
  • Chapters
  • descriptions off, selected
  • captions off, selected
      Video length is 4:59

      Reduce Time to Results with MATLAB Using Parallel Computing

      MATLAB® makes it easy to leverage your local and remote hardware to scale up your MATLAB applications and run multiple Simulink® simulations in parallel.

      Parallel Computing Toolbox™ lets you solve computationally and data-intensive problems using multicore processors, GPUs, and computer clusters. Parallel-enabled functions in MATLAB and other toolboxes and high-level constructs such as parallel for-loops, special array types, and parallelized numerical algorithms enable you to parallelize MATLAB applications without CUDA® or MPI programming.

      You can scale your computations further by running them across multiple machines with MATLAB Parallel Server™. You can prototype your programs and simulations on the desktop and then run them on clusters and clouds without recoding. MATLAB Parallel Server supports interactive computations and batch jobs and runs them as scheduled tasks on your cluster.

      Published: 14 Aug 2023

      This video will demonstrate how you can speed up your computations by running them in parallel on your machine with Parallel Computing Toolbox on a cluster with MATLAB Parallel Server. In this case, we can speed up a parameter sweep by running it in parallel on our computer and then by using your remote cluster. This video will show you how you can get started.

      We will be using the parameter sweep example available on the MathWorks site for this demo. This example will show how to perform a parameter sweep on a classical system, the Van der Pol oscillator. This live script uses an adaptation of the parameter sweep and shows how a typical MATLAB user may leverage more resources while performing their work.

      The first parameter sweep scenario is done in serial without any parallelization on 10-by-10 grid. This takes about 12 seconds. After confirming that our algorithm is working and we have run a small use case, we are ready to scale up the problem and run the parameter sweep on a bigger grid. To save time by using additional resources, we will rerun the parameter sweep in parallel using Parallel Computing Toolbox.

      First we're going to start a pool of workers. These are MATLAB computational engines that run in the background that we can offload work to. We recommend running one worker per one physical core. This machine has four physical cores, so we will start four workers. You can see that the pool has successfully started, as indicated in the live script and in the status at the bottom left of the MATLAB desktop. We are also going to increase the problem size and run the parameter sweep on a 20-by-20 grid. We will use parfor to speed things up.

      While the parallel workers are running, you will notice that the status indicator in the bottom left of the MATLAB desktop is green. With Parallel Computing Toolbox, I was able to increase the problem size four times and run it across four workers in about the same time as the serial run, getting near linear scalability. Now let's compare the serial and parallel code.

      Aside from the function name, the only difference is that I changed my for loop to a parfor loop. This will automatically run the contents of the loop in parallel. If you run into any issues when changing your for loop to a parfor loop, the code analyzer will inform you of any problems. Next let's run our parameter sweep on the cluster and scale it up further. I would like to continue running MATLAB on my personal machine and offload computations to a remote cluster so I can run even larger cases without needing to wait longer for results.

      To get started, I'm going to use the Discover Clusters feature to get access to a cluster on my network. This will work for the MATLAB Job Scheduler or for a third-party scheduler like Slurm. This process will create a cluster profile that I can use to submit work to a remote cluster. This requires that MATLAB Parallel Server is installed and licensed on the cluster.

      I'm going to start a pool of 400 workers on my Slurm cluster, and I'm attaching some files along with my job. This is an optional step, as MATLAB will run an automatic file dependency analysis and attempt to attach all the necessary MATLAB code files with the job. This pool of workers will allow me to execute my previously written parallel code on the remote cluster resources without ever leaving MATLAB. After the pool starts, we can see that the workers are running on the cluster by the host name output.

      Now let's run an even bigger example. We're going to perform a parameter sweep on a 200-by-200 grid using 400 workers. This is 100 times more work with 100 times more compute resources. So we expect similar runtime to our 20-by-20 case with four workers. Let's compare the runtime results.

      We got near linear scalability when going from our serial run to a problem with four times as much work when using Parallel Computing Toolbox with four workers. When scaling the problem further to 400 workers, with 100 times more work and 100 times more workers, it took almost twice as long. Why is that? Well, the overhead associated with the additional workers in the job is enough to be more significant. If the problem were more computationally intensive, we might expect the problem to have run in the same amount of time.

      To summarize, I prototyped and developed a parameter sweep application on my machine. Then I scaled up the parameter sweep on my local machine by running it in parallel with Parallel Computing Toolbox with four times as many cases and four times as many workers. After determining that my code ran in parallel, I introduced MATLAB Parallel Server and scaled the problem up further, without adding any significant additional execution time, by using more resources on a remote cluster.

      View more related videos