Jump to content
Sign in to follow this  
stacker_liew

What is the meaning of 2 In here

Recommended Posts

What is the meaning of 2 in here?

       TParallel.For(2,1,Max,procedure(I:Int64)
       begin
         if IsPrime(I) then
          TInterlocked.Increment(Tot);
       end);

 

Share this post


Link to post

2 is Stride parameter. However, it does not actually do what people think it does. It divides work in chunks that will run on same task effectively limiting number of threads used for running parallel for loop at a time. 

 

Default value of stride is 1 which means that each pass will run independently of others. If the stride is 2, then Max number will be divided with 2 and there will be Max/2 number of chunks - tasks. If the Stride is same as Max then all passes will run inside single task.

 

Someone writing this code though that stride defines index increments, but that is not so. Procedure will still run for each index from lower bound to upper bound  regardless of stride value and calculation of prime numbers will be run for index 1, 2, 3,...  

 

 

Edited by Dalija Prasnikar
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×