开发者

how to add percentage completion on parallel nested loops?

for example, i wish I can see 1% ~ 100%, how could I do that?

Parallel.For<Dictionary<int, long>>(0, r1, () => new Dictionary<int, long>(), (j, loop, tmpWi开发者_开发技巧nRange) =>
    {
        for (int k = 0; k < r2; k++)
            for (int l = 0; l < r3; l++)
                for (int m = 0; m < r4; m++)
                {
                    int pay = GetPay(j, k, l, m);
                    tmpWinRange[pay]++;
                }
        return tmpWinRange;
    },
(x) => { tmpWinRangeCollection.Add(x); }
);


How about using an interlocked increment to update the progress?

int progressCount = 0;
Parallel.For<Dictionary<int, long>>(0, r1, () => new Dictionary<int, long>(), 
    (j, loop, tmpWinRange) => 
    { 
        for (int k = 0; k < r2; k++) 
            for (int l = 0; l < r3; l++) 
                for (int m = 0; m < r4; m++) 
                { 
                    int pay = GetPay(j, k, l, m); 
                    tmpWinRange[pay]++; 
                }
        Interlocked.Increment(ref progressCount);

        return tmpWinRange; 
    }, 
    (x) => { tmpWinRangeCollection.Add(x); } 
); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜