What exactly is vectorization doing

3 次查看(过去 30 天)
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?

采纳的回答

Steven Lord
Steven Lord 2022-10-13
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.)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by