Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I measure the speedup from parallelization in matlab?

If I assume that a problem is a candidate for parallization e.g. matrix multiplication or some other problem and I use an Intel i7 haswell dualcore, is there some way I can compare a parallel execution to a sequential version of the same program or will matlab optimize a program to my architecture (dualcore, quadcore..)? I would like to know the speedup from adding more processors from a good benchmark parallell program.

like image 457
Niklas Rosencrantz Avatar asked Aug 14 '14 22:08

Niklas Rosencrantz


People also ask

How do I use parallel computing in MATLAB?

Depending on your preferences, MATLAB can start a parallel pool automatically. To enable this feature, select Parallel > Parallel Preferences in the Environment group on the Home tab, and then select Automatically create a parallel pool. Set solver options to use parallel computing.

Does MATLAB support multithreading?

Multithreaded computations have been on by default in MATLAB since Release 2008a. These functions automatically execute on multiple computational threads in a single MATLAB session, allowing them to execute faster on multicore-enabled machines.

What does parallel pool do in MATLAB?

What Is a Parallel Pool? A parallel pool is a set of MATLAB® workers on a compute cluster or desktop. By default, a parallel pool starts automatically when needed by parallel language features such as parfor . You can specify the default pool size and cluster in your parallel preferences.

How can I increase my Parfor speed?

You can improve the performance of parfor -loops in various ways. This includes parallel creation of arrays inside the loop; profiling parfor -loops; slicing arrays; and optimizing your code on local workers before running on a cluster.


3 Answers

Unfortunately there is no such thing as a benchmark parallel program. If you measure a speedup for a benchmark algorithm that does not mean that all the algorithms will benefit from parallelization

Since your target architecture has only 2 cores you might be better off avoiding parallelization at all and let Matlab and the operative system to optimize the execution. Anyway, here are the steps I followed.

  • Determine if your problem is apt for parallelization by calculating the theoretical speedup. Some problems like matrix multiplication or Gauss elimination are well studied. Since I assume your problem is more complicated than that, try to decompose your algorithm into simple blocks and determine, block-wise, the advantages of parallelization.
  • If you find that several parts of your algorithms could profit from parallelization, study those part separately.
  • Obtain statistical information of the runtime of your sequential algorithm. That is, run your program X number of times under similar conditions (and similar inputs) and average the running time.
  • Obtain statistical information of the runtime of your parallel algorithm.
  • Measure with the profiler. Many people recommends to use function like tic or toc. The profiler will give you a more accurate picture of your running times, as well as detailed information per function. See the documentation for detailed information on how to use the profiler.
  • Don't make the mistake of not taking into account the time Matlab takes to open the pool of workers (I assume you are working with the Parallel Computing Toolbox). Depending on your number of workers, the pool takes more/less time and in some occasions it could be up to 1 minute (2011b)!
like image 92
gire Avatar answered Oct 19 '22 21:10

gire


You can try "Run and time" feature on MATLAB.

Or simply put some tic and toc to the first and end of your code, respectively.

like image 42
Nematollah Zarmehi Avatar answered Oct 19 '22 21:10

Nematollah Zarmehi


Matlab provides a number of timing functions to help you assess the performance of your code: go read the documentation here and select the function that you deem most appropriate in your case! In particular, be aware of the difference between tic toc and the cputime function.

like image 2
Etienne Pellegrini Avatar answered Oct 19 '22 20:10

Etienne Pellegrini