Parallel computing implementation is taking longer time that serial computation
2 views (last 30 days)
Show older comments
I am trying to use parallel computation for a working pipeline, where data is collected in buffer and then the buffer is processed. Using parallel computation I am spliting this to two threads. One for collecting the data to buffer and second thread takes the buffer as input and process the algorithm.
But We are seeing a huge time difference while using parallel computing. Using serial computation it takes 0.1s for 1000 iterations, but parallel computation is taking around 20s. The code we are using is exactly similar to the example we have attached.
In order to avoid the data dependecy between we used the thread with independent data but still it is taking the same time.
It would be helpful if you could get answers for the following questions
- How to improve the efficiency of the compution ?
- How to explicitly assign a core to a thread?
- Why the performance degraded when parallel computation is used?
Please find the attached code for your reference. add.m is the fuction, parallelCode.m is the parallel computation code, serialCode.m is the serial computation code.
4 Comments
Raymond Norris
on 21 Sep 2021
Your problem isn't parallelizable. For a given iteration, two tasks happen sequentially. You run task 1, which feeds task 2. And, at a higher level, iteration 100 is ultimately dependent on iteration 50, which dependent on iteration 1.
If you roll this out
Iteration_1/task_1 --> iteration_1/task_2 --> Iteration_2/task_1 . . . --> Iteration_1000/task_2
There's no where to break it up and run iterations / tasks in parallel. Anything you're doing in parallelCode is only going to slow down the code by having MATLAB do more stuff other than the barebones for-loop in serialCode.
As a side note, I don't see where "we used the thread with independent data" is happening. What independent data?
Answers (0)
See Also
Categories
Find more on Startup and Shutdown 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!