在并行代码内并行 [英] parallel within parallel code
本文介绍了在并行代码内并行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一旦我将任务划分为4个独立的任务,并使它们并行运行.是否可以进一步使每个任务并行运行?(例如,每个任务,每个循环都有很多-可以实现为并行代码)
Once I have divided the tasks to 4 independent tasks and make them run in parallel. Is it possible to further make each task run in parallel ? (says, each task, there are lots of for each loop - that could be implemented as parallel code)
推荐答案
您当然可以,但是尽管如此,您必须考虑多个因素
You have to take into account multiple factors though
- 迭代的大小是多少(越多越好)
- 您的CPU可以处理多少个并发线程
-
处理器中的内核数量
- What's the size of your iterations (The more, the better)
- How many concurrent threads can your CPU handle
The amount of cores in your processor
Parallel.For(0, length1, i =>
{
Parallel.For(0, length2, j =>
{
Console.WriteLine(i * j);
});
});
这篇关于在并行代码内并行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文