View Single Post
  #2  
Old 11-26-2011, 05:21
aldente aldente is offline
VIP
 
Join Date: Jul 2003
Posts: 266
Rept. Given: 27
Rept. Rcvd 7 Times in 5 Posts
Thanks Given: 36
Thanks Rcvd at 10 Times in 9 Posts
aldente Reputation: 7
I guess that's because the condition "i<k" has to be evaluated after each loop, and C/C++ allows changes to k during the loop.

Other languages (like MATLAB) would run through that loop for k_0-times, with k_0 being the value of k when entering the loop. Changes to k will be ignored. In this case its possible to parallize that loop (called "parfor" in MATLAB):

parfor i=0:k-1
...
end

But in C/C++ you have to check the expression each time, therefore it's just not possible to parallize that loop, because you do NOT know in advance how many times you have to run through that loop if k is a non-constant variable.

Maybe you should try a "const int k" to see if that gets parallized.
Reply With Quote