/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 .
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
#include "IFstream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
Type Foam::fileOperations::masterUncollatedFileOperation::scatterList
(
const UList& masterLst,
const int tag,
const label comm
) const
{
// TBD: more efficient scatter
PstreamBuffers pBufs(UPstream::commsTypes::nonBlocking, tag, comm);
if (Pstream::master(comm))
{
for (label proci = 1; proci < Pstream::nProcs(comm); proci++)
{
UOPstream os(proci, pBufs);
os << masterLst[proci];
}
}
pBufs.finishedSends();
Type myResult;
if (Pstream::master(comm))
{
myResult = masterLst[Pstream::myProcNo(comm)];
}
else
{
UIPstream is(Pstream::masterNo(), pBufs);
is >> myResult;
}
return myResult;
}
template
Type Foam::fileOperations::masterUncollatedFileOperation::masterOp
(
const fileName& fName,
const fileOp& fop,
const int tag,
const label comm
) const
{
if (IFstream::debug)
{
Pout<< "masterUncollatedFileOperation::masterOp : Operation "
<< typeid(fileOp).name()
<< " on " << fName << endl;
}
if (Pstream::parRun())
{
List filePaths(Pstream::nProcs(comm));
filePaths[Pstream::myProcNo(comm)] = fName;
Pstream::gatherList(filePaths, tag, comm);
List result(filePaths.size());
if (Pstream::master(comm))
{
result = fop(filePaths[0]);
for (label i = 1; i < filePaths.size(); i++)
{
if (filePaths[i] != filePaths[0])
{
result[i] = fop(filePaths[i]);
}
}
}
return scatterList(result, tag, comm);
}
else
{
return fop(fName);
}
}
template
Type Foam::fileOperations::masterUncollatedFileOperation::masterOp
(
const fileName& src,
const fileName& dest,
const fileOp& fop,
const int tag,
const label comm
) const
{
if (IFstream::debug)
{
Pout<< "masterUncollatedFileOperation : Operation on src:" << src
<< " dest:" << dest << endl;
}
if (Pstream::parRun())
{
List srcs(Pstream::nProcs(comm));
srcs[Pstream::myProcNo(comm)] = src;
Pstream::gatherList(srcs, tag, comm);
List dests(srcs.size());
dests[Pstream::myProcNo(comm)] = dest;
Pstream::gatherList(dests, tag, comm);
List result(Pstream::nProcs(comm));
if (Pstream::master(comm))
{
result = fop(srcs[0], dests[0]);
for (label i = 1; i < srcs.size(); i++)
{
if (srcs[i] != srcs[0])
{
result[i] = fop(srcs[i], dests[i]);
}
}
}
return scatterList(result, tag, comm);
}
else
{
return fop(src, dest);
}
}
// ************************************************************************* //