38void Foam::ParSortableList<Type>::write
40 const List<Type>& elems,
48 os <<
' ' << elems[elemI];
55void Foam::ParSortableList<Type>::copyInto
57 const List<Type>& values,
58 const labelList& indices,
59 const label fromProcNo,
61 List<taggedValue>& dest
66 taggedValue& tagVal = dest[destI];
68 tagVal.value() =
values[elemI];
69 tagVal.index() = indices[elemI];
70 tagVal.procID() = fromProcNo;
78void Foam::ParSortableList<Type>::getPivots
80 const List<Type>& elems,
84 pivots.setSize(Pstream::nProcs());
90 pivots[pivotI] = elems[pivotPos];
92 pivotPos += elems.size()/Pstream::nProcs();
98void Foam::ParSortableList<Type>::checkAndSend
103 const label destProci
106 if (destProci != Pstream::myProcNo())
109 indices.setSize(bufSize);
113 Pout<<
"Sending to " << destProci <<
" elements:" <<
values
118 OPstream toProc(UPstream::commsTypes::buffered, destProci);
119 toProc <<
values << indices;
156 label
n = this->size();
169 getPivots(sorted, pivots);
183 Pstream::gatherList(sortedGatherList);
185 if (Pstream::master())
187 labelList allPivots =
188 ListListOps::combine<labelList>
191 accessOp<labelList>()
194 SortableList<Type> sortedPivots(allPivots);
199 write(allPivots, Pout);
203 getPivots(sortedPivots, pivots);
205 Pstream::broadcast(pivots);
209 Pout<<
"new pivots:";
234 if ((pivotI < Pstream::nProcs()) && (sorted[sortedI] > pivots[pivotI]))
236 checkAndSend(sendValues, sendIndices, sendI, destProci);
239 sendValues.setSize(sorted.size());
240 sendIndices.setSize(sorted.size());
247 if (destProci != Pstream::myProcNo())
249 sendValues[sendI] = sorted[sortedI];
250 sendIndices[sendI] = sorted.indices()[sortedI];
255 ownValues[ownI] = sorted[sortedI];
256 ownIndices[ownI] = sorted.indices()[sortedI];
265 checkAndSend(sendValues, sendIndices, sendI, destProci);
269 ownValues.setSize(ownI);
270 ownIndices.setSize(ownI);
274 Pout<<
"Not sending (to myself) elements "
275 << ownValues <<
endl;
285 List<taggedValue> combinedValues(2 *
n/Pstream::nProcs());
289 for (
const int proci : Pstream::allProcs())
291 if (proci == Pstream::myProcNo())
295 Pout<<
"Copying from own:" << ownValues <<
endl;
299 copyInto(ownValues, ownIndices, proci, combinedI, combinedValues);
309 Pout<<
"Receiving from " << proci <<
endl;
312 IPstream fromProc(UPstream::commsTypes::buffered, proci);
314 fromProc >> recValues >> recIndices;
318 Pout<<
"Received from " << proci
319 <<
" elements:" << recValues <<
endl;
325 Pout<<
"Copying starting at:" << combinedI <<
endl;
327 copyInto(recValues, recIndices, proci, combinedI, combinedValues);
330 combinedValues.setSize(combinedI);
337 indices_.setSize(combinedI);
338 procs_.setSize(combinedI);
340 forAll(combinedValues, elemI)
342 this->operator[](elemI) = combinedValues[elemI].value();
343 indices_[elemI] = combinedValues[elemI].index();
344 procs_[elemI] = combinedValues[elemI].procID();
Inter-processor communication reduction functions.
Input inter-processor communications stream.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void setSize(label n)
Alias for resize().
void sort()
(stable) sort the list (if changed after construction time)
ParSortableList(const UList< Type > &)
Construct from List, sorting the elements.
A list that is sorted upon construction or when explicitly requested with the sort() method.
const labelList & indices() const noexcept
Return the list of sorted indices. Updated every sort.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Type & operator[](const label i)
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
@ buffered
"buffered" : (MPI_Bsend, MPI_Recv)
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
@ gatherList
gatherList [manual algorithm]
@ broadcast
broadcast [MPI]
OBJstream os(runTime.globalPath()/outputName)
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Namespace for handling debugging switches.
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
void sort(UList< T > &list)
Sort the list.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
points setSize(newPointi)
#define forAll(list, i)
Loop across all elements in list.
Object access operator or list access operator (default is pass-through).