Commit ef882e54 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: zero initialize memory for Pstream send (issue #814)

- this avoids some valgrind messages

      "Uninitialised byte(s) found during client check request"
parent 6d89a3ec
......@@ -27,11 +27,7 @@ License
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
namespace Foam
{
DynamicList<char> PstreamBuffers::nullBuf(0);
}
Foam::DynamicList<char> Foam::PstreamBuffers::nullBuf(0);
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
......@@ -52,7 +48,7 @@ Foam::PstreamBuffers::PstreamBuffers
version_(version),
sendBuf_(UPstream::nProcs(comm)),
recvBuf_(UPstream::nProcs(comm)),
recvBufPos_(UPstream::nProcs(comm), 0),
recvBufPos_(UPstream::nProcs(comm), 0),
finishedSendsCalled_(false)
{}
......@@ -131,13 +127,13 @@ void Foam::PstreamBuffers::finishedSends(labelList& recvSizes, const bool block)
void Foam::PstreamBuffers::clear()
{
forAll(sendBuf_, i)
for (DynamicList<char>& buf : sendBuf_)
{
sendBuf_[i].clear();
buf.clear();
}
forAll(recvBuf_, i)
for (DynamicList<char>& buf : recvBuf_)
{
recvBuf_[i].clear();
buf.clear();
}
recvBufPos_ = 0;
finishedSendsCalled_ = false;
......
......@@ -34,30 +34,31 @@ Description
explicit buffers.
Example usage:
\code
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);
PstreamBuffers pBuffers(Pstream::commsTypes::nonBlocking);
for (label proci = 0; proci < Pstream::nProcs(); proci++)
for (label proci = 0; proci < Pstream::nProcs(); ++proci)
{
if (proci != Pstream::myProcNo())
{
someObject vals;
UOPstream str(proci, pBuffers);
str << vals;
UOPstream send(proci, pBufs);
send << vals;
}
}
pBuffers.finishedSends(); // no-op for blocking
pBufs.finishedSends(); // no-op for blocking
for (label proci = 0; proci < Pstream::nProcs(); proci++)
for (label proci = 0; proci < Pstream::nProcs(); ++proci)
{
if (proci != Pstream::myProcNo())
{
UIPstream str(proci, pBuffers);
someObject vals(str);
UIPstream recv(proci, pBufs);
someObject vals(recv);
}
}
\endcode
SourceFiles
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -53,8 +53,8 @@ inline void Foam::UOPstream::prepareBuffer
// Extend buffer (as required)
sendBuf_.reserve(max(1000, label(pos + count)));
// Move to the aligned output position
sendBuf_.setSize(pos);
// Move to the aligned output position. Fill any gap with nul char.
sendBuf_.resize(pos, '\0');
}
......@@ -93,7 +93,7 @@ inline void Foam::UOPstream::writeToBuffer
const label pos = sendBuf_.size();
// Extend the addressable range for direct pointer access
sendBuf_.setSize(pos + count);
sendBuf_.resize(pos + count);
char* const __restrict__ buf = (sendBuf_.begin() + pos);
const char* const __restrict__ input = reinterpret_cast<const char*>(data);
......
......@@ -212,7 +212,7 @@ void Foam::Pstream::exchange
// Presize all receive buffers
forAll(recvSizes, proci)
{
label nRecv = recvSizes[proci];
const label nRecv = recvSizes[proci];
if (proci != Pstream::myProcNo(comm) && nRecv > 0)
{
......
......@@ -25,49 +25,22 @@ License
#include "PstreamGlobals.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// Outstanding non-blocking operations.
//! \cond fileScope
DynamicList<MPI_Request> PstreamGlobals::outstandingRequests_;
//! \endcond
//// Max outstanding non-blocking operations.
////! \cond fileScope
//int PstreamGlobals::nRequests_ = 0;
////! \endcond
Foam::DynamicList<MPI_Request> Foam::PstreamGlobals::outstandingRequests_;
// Free'd non-blocking operations.
//! \cond fileScope
//DynamicList<label> PstreamGlobals::freedRequests_;
//! \endcond
int Foam::PstreamGlobals::nTags_ = 0;
// Max outstanding message tag operations.
//! \cond fileScope
int PstreamGlobals::nTags_ = 0;
//! \endcond
Foam::DynamicList<int> Foam::PstreamGlobals::freedTags_;
// Free'd message tags
//! \cond fileScope
DynamicList<int> PstreamGlobals::freedTags_;
//! \endcond
Foam::DynamicList<MPI_Comm> Foam::PstreamGlobals::MPICommunicators_;
Foam::DynamicList<MPI_Group> Foam::PstreamGlobals::MPIGroups_;
// Allocated communicators.
//! \cond fileScope
DynamicList<MPI_Comm> PstreamGlobals::MPICommunicators_;
DynamicList<MPI_Group> PstreamGlobals::MPIGroups_;
//! \endcond
void PstreamGlobals::checkCommunicator
void Foam::PstreamGlobals::checkCommunicator
(
const label comm,
const label otherProcNo
const label toProcNo
)
{
if
......@@ -77,16 +50,13 @@ void PstreamGlobals::checkCommunicator
)
{
FatalErrorInFunction
<< "otherProcNo:" << otherProcNo << " : illegal communicator "
<< comm << endl
<< "Communicator should be within range 0.."
<< PstreamGlobals::MPICommunicators_.size()-1 << abort(FatalError);
<< "toProcNo:" << toProcNo << " : illegal communicator "
<< comm << nl
<< "Communicator should be within range [0,"
<< PstreamGlobals::MPICommunicators_.size()
<< ')' << abort(FatalError);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -37,36 +37,30 @@ SourceFiles
#define PstreamGlobals_H
#include "DynamicList.H"
#include <mpi.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class PstreamGlobals Declaration
\*---------------------------------------------------------------------------*/
namespace PstreamGlobals
{
//- Outstanding non-blocking operations.
extern DynamicList<MPI_Request> outstandingRequests_;
//extern int nRequests_;
//extern DynamicList<label> freedRequests_;
//- Max outstanding message tag operations.
extern int nTags_;
//- Free'd message tags
extern DynamicList<int> freedTags_;
// Current communicators. First element will be MPI_COMM_WORLD
extern DynamicList<MPI_Comm> MPICommunicators_;
extern DynamicList<MPI_Group> MPIGroups_;
void checkCommunicator(const label, const label procNo);
void checkCommunicator(const label comm, const label toProcNo);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment