Reputation: 18242
I'm really trying to wrap my head around vectorization but I can't seem to understand it. I don't know if I don't understand how to vectorize, or if I don't understand the array notation that's being used. An example of a loop I'm working on with school is below:
for (M=0; M< number_of_iterations/2; M++){
for (i=2; i<n-1; i++)
for (j=1; j<n-1; j++)
y[i][j]= (x[i-1][j]+x[i][j-1]+x[i+1][j]+x[i][j+1]+x[i-2][j])/5.;
I'm not sure I quite understand the whole thing on dependencies - Is there a way to vectorize this using array notation as is, or do I need to adjust it somehow to account for dependencies throughout?
Thanks in advance for any help.
Upvotes: 0
Views: 36
Reputation: 975
First I recommendo you to use brakets {} to organize your lines of code and understand it better. Second, take a look to this page: http://www.javatutorialhub.com/java-arrays.html Thirg, always start with easy examples to not get confused.
Upvotes: 1
Reputation: 182761
Assuming x
and y
are distinct arrays that don't overlap at all, there are no dependencies. x
never changes, and all computations have results that only depend on x
. No computation depends on the results of a prior computation.
The calculations and assignments used in that loop could occur in any order and with any concurrency.
Upvotes: 1