Azzera filtri
Azzera filtri

What exactly is vectorization doing

2 visualizzazioni (ultimi 30 giorni)
Jiayun Liu
Jiayun Liu il 13 Ott 2022
Commentato: Jiayun Liu il 13 Ott 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?

Risposta accettata

Steven Lord
Steven Lord il 13 Ott 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.)

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by