Exetools  

Go Back   Exetools > General > General Discussion

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT +8. The time now is 07:55.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )