各个进程将对父数组的子集进行排序。但是,在主进程收集所有这些子集之后,必须对父数组进行一次排序。
e.g.
原始数组 = {1,7,2,3, 10,4,8,0, 11,5,9,6}
分散后 进程 1:{1,7,2,3} 进程 2:{10,4,8,0} 进程 3:{11,5,9,6}
和单个进程排序:{1,2,3,7},{0,4,8,10},{5,6,9,11}
因此,收集后,原始数组为 {1,2,3,7 , 0,4,8,10 , 5,6,9,11}
因此必须再进行一次排序。
Edit :
One of the solutions would be (This can be further optimized):
instead of using mpi scatter and gather use a plain mpi send and mpi receive.
The master process/node would give the data to the dummy master process/node which will further divide it to rest of the nodes. The last line of nodes can sort the sub set of data and return the sorted subsets to their parents.
after the parents receive the individually sorted sub sets they will sort the sorted subsets and provide their sets to their parents.
该方法还可以进一步优化。