我正试图围绕并行for-loops如何工作的想法,这对我来说很新,并且已经读过这个stackoverflow线程,在这里找到span and parallel loop,并找到了最佳答案真有帮助。
我想知道的是,如果我有一个并行的lop,并且在它内部有一个并行的lop,如果它们将按照以下方式运行(为方便起见,我会让n = 5和'to '表示最多包括(< =)):
以下是我脑海中的代码:
parallel for j=1 to n{
parallel for i=1 to j-1{
Do-something
}
}
这是我倾向于的线索的行为,但是希望有人确认是否正确:
Time Action
0 Thread0 creates Thread1
1 Thread0 creates Thread2, T1 -> T3
2 T0 -> T4, T1 -> T5
好的,这里创建了外观的所有线程。现在为了内心。这里subXY表示线程x的线程号y:
time Action
3 T0 -> SubT0t0, T1 -> subT1t0, T2-> SubT2t0....
//All threads have created a subthread t0 so 5 more threads created.
4 T0 -> subT1t1, subT0t0 -> subT2t1, T1->subT2t2, subT1t0->subT3t1...
//All the subthreads created more threads AND the 'Older' threads
//created subthreads under other 'Older' threads. 11 more created.
5 T0 -> subT5t2, subT0t0 -> subT5t3, T1 -> subT5t4, subT5t5
//All threads have been created.
6 Execute command Do-something
我知道这可能不是我所想的最好的描述,但它是我能想到的最好的。
这是对的吗?或者外部循环线程只会使一个线程连接到他自己?例如,T1只会生成subT1XX线程吗?
在那段时间,5时间什么都不做的线程会执行命令吗?
如果有人可以帮助我,这对我很有帮助。