Help with Multithreading!

6 views (last 30 days)
RB
RB on 15 May 2019
Answered: Jan on 15 May 2019
I have a for loop that runs through .tif files. Within the for loop there are more for loops. I want to speed up this code because it takes a very VERY long time to run on even one .tif file. I wanted to use multithreading or parallel threading, however the parfor command that comes with the parallel toolbox in matlab cannot be used on my for loops. Parfor cannot be used because we iterate through files in the first loop, and the following loops are order dependent. We need it to go consecutively, so parallel threading is not going to work. Is there any other way to use multithreading in these scenarios? Even a way to use mutlithreading in the first for loop (the one that runs through images - parfor won't work because the for loop is not an increasing integer) would speed it up by doing multiple images at once.
Any help is greatly appreciated, thank you!

Answers (1)

Jan
Jan on 15 May 2019
If the data must be processed sequentially, you cannot run the task in a parallel way and therefor multi-threading will not help, because each thread would have to wait until the former one is ready. Multi-threading is useful only, if the data can be processed in parallel.
I suggest to post your code. The forum usually finds a way to accelerate it. In addition it would clarify statements like "the for loop is not an increasing integer".

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!