mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: cleaner separation of global and local world naming
- UPstream::globalComm constant always refers to MPI_COMM_WORLD but UPstream::worldComm could be MPI_COMM_WORLD (single world) or a dedicated local communicator (for multi-world). - provide a Pstream wrapped version of MPI_COMM_SELF, references as UPstream::selfComm - UPstream::isUserComm(label) test for additional user-defined communicators
This commit is contained in:
committed by
Andrew Heather
parent
7fe8bdcf99
commit
ffeef76d8f
3
applications/test/parallel-comm1/Make/files
Normal file
3
applications/test/parallel-comm1/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-parallel-comm1.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-parallel-comm1
|
||||
2
applications/test/parallel-comm1/Make/options
Normal file
2
applications/test/parallel-comm1/Make/options
Normal file
@ -0,0 +1,2 @@
|
||||
/* EXE_INC = */
|
||||
/* EXE_LIBS = */
|
||||
185
applications/test/parallel-comm1/Test-parallel-comm1.C
Normal file
185
applications/test/parallel-comm1/Test-parallel-comm1.C
Normal file
@ -0,0 +1,185 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2013-2017 OpenFOAM Foundation
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-parallel-communicators
|
||||
|
||||
Description
|
||||
Checks communication using user-defined communicators
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "Time.H"
|
||||
#include "IPstream.H"
|
||||
#include "OPstream.H"
|
||||
#include "vector.H"
|
||||
#include "IOstreams.H"
|
||||
#include "PstreamReduceOps.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
scalar sumReduce
|
||||
(
|
||||
const label comm,
|
||||
const scalar localValue
|
||||
)
|
||||
{
|
||||
scalar sum = 0;
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
if (UPstream::master(comm))
|
||||
{
|
||||
// Add master value and all slaves
|
||||
sum = localValue;
|
||||
|
||||
for (const int slave : UPstream::subProcs(comm))
|
||||
{
|
||||
scalar slaveValue;
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::commsTypes::blocking,
|
||||
slave,
|
||||
reinterpret_cast<char*>(&slaveValue),
|
||||
sizeof(scalar),
|
||||
UPstream::msgType(), // tag
|
||||
comm // communicator
|
||||
);
|
||||
|
||||
sum += slaveValue;
|
||||
}
|
||||
|
||||
// Send back to slaves
|
||||
|
||||
for (const int slave : UPstream::subProcs(comm))
|
||||
{
|
||||
UOPstream::write
|
||||
(
|
||||
UPstream::commsTypes::blocking,
|
||||
slave,
|
||||
reinterpret_cast<const char*>(&sum),
|
||||
sizeof(scalar),
|
||||
UPstream::msgType(), // tag
|
||||
comm // communicator
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
UOPstream::write
|
||||
(
|
||||
UPstream::commsTypes::blocking,
|
||||
UPstream::masterNo(),
|
||||
reinterpret_cast<const char*>(&localValue),
|
||||
sizeof(scalar),
|
||||
UPstream::msgType(), // tag
|
||||
comm // communicator
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
UIPstream::read
|
||||
(
|
||||
UPstream::commsTypes::blocking,
|
||||
UPstream::masterNo(),
|
||||
reinterpret_cast<char*>(&sum),
|
||||
sizeof(scalar),
|
||||
UPstream::msgType(), // tag
|
||||
comm // communicator
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
#include "setRootCase.H"
|
||||
#include "createTime.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Allocate a communicator
|
||||
label n = Pstream::nProcs(UPstream::worldComm);
|
||||
|
||||
DynamicList<label> bottom;
|
||||
DynamicList<label> top;
|
||||
|
||||
for (label i = 0; i < n/2; i++)
|
||||
{
|
||||
bottom.append(i);
|
||||
}
|
||||
for (label i = n/2; i < n; i++)
|
||||
{
|
||||
top.append(i);
|
||||
}
|
||||
|
||||
//Pout<< "bottom:" << bottom << endl;
|
||||
Pout<< "top :" << top << endl;
|
||||
|
||||
|
||||
scalar localValue = 111*UPstream::myProcNo(UPstream::worldComm);
|
||||
Pout<< "localValue :" << localValue << endl;
|
||||
|
||||
|
||||
label comm = Pstream::allocateCommunicator
|
||||
(
|
||||
UPstream::worldComm,
|
||||
top
|
||||
);
|
||||
|
||||
Pout<< "allocated comm :" << comm << endl;
|
||||
Pout<< "comm myproc :" << Pstream::myProcNo(comm)
|
||||
<< endl;
|
||||
|
||||
|
||||
if (Pstream::myProcNo(comm) != -1)
|
||||
{
|
||||
scalar sum = returnReduce
|
||||
(
|
||||
localValue,
|
||||
sumOp<scalar>(),
|
||||
UPstream::msgType(),
|
||||
comm
|
||||
);
|
||||
Pout<< "sum :" << sum << endl;
|
||||
}
|
||||
|
||||
Pstream::freeCommunicator(comm);
|
||||
|
||||
|
||||
Pout<< "End\n" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user