From ea8d2901917cf8b4df23f030c79af416b39cc3ee Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 4 Feb 2013 10:17:37 +0000 Subject: [PATCH] ENH: communicators: initial version - extended Pstream API --- .../Test-parallel-communicators.C | 63 ++--- .../extrude/extrudeMesh/extrudeMesh.C | 1 + .../decomposePar/domainDecomposition.C | 2 + etc/bashrc | 2 +- etc/cshrc | 2 +- .../IOobjects/IOdictionary/IOdictionaryIO.C | 5 +- src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C | 2 + src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H | 1 + src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C | 3 +- src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H | 1 + src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H | 65 +++-- .../db/IOstreams/Pstreams/PstreamBuffers.C | 16 +- .../db/IOstreams/Pstreams/PstreamBuffers.H | 3 + .../Pstreams/PstreamCombineReduceOps.H | 42 ++- .../db/IOstreams/Pstreams/PstreamReduceOps.H | 65 +++-- .../db/IOstreams/Pstreams/UIPstream.C | 4 +- .../db/IOstreams/Pstreams/UIPstream.H | 6 +- .../db/IOstreams/Pstreams/UOPstream.C | 9 +- .../db/IOstreams/Pstreams/UOPstream.H | 6 +- src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C | 187 +++++++++++-- src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H | 179 ++++++++++--- .../IOstreams/Pstreams/combineGatherScatter.C | 250 ++++++++++++++---- src/OpenFOAM/db/IOstreams/Pstreams/exchange.C | 27 +- .../db/IOstreams/Pstreams/gatherScatter.C | 68 +++-- .../db/IOstreams/Pstreams/gatherScatterList.C | 78 ++++-- src/OpenFOAM/db/regIOobject/regIOobjectRead.C | 5 +- .../LUscalarMatrix/procLduInterface.C | 10 +- .../LUscalarMatrix/procLduInterface.H | 3 +- .../lduInterface/processorLduInterface.H | 7 +- .../processorLduInterfaceTemplates.C | 24 +- .../processorLduInterfaceField.H | 3 + .../processorGAMGInterfaceField.H | 6 + .../processorGAMGInterface.H | 8 +- .../ProcessorTopology/ProcessorTopology.C | 16 +- .../ProcessorTopology/ProcessorTopology.H | 4 +- .../polyMesh/globalMeshData/globalMeshData.C | 2 +- .../mapPolyMesh/mapDistribute/mapDistribute.C | 6 +- .../constraint/processor/processorPolyPatch.C | 14 + .../constraint/processor/processorPolyPatch.H | 11 + .../processorCyclicPolyPatch.C | 2 + .../processorCyclicPolyPatch.H | 1 + src/Pstream/dummy/UIPread.C | 16 +- src/Pstream/dummy/UOPwrite.C | 6 +- src/Pstream/dummy/UPstream.C | 27 +- src/Pstream/mpi/PstreamGlobals.C | 31 ++- src/Pstream/mpi/PstreamGlobals.H | 11 +- src/Pstream/mpi/UIPread.C | 27 +- src/Pstream/mpi/UOPwrite.C | 21 +- src/Pstream/mpi/UPstream.C | 201 ++++++++++++-- src/Pstream/mpi/allReduce.H | 3 +- src/Pstream/mpi/allReduceTemplates.C | 39 +-- .../fvMeshDistribute/fvMeshDistribute.C | 2 + .../processor/processorFvPatchField.C | 26 +- .../processor/processorFvPatchField.H | 6 + .../processor/processorFvPatchScalarField.C | 10 +- .../constraint/processor/processorFvPatch.H | 10 +- 56 files changed, 1250 insertions(+), 395 deletions(-) diff --git a/applications/test/parallel-communicators/Test-parallel-communicators.C b/applications/test/parallel-communicators/Test-parallel-communicators.C index e5c4b99648..2b9277fb6e 100644 --- a/applications/test/parallel-communicators/Test-parallel-communicators.C +++ b/applications/test/parallel-communicators/Test-parallel-communicators.C @@ -150,45 +150,48 @@ int main(int argc, char *argv[]) top.append(i); } - Pout<< "bottom:" << bottom << endl; - Pout<< "top:" << top << endl; + //Pout<< "bottom:" << bottom << endl; + Pout<< "top :" << top << endl; scalar localValue = 111*UPstream::myProcNo(UPstream::worldComm); - Pout<< "localValue:" << localValue << endl; + Pout<< "localValue :" << localValue << endl; - if (Pstream::myProcNo(UPstream::worldComm) < n/2) + + label comm = Pstream::allocateCommunicator + ( + UPstream::worldComm, + top + ); + + Pout<< "allocated comm :" << comm << endl; + Pout<< "comm myproc :" << Pstream::myProcNo(comm) + << endl; + + + if (Pstream::myProcNo(comm) != -1) { - label comm = Pstream::allocateCommunicator + //scalar sum = sumReduce(comm, localValue); + //scalar sum = localValue; + //reduce + //( + // UPstream::treeCommunication(comm), + // sum, + // sumOp(), + // Pstream::msgType(), + // comm + //); + scalar sum = returnReduce ( - UPstream::worldComm, - bottom + localValue, + sumOp(), + Pstream::msgType(), + comm ); - - Pout<< "allocated bottom comm:" << comm << endl; - Pout<< "comm myproc :" << Pstream::myProcNo(comm) - << endl; - scalar sum = sumReduce(comm, localValue); - Pout<< "sum :" << sum << endl; - - Pstream::freeCommunicator(comm); + Pout<< "sum :" << sum << endl; } - else - { - label comm = Pstream::allocateCommunicator - ( - UPstream::worldComm, - top - ); - Pout<< "allocated top comm:" << comm << endl; - Pout<< "comm myproc :" << Pstream::myProcNo(comm) - << endl; - scalar sum = sumReduce(comm, localValue); - Pout<< "sum :" << sum << endl; - - Pstream::freeCommunicator(comm); - } + Pstream::freeCommunicator(comm); Pout<< "End\n" << endl; diff --git a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C index bafe305504..6e6c02546d 100644 --- a/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C +++ b/applications/utilities/mesh/generation/extrude/extrudeMesh/extrudeMesh.C @@ -496,6 +496,7 @@ int main(int argc, char *argv[]) mesh.nFaces(), // start patchI, // index mesh.boundaryMesh(),// polyBoundaryMesh + Pstream::worldComm, // communicator Pstream::myProcNo(),// myProcNo nbrProcI // neighbProcNo ) diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C index f5dabf6077..04e1c18685 100644 --- a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C +++ b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C @@ -448,6 +448,7 @@ bool Foam::domainDecomposition::writeDecomposition() curStart, nPatches, procMesh.boundaryMesh(), + Pstream::worldComm, procI, curNeighbourProcessors[procPatchI] ); @@ -475,6 +476,7 @@ bool Foam::domainDecomposition::writeDecomposition() curStart, nPatches, procMesh.boundaryMesh(), + Pstream::worldComm, procI, curNeighbourProcessors[procPatchI], referPatch, diff --git a/etc/bashrc b/etc/bashrc index f077631ac8..79cf4f47d8 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -32,7 +32,7 @@ #------------------------------------------------------------------------------ export WM_PROJECT=OpenFOAM -export WM_PROJECT_VERSION=dev +export WM_PROJECT_VERSION=dev.procAgglom ################################################################################ # USER EDITABLE PART: Changes made here may be lost with the next upgrade diff --git a/etc/cshrc b/etc/cshrc index 6b5eb16632..6453413b38 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -31,7 +31,7 @@ #------------------------------------------------------------------------------ setenv WM_PROJECT OpenFOAM -setenv WM_PROJECT_VERSION dev +setenv WM_PROJECT_VERSION dev.procAgglom ################################################################################ # USER EDITABLE PART: Changes made here may be lost with the next upgrade diff --git a/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionaryIO.C b/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionaryIO.C index e620b3b942..39dd109366 100644 --- a/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionaryIO.C +++ b/src/OpenFOAM/db/IOobjects/IOdictionary/IOdictionaryIO.C @@ -78,9 +78,10 @@ void Foam::IOdictionary::readFile(const bool masterOnly) ( comms, const_cast(headerClassName()), - Pstream::msgType() + Pstream::msgType(), + Pstream::worldComm ); - Pstream::scatter(comms, note(), Pstream::msgType()); + Pstream::scatter(comms, note(), Pstream::msgType(), Pstream::worldComm); // Get my communication order const Pstream::commsStruct& myComm = comms[Pstream::myProcNo()]; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C index 1431585bfd..6871c3ff65 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C @@ -33,6 +33,7 @@ Foam::IPstream::IPstream const int fromProcNo, const label bufSize, const int tag, + const label comm, streamFormat format, versionNumber version ) @@ -45,6 +46,7 @@ Foam::IPstream::IPstream buf_, externalBufPosition_, tag, // tag + comm, false, // do not clear buf_ if at end format, version diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H index eb236a0c78..3a0047df1a 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H @@ -69,6 +69,7 @@ public: const int fromProcNo, const label bufSize = 0, const int tag = UPstream::msgType(), + const label comm = UPstream::worldComm, streamFormat format=BINARY, versionNumber version=currentVersion ); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C index 233fd10f6e..a9fccf4f1b 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C @@ -33,12 +33,13 @@ Foam::OPstream::OPstream const int toProcNo, const label bufSize, const int tag, + const label comm, streamFormat format, versionNumber version ) : Pstream(commsType, bufSize), - UOPstream(commsType, toProcNo, buf_, tag, true, format, version) + UOPstream(commsType, toProcNo, buf_, tag, comm, true, format, version) {} diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H index edc8dce488..2abff736b4 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H @@ -66,6 +66,7 @@ public: const int toProcNo, const label bufSize = 0, const int tag = UPstream::msgType(), + const label comm = UPstream::worldComm, streamFormat format=BINARY, versionNumber version=currentVersion ); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H index 9f39306ccc..0fcd546582 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H @@ -98,7 +98,8 @@ public: const List& comms, T& Value, const BinaryOp& bop, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication @@ -107,7 +108,8 @@ public: ( T& Value, const BinaryOp& bop, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = Pstream::worldComm ); //- Scatter data. Distribute without modification. Reverse of gather @@ -116,12 +118,18 @@ public: ( const List& comms, T& Value, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication template - static void scatter(T& Value, const int tag = Pstream::msgType()); + static void scatter + ( + T& Value, + const int tag = Pstream::msgType(), + const label comm = Pstream::worldComm + ); // Combine variants. Inplace combine values from processors. @@ -133,7 +141,8 @@ public: const List& comms, T& Value, const CombineOp& cop, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication @@ -142,7 +151,8 @@ public: ( T& Value, const CombineOp& cop, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = Pstream::worldComm ); //- Scatter data. Reverse of combineGather @@ -151,7 +161,8 @@ public: ( const List& comms, T& Value, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication @@ -159,7 +170,8 @@ public: static void combineScatter ( T& Value, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = Pstream::worldComm ); // Combine variants working on whole List at a time. @@ -170,7 +182,8 @@ public: const List& comms, List& Value, const CombineOp& cop, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication @@ -179,7 +192,8 @@ public: ( List& Value, const CombineOp& cop, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = Pstream::worldComm ); //- Scatter data. Reverse of combineGather @@ -188,7 +202,8 @@ public: ( const List& comms, List& Value, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication @@ -196,7 +211,8 @@ public: static void listCombineScatter ( List& Value, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = Pstream::worldComm ); // Combine variants working on whole map at a time. Container needs to @@ -208,7 +224,8 @@ public: const List& comms, Container& Values, const CombineOp& cop, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication @@ -217,7 +234,8 @@ public: ( Container& Values, const CombineOp& cop, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = UPstream::worldComm ); //- Scatter data. Reverse of combineGather @@ -226,7 +244,8 @@ public: ( const List& comms, Container& Values, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication @@ -234,7 +253,8 @@ public: static void mapCombineScatter ( Container& Values, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = UPstream::worldComm ); @@ -249,7 +269,8 @@ public: ( const List& comms, List& Values, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication @@ -257,7 +278,8 @@ public: static void gatherList ( List& Values, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = UPstream::worldComm ); //- Scatter data. Reverse of gatherList @@ -266,7 +288,8 @@ public: ( const List& comms, List& Values, - const int tag + const int tag, + const label comm ); //- Like above but switches between linear/tree communication @@ -274,7 +297,8 @@ public: static void scatterList ( List& Values, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = UPstream::worldComm ); @@ -291,6 +315,7 @@ public: List&, labelListList& sizes, const int tag = UPstream::msgType(), + const label comm = UPstream::worldComm, const bool block = true ); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C index 24eec63c35..cbb62ae55c 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C @@ -40,17 +40,19 @@ Foam::PstreamBuffers::PstreamBuffers ( const UPstream::commsTypes commsType, const int tag, + const label comm, IOstream::streamFormat format, IOstream::versionNumber version ) : commsType_(commsType), tag_(tag), + comm_(comm), format_(format), version_(version), - sendBuf_(UPstream::nProcs()), - recvBuf_(UPstream::nProcs()), - recvBufPos_(UPstream::nProcs(), 0), + sendBuf_(UPstream::nProcs(comm)), + recvBuf_(UPstream::nProcs(comm)), + recvBufPos_(UPstream::nProcs(comm), 0), finishedSendsCalled_(false) {} @@ -90,6 +92,7 @@ void Foam::PstreamBuffers::finishedSends(const bool block) recvBuf_, sizes, tag_, + comm_, block ); } @@ -108,6 +111,7 @@ void Foam::PstreamBuffers::finishedSends(labelListList& sizes, const bool block) recvBuf_, sizes, tag_, + comm_, block ); } @@ -123,9 +127,9 @@ void Foam::PstreamBuffers::finishedSends(labelListList& sizes, const bool block) // Note: possible only if using different tag from write started // by ~UOPstream. Needs some work. - //sizes.setSize(UPstream::nProcs()); - //labelList& nsTransPs = sizes[UPstream::myProcNo()]; - //nsTransPs.setSize(UPstream::nProcs()); + //sizes.setSize(UPstream::nProcs(comm)); + //labelList& nsTransPs = sizes[UPstream::myProcNo(comm)]; + //nsTransPs.setSize(UPstream::nProcs(comm)); // //forAll(sendBuf_, procI) //{ diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H index 0b88a644f0..da6cb21acc 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H @@ -95,6 +95,8 @@ class PstreamBuffers const int tag_; + const label comm_; + const IOstream::streamFormat format_; const IOstream::versionNumber version_; @@ -127,6 +129,7 @@ public: ( const UPstream::commsTypes commsType, const int tag = UPstream::msgType(), + const label comm = UPstream::worldComm, IOstream::streamFormat format=IOstream::BINARY, IOstream::versionNumber version=IOstream::currentVersion ); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H index c657e0a140..4a2985ef3a 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamCombineReduceOps.H @@ -53,11 +53,12 @@ void combineReduce const List& comms, T& Value, const CombineOp& cop, - const int tag + const int tag, + const label comm ) { - Pstream::combineGather(comms, Value, cop, tag); - Pstream::combineScatter(comms, Value, tag); + Pstream::combineGather(comms, Value, cop, tag, comm); + Pstream::combineScatter(comms, Value, tag, comm); } @@ -66,24 +67,45 @@ void combineReduce ( T& Value, const CombineOp& cop, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = Pstream::worldComm ) { - if (UPstream::nProcs() < UPstream::nProcsSimpleSum) + if (UPstream::nProcs(comm) < UPstream::nProcsSimpleSum) { Pstream::combineGather ( - UPstream::linearCommunication(), + UPstream::linearCommunication(comm), Value, cop, - tag + tag, + comm + ); + Pstream::combineScatter + ( + UPstream::linearCommunication(comm), + Value, + tag, + comm ); - Pstream::combineScatter(UPstream::linearCommunication(), Value, tag); } else { - Pstream::combineGather(UPstream::treeCommunication(), Value, cop, tag); - Pstream::combineScatter(UPstream::treeCommunication(), Value, tag); + Pstream::combineGather + ( + UPstream::treeCommunication(comm), + Value, + cop, + tag, + comm + ); + Pstream::combineScatter + ( + UPstream::treeCommunication(comm), + Value, + tag, + comm + ); } } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H index 47c7c51acd..bd8f5ab1dc 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamReduceOps.H @@ -44,11 +44,12 @@ void reduce const List& comms, T& Value, const BinaryOp& bop, - const int tag + const int tag, + const label comm ) { - Pstream::gather(comms, Value, bop, tag); - Pstream::scatter(comms, Value, tag); + Pstream::gather(comms, Value, bop, tag, comm); + Pstream::scatter(comms, Value, tag, comm); } @@ -58,16 +59,17 @@ void reduce ( T& Value, const BinaryOp& bop, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = UPstream::worldComm ) { - if (UPstream::nProcs() < UPstream::nProcsSimpleSum) + if (UPstream::nProcs(comm) < UPstream::nProcsSimpleSum) { - reduce(UPstream::linearCommunication(), Value, bop, tag); + reduce(UPstream::linearCommunication(comm), Value, bop, tag, comm); } else { - reduce(UPstream::treeCommunication(), Value, bop, tag); + reduce(UPstream::treeCommunication(comm), Value, bop, tag, comm); } } @@ -78,18 +80,33 @@ T returnReduce ( const T& Value, const BinaryOp& bop, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = UPstream::worldComm ) { T WorkValue(Value); - if (UPstream::nProcs() < UPstream::nProcsSimpleSum) + if (UPstream::nProcs(comm) < UPstream::nProcsSimpleSum) { - reduce(UPstream::linearCommunication(), WorkValue, bop, tag); + reduce + ( + UPstream::linearCommunication(comm), + WorkValue, + bop, + tag, + comm + ); } else { - reduce(UPstream::treeCommunication(), WorkValue, bop, tag); + reduce + ( + UPstream::treeCommunication(comm), + WorkValue, + bop, + tag, + comm + ); } return WorkValue; @@ -102,11 +119,12 @@ void sumReduce ( T& Value, label& Count, - const int tag = Pstream::msgType() + const int tag = Pstream::msgType(), + const label comm = UPstream::worldComm ) { - reduce(Value, sumOp(), tag); - reduce(Count, sumOp