在我的并行算法书中,PRAM 模型有以下伪代码:
procedure PrefixSumPRAM( A, n ):
BEGIN
b := new Array(2*n-1);
b[1] := SumPRAM(A, n); //this will load A with the computation tree and return the sum
for i := 1 to ( log2(n) - 1 ) do
BEGIN
for all procID where (2^i) <= procID <= ((2^(i+1))-1) do in parallel
BEGIN
if odd(procID) then
b[ procID ] := b[ procID/2 ];
else
b[ procID ] := b[ procID/2 ] - a[ procID+1 ];
END
END
END
但是...PRAM 指定所有处理器必须对不同的数据执行相同的指令。
所以这个程序只能在 CREW PRAM 模型上执行?
或可在 EREW 模型上执行,则具有奇数 ID 的处理器将执行
b[procID]:=b[procID/2];
当具有偶数 id 的处理器执行(例如)NOP 指令时?