stacker_liew 5 Posted May 6, 2023 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
Dalija Prasnikar 1396 Posted May 6, 2023 (edited) 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 May 6, 2023 by Dalija Prasnikar 1 Share this post Link to post