Parallel Processing for Simple Code
2 views (last 30 days)
Show older comments
I'm trying to simulate a 400 lines code in MATLAB and it took 20-30 minutes to complete in my Corei7 PC, Is there any way to run this code with parallel processing to minimizing the time.
0 Comments
Accepted Answer
John D'Errico
on 19 Sep 2019
Edited: John D'Errico
on 19 Sep 2019
Um, so? You clearly are not an experienced user of MATLAB. So your code may be inefficient. That it took a long time is not a surprise, as it is absolutely trivial to write inefficient code.
Can you do something in parallel? Well, possibly, IF you have the parallel processing toolbox, and you know what you are doing. Otherwise, MATLAB already does some/many computationally intensive things in parallel. So you might not even gain much, if anything.
A FAR better approach is to look at your code critically. We cannot do that for a lengthy code written by a novice. Your first step should be to learn about the profiling tool. It can tell you where the bottlenecks lie in your code, what specific lines make it slow? Then spend some time thinking about how to improve them. Again, novice code is often inefficient. If you find a specific line that is a problem, then ask how to make it better on this forum. It may be the solution is to completely change your general algorithm. But we cannot know that without seeing anything, and certainly not for a massive piece of code.
So the answer is not to just try brute force to somehow make your computer run poorly written code faster. You will rarely gain much by that approach, and it will be expensive (because that toolbox is not cheap.) Instead, learn to find where your code is inefficient, and that way, make it fast.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical 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!