What exactly is vectorization doing

1 view (last 30 days)
I am curious why does vectorization reduces computational time? Is matlab using multiple cores when I vectorize? If that is the case, does it mean that vectorized codes will always run faster the more cores you have?

Accepted Answer

Steven Lord
Steven Lord on 13 Oct 2022
When you go grocery shopping do you go from your house to the store, pick up one item, go from the store to your house, and repeat that process for each item?
Or do you make a list, go from your house to the store, pick up all the items on the list in one trip, and go from the store to your house?
Avoiding the overhead of repeated trips between your house and the store is a good thing. But if the "one item" you're going to the store to pick up is a large piece of furniture, it may make sense to make multiple trips because fitting the item and anything else in your car would be difficult. That would represent a case where vectorization could be slower than non-vectorized code because of memory or other resource constraints.
Many functions in MATLAB are multithreaded if the inputs are "large enough" (and no, I'm not going to quantify what that means. It can be different for different functions and can change from release to release.)

More Answers (0)

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!