Hello, Maybe someone could help me to speedup this type of for loop? I did try parfor, I did try to think of way using GPU, but it does not work with indexing.
No. You simply created one large array in memory, and then on the next line created another large array in memory, that replaced the first array. It had nothing to do with preallocation, if that is what you were thinking, because you were not using indexing anywhere. Preallocation is where there is onlyone array (with its final size) in memory and its values are accessed using indexing: thus the array does not change size so it does not need to be moved in memory (not really relevant to your code) and its elements are simply accessedin situ using indexing (which is what you werenot doing). Read the documentation and check how the examples use indexing:
Creating such a large array (which is entirely unused) will definitely slow down the code.
@madhan ravi: in any case, don't just believe me or Bruno because we wrote something: try it yourself! Use a loop andtic &toc, or usetimeit, and find out yourself. Experimentation is always worthwhile.
Another hint: Ina+(1:d) you create the double vector1:d at first and then adda to each element. It is more efficient to omit the addition and create vector directly:
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
0 Comments
Sign in to comment.