The pseudo code below represents a sequential version of odd/even transposition sort. It sorts an N element array, a[0:N-1], for N even.
While notsorted do
begin
for i := 0 step 2 until N-2 do
compare&swap(a[i], a[i+1]);
for i := 1 step 2 until N-3 do
compare&swap(a[i], a[i+1]);
end;
It is assumed that compare&swap is a subroutine which compares its two arguments and swaps them if they are not in order. It is also assumed that notsorted will be changed from true to false when sorting is complete (not shown in the code above).
(a) How should the array a[0:N-1] be spread over the memories of a P processor distributed memory multiprocessor in order to implement a parallel version of this program? Assume that P divides N evenly, so N = P imes m, where m is an integer. (Hint: first find the index ranges of āaā for array elements for processor āiā and give the partitioned array a new name which would be the section of the array belonging to processor i. Then this new smaller array defined within each process can have indices 0,..., ?).
(b) Write pseudo code for processor i of the P processors assuming i is neither the first nor the last processor. Assume a non-blocking send(, ) and a blocking receive(, ) for communication. (Hint: assume m is even and m >= 6).