Filter löschen
Filter löschen

What exactly is vectorization doing

2 Ansichten (letzte 30 Tage)
Jiayun Liu
Jiayun Liu am 13 Okt. 2022
Kommentiert: Jiayun Liu am 13 Okt. 2022
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?

Akzeptierte Antwort

Steven Lord
Steven Lord am 13 Okt. 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.)

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by