program rank1; // find the rank of N mumber in o(logN) time const n = 8; sharedvar rankf: array[1..n] of word; ranki: array[1..n,1..n] of word; values : array[1..n] of word; procedure init; var i : word; begin P := n*n; // assign the number of processor to PRAM model // for i := 1 to n do // initialize the value // rankf[i] := 0; values[i] := n-i; writeln(values[i]); end; // for end init; procedure finish; var i :word; begin for i := 1 to n do writeln(rankf[i]); // write the result // end; //for end finish; var i,j,a,b,c,d,limit : word; begin // main // the algorithm to find the rank in log(n) time par a := 0 to n*n-1 sync do // for every processor does in parallel // i := a mod n + 1; j := a div n + 1; if (values[i] <= values[j]) then ranki[i,j] := 1 else ranki[i,j] := 0; end; // if end; // par par a := 1 to n sync do // sum the value in array // for c := 1 to log(n) do limit := 1; for d := 1 to c do limit := 2*limit; end; // for for b := 1 to (n/limit) do ranki[a,b] := ranki[a,2*b-1] + ranki[a,2*b]; end; // for end; // for rankf[a] := ranki[a,1]; end; // par @CLOCK end rank1.