36 template<
typename _RandomAccessIter,
typename _Compare,
37 typename _SeqSortType,
typename _SplitType,
typename _MergeType>
39 _Compare comp,
long *dist_in,
45 typedef typename iterator_traits<_RandomAccessIter>::value_type _ValueType;
46 typedef typename iterator_traits<_RandomAccessIter>::difference_type _Distance;
49 MPI_Comm_size (comm, &nproc);
50 MPI_Comm_rank (comm, &rank);
52 MPI_Datatype MPI_valueType, MPI_distanceType;
53 MPI_Type_contiguous (
sizeof(_ValueType), MPI_CHAR, &MPI_valueType);
54 MPI_Type_commit (&MPI_valueType);
55 MPI_Type_contiguous (
sizeof(_Distance), MPI_CHAR, &MPI_distanceType);
56 MPI_Type_commit (&MPI_distanceType);
58 _Distance *dist =
new _Distance[nproc];
59 for (
int i=0; i<nproc; ++i) dist[i] = (_Distance) dist_in[i];
65 mysort.
seqsort (first, last, comp);
69 MPI_Type_free(&MPI_valueType);
70 MPI_Type_free(&MPI_distanceType);
78 vector< vector<_Distance> > right_ends(nproc + 1, vector<_Distance>(nproc, 0));
80 mysplit.
split (first, last, dist, comp, right_ends,
81 MPI_valueType, MPI_distanceType, comm);
84 progress (rank, 2, const_cast<char *>(
string(
"alltoall").c_str()), comm);
85 _Distance n_loc = last - first;
86 _ValueType *trans_data =
new _ValueType[n_loc];
87 _Distance *boundaries =
new _Distance[nproc+1];
88 alltoall (right_ends, first, last,
89 trans_data, boundaries,
90 MPI_valueType, MPI_distanceType, comm);
94 mymerge.
merge (trans_data, first, boundaries, nproc, comp);
99 MPI_Type_free (&MPI_valueType);
100 MPI_Type_free (&MPI_distanceType);
103 progress (rank, 4, const_cast<char *>(
string(
"finish").c_str()), comm);
108 template<
typename _RandomAccessIter,
typename _Compare>
110 _RandomAccessIter last,
111 _Compare comp,
long *dist, MPI_Comm comm) {
117 parallel_sort (first, last, comp, dist, mysort, mysplit, mymerge, comm);
120 template<
typename _RandomAccessIter>
122 _RandomAccessIter last,
123 long *dist, MPI_Comm comm) {
125 typedef typename iterator_traits<_RandomAccessIter>::value_type _ValueType;
132 dist, mysort, mysplit, mymerge, comm);
void parallel_sort(_RandomAccessIter first, _RandomAccessIter last, _Compare comp, long *dist_in, SeqSort< _SeqSortType > &mysort, Split< _SplitType > &mysplit, Merge< _MergeType > &mymerge, MPI_Comm comm)
void seqsort(_ValueType *first, _ValueType *last, _Compare comp)
void merge(_ValueType *in, _ValueType *out, _Distance *disps, int nproc, _Compare comp)
void split(_RandomAccessIter first, _RandomAccessIter last, _Distance *dist, _Compare comp, vector< vector< _Distance > > &right_ends, MPI_Datatype &MPI_valueType, MPI_Datatype &MPI_distanceType, MPI_Comm comm)