mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: UOPstream indexes out of bounds after whitespace stripping (fixes #134)
- only affects transfer of C-style string with a single character
remaining after whitespace stripping. Test added into Test-parallel.
- Note some idiosyncrasies in the behaviour:
send | receives
-------------------------+-------------------------
string("a b c") | string "a b c"
string("a") | string "a"
"a b c" | word "abc"
'd' | char 'd'
"d" | char 'd'
"d " | char 'd'
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -42,19 +42,8 @@ Description
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
#include "setRootCase.H"
|
||||
#include "createTime.H"
|
||||
|
||||
|
||||
// Test mapDistribute
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
if (true)
|
||||
void testMapDistribute()
|
||||
{
|
||||
Random rndGen(43544*Pstream::myProcNo());
|
||||
|
||||
@ -71,7 +60,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Send all ones to processor indicated by .first()
|
||||
|
||||
|
||||
// Count how many to send
|
||||
labelList nSend(Pstream::nProcs(), 0);
|
||||
forAll(complexData, i)
|
||||
@ -122,8 +110,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Construct distribute map (destructively)
|
||||
mapDistribute map(constructSize, sendMap.xfer(), recvMap.xfer());
|
||||
|
||||
@ -134,28 +120,27 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Perr<< "\nStarting transfers\n" << endl;
|
||||
|
||||
vector data(0, 1, 2);
|
||||
|
||||
if (Pstream::parRun())
|
||||
template<class T>
|
||||
void testTransfer(const T& input)
|
||||
{
|
||||
T data = input;
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
Perr<<"test transfer (" << (typeid(T).name()) << "): " << data << nl << endl;
|
||||
}
|
||||
|
||||
if (Pstream::myProcNo() != Pstream::masterNo())
|
||||
{
|
||||
{
|
||||
Perr<< "slave sending to master "
|
||||
<< Pstream::masterNo() << endl;
|
||||
Perr<< "slave sending to master " << Pstream::masterNo() << endl;
|
||||
OPstream toMaster(Pstream::blocking, Pstream::masterNo());
|
||||
toMaster << data;
|
||||
}
|
||||
|
||||
Perr<< "slave receiving from master "
|
||||
<< Pstream::masterNo() << endl;
|
||||
Perr<< "slave receiving from master " << Pstream::masterNo() << endl;
|
||||
IPstream fromMaster(Pstream::blocking, Pstream::masterNo());
|
||||
fromMaster >> data;
|
||||
|
||||
Perr<< data << endl;
|
||||
}
|
||||
else
|
||||
@ -164,13 +149,12 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
int slave = Pstream::firstSlave();
|
||||
slave <= Pstream::lastSlave();
|
||||
slave++
|
||||
++slave
|
||||
)
|
||||
{
|
||||
Perr<< "master receiving from slave " << slave << endl;
|
||||
IPstream fromSlave(Pstream::blocking, slave);
|
||||
fromSlave >> data;
|
||||
|
||||
Perr<< data << endl;
|
||||
}
|
||||
|
||||
@ -178,7 +162,7 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
int slave = Pstream::firstSlave();
|
||||
slave <= Pstream::lastSlave();
|
||||
slave++
|
||||
++slave
|
||||
)
|
||||
{
|
||||
Perr<< "master sending to slave " << slave << endl;
|
||||
@ -188,8 +172,105 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
Info<< "End\n" << endl;
|
||||
|
||||
template<class T>
|
||||
void testTokenized(const T& data)
|
||||
{
|
||||
token tok;
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
Perr<<"test tokenized \"" << data << "\"" << nl << endl;
|
||||
}
|
||||
|
||||
if (Pstream::myProcNo() != Pstream::masterNo())
|
||||
{
|
||||
{
|
||||
Perr<< "slave sending to master " << Pstream::masterNo() << endl;
|
||||
OPstream toMaster(Pstream::blocking, Pstream::masterNo());
|
||||
toMaster << data;
|
||||
}
|
||||
|
||||
Perr<< "slave receiving from master " << Pstream::masterNo() << endl;
|
||||
IPstream fromMaster(Pstream::blocking, Pstream::masterNo());
|
||||
|
||||
fromMaster >> tok;
|
||||
Perr<< tok.info() << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for
|
||||
(
|
||||
int slave = Pstream::firstSlave();
|
||||
slave <= Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
Perr<< "master receiving from slave " << slave << endl;
|
||||
IPstream fromSlave(Pstream::blocking, slave);
|
||||
fromSlave >> tok;
|
||||
Perr<< tok.info() << endl;
|
||||
}
|
||||
|
||||
for
|
||||
(
|
||||
int slave = Pstream::firstSlave();
|
||||
slave <= Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
Perr<< "master sending to slave " << slave << endl;
|
||||
OPstream toSlave(Pstream::blocking, slave);
|
||||
toSlave << data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#include "setRootCase.H"
|
||||
#include "createTime.H"
|
||||
|
||||
testMapDistribute();
|
||||
|
||||
if (!Pstream::parRun())
|
||||
{
|
||||
Info<< "\nWarning: not parallel - skipping further tests\n" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Info<< "\nStarting transfers\n\n" << endl;
|
||||
|
||||
testTransfer(vector(0, 1, 2));
|
||||
testTransfer(label(1234));
|
||||
testTransfer(scalar(3.14159));
|
||||
testTransfer(string("test string"));
|
||||
testTransfer(string(" x "));
|
||||
testTransfer(word("3.141 59")); // bad word, but transfer doesn't care
|
||||
|
||||
testTokenized(label(1234));
|
||||
testTokenized(scalar(3.14159));
|
||||
testTokenized('a');
|
||||
testTokenized('$'); // will not tokenize well
|
||||
|
||||
testTokenized(string("test string1"));
|
||||
testTokenized("test string1");
|
||||
testTokenized(word("3.141 59")); // bad word, but transfer doesn't care
|
||||
|
||||
testTokenized(string(" a "));
|
||||
testTokenized(" a ");
|
||||
|
||||
testTokenized(string(" $ "));
|
||||
testTokenized(" $ "); // reduces to 'char' and will not tokenize well
|
||||
|
||||
testTokenized(string(" $$ "));
|
||||
testTokenized(" $$ "); // reduces to 'word' and is tagged as such
|
||||
|
||||
|
||||
Info<< "End\n" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -194,7 +194,7 @@ Foam::Ostream& Foam::UOPstream::write(const char* str)
|
||||
|
||||
if (nonWhiteChars.size() == 1)
|
||||
{
|
||||
return write(nonWhiteChars.c_str()[1]);
|
||||
return write(nonWhiteChars[0]);
|
||||
}
|
||||
else if (nonWhiteChars.size())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user