并行排序ShearSort ---[MPI , c++]

思想:

(1) 对于一个nxm的数组,使用N个work进行处理.
  (2)  先按行对数组进行升序和降序排序【由左至右】,一般奇数序列work升序,偶数序号的work进行降序
(3)再按列对数组进行升序排序【由上至下】
(4)当数据不再发生变化时,终止退出.

并行排序ShearSort ---[MPI , c++]_第1张图片


/*
----------------------------------
Version    : ??
File Name :     ShearSort.py
Description :   
Author  :       xijun1
Email   :       [email protected]
Date    :       2018/12/18
-----------------------------------
Change Activity  :   2018/12/18
-----------------------------------
__author__ = 'xijun1'
*/

#include "mpi.h"
#include 
#include 
#include 
#include 
using std::cin;
using std::cout;
using std::endl;
using std::vector;

//归并排序
bool Less(int a, int b){
    return a  b;
}
//升序
bool Merge(int *A ,int ps ,int mid , int len , bool( * Comp)(int a , int b) ){
    int i=ps,j=mid,cnt=0;
    int C[len-ps+1];
    bool is_change = false;
    while(i

结果:


demo_mpi mpirun  --mca btl_vader_backing_directory /tmp --oversubscribe   -np 4 shear_sort
start epoch: 0
3 6 11 16
10 8 5 1
2 7 12 14
15 13 9 4
start epoch: 1
2 3 10 15
6 7 8 13
5 9 11 12
1 4 14 16
start epoch: 2
1 2 5 6
9 7 4 3
8 10 11 14
16 15 13 12
start epoch: 3
1 8 9 16
2 7 10 15
4 5 11 13
3 6 12 14
start epoch: 4
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
---------------------------
1  2  3  4  
8  7  6  5  
9  10  11  12  
16  15  14  13  

转载于:https://www.cnblogs.com/gongxijun/p/10137787.html

你可能感兴趣的:(c/c++,python)