This example shows how to run the MATLAB benchmark on your cluster workers. The benchmark measures the execution speed of several MATLAB computations. You can plot these results and compare the performance of the client and workers.
This example uses
pbench, a function that runs a subset of the tests in
bench, the MATLAB benchmark. The tests in this subset are LU, FFT, ODE, and Sparse. For details on these tests, see
Run the MATLAB benchmark on the client.
tClient = pbench
tClient = 1×4 0.1590 0.1599 0.0939 0.1673
Create a parallel pool using the
parpool function. By default,
parpool starts a parallel pool with workers on your default cluster. Select your default cluster on the MATLAB Home tab, in the Environment area, in Parallel > Select a Default Cluster.
Starting parallel pool (parpool) using the 'MyCluster' profile ... Connected to the parallel pool (number of workers: 4).
Run the MATLAB benchmark on the workers using the
parfevalOnAll offloads the execution of a function to all the workers in the pool, and returns a
parallel.FevalOnAllFuture object to hold the results when they are ready. To obtain the results from the workers, use
fetchOutputs on the future object.
f = parfevalOnAll(@pbench,1); tWorkers = fetchOutputs(f);
Combine the results of the client and workers, and plot them using a bar plot. Compare the relative performances of the workers and client.
tClientAndWorkers = [tClient;tWorkers]; ax = axes; bar(tClientAndWorkers'); ax.XTickLabel = ["LU","FFT","ODE","Sparse"]; xlabel("Benchmark type"); ylabel("Benchmark execution time (seconds)"); workerNames = strcat("Worker ",string(1:size(tWorkers,1))); legend(["Client",workerNames]);
By default, the MATLAB client is enabled for multithreading. Multithreading enables MATLAB numerical functions, such as
fft, to run on multiple cores using multiple computational threads. The workers use a single computational thread by default, because they are typically associated with a single core. Therefore, the LU test, for example, runs faster on the MATLAB client than on the workers. Other problems, such as ODEs, cannot benefit from multithreading, so they perform the same on the MATLAB client and workers. Consider this difference when deciding whether to distribute computations to MATLAB parallel workers, such as with
parfor. For more details, see Deciding When to Use parfor. For more information on multithreading, see Run MATLAB on multicore and multiprocessor machines.