Why does the "bwskel" function perform poorly after adding parallel processing to my workflow?

I am trying to perform an image processing task on a set of high resolution satellite images (1350 x 2000 pixels). There are a few thousand images that I would like to process, and it currently takes a lot of time to process them all. For this reason, I tried to add parallel processing to my workflow by using "batch" and "parfor". Unfortunately, I found that my performance was worse after adding a parallel pool with 4 workers to my workflow using my local parallel cluster. After using the "profile" tool on my workflow, I was able to identify that the most time consuming part was the "bwskel" function, which took up a majority of the time.
Why does the "bwskel" function perform so poorly after adding parallel processing to my workflow?

 Accepted Answer

The reason that "bwskel" does not perform well in your parallel processing workflow, is that the function's internal implementation employs the use of multithreading. There are actually a number of image processing functions that do this since it can provide performance benefits when it comes to image processing tasks.
It is also important to note that when you start the MATLAB desktop environment, MATLAB will begin by opening multiple computational threads. The "maxNumCompThreads" command returns the maximum number of computational threads that MATLAB will open. This number is dependent on operating system and processor, but it will typically be greater than 1. Because MATLAB opens with multiple computational threads, functions like "bwskel" can take advantage of their multithreaded implementation. Please refer to the following documentation for more information on the "maxNumCompThreads" functions:
The reason it is important to discuss how many computational threads MATLAB starts with is that each parallel worker begins with one computational thread by default when using your local parallel cluster. Since each parallel worker only has one computational thread, the "bwskel" function cannot take advantage of its multithreaded implementation. 
To fix this issue you can change the number of computational threads that each parallel worker on your local parallel cluster is allowed to use. This will allow each worker to take advantage of the multithreaded implementation of “bwskel”. Please refer to the following documentation to see how you can use the Cluster Profile Manager to change the settings on your “local” cluster:
The section labeled “Edit Number of Workers and Cluster Settings” explains that the number of workers and threads can be edited on the chosen parallel cluster.
Please keep in mind that the number of threads and workers that you are using will be limited by the hardware that your machine is using.

More Answers (0)

Categories

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!