CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   PStream/IPstream/OPstream class support for int64_t? (http://www.cfd-online.com/Forums/openfoam-programming-development/81606-pstream-ipstream-opstream-class-support-int64_t.html)

allenzhao November 1, 2010 12:46

PStream/IPstream/OPstream class support for int64_t?
 
Hi,

I am using OpenFOAM-1.4.1-dev with gcc. But I have a need to pass int64_t type data using IPstream/OPstream class, and apparently, the PStream class does not support int64_t type ( at compilation time:

Example:
typedef int64_t INTEGER8;

INTEGER8 masterData, slaveData;

from master node:
OPstream toSlave(slave);
toSlave << (INTEGER8) masterData;

On slave node:
IPstream fromMaster(Pstream::masterNo());
fromMaster >> slaveData;

gcc (with either -m32 or -m64) will give something like following:

../gtopenfoamLib/FoamCalls.cpp:181: error: ambiguous overload for ‚operator>>‚ in ‚fromSlave >> objSlave‚
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/Istream.H:160: note: candidates are: Foam::Istream& Foam:operator>>(Foam::Istream&, Foam::IOstream& (*)(Foam::IOstream&)) <near match>
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/Istream.H:154: note: Foam::Istream& Foam:operator>>(Foam::Istream&, Foam::Istream& (*)(Foam::Istream&)) <near match>
../gtopenfoamLib/FoamCalls.cpp:182: warning: use of old-style cast
../gtopenfoamLib/FoamCalls.cpp:182: warning: use of old-style cast
../gtopenfoamLib/FoamCalls.cpp:189: warning: use of old-style cast
../gtopenfoamLib/FoamCalls.cpp:189: error: ambiguous overload for ‚operator<<‚ in ‚toMaster << (long int)lpFoamObjectRef‚
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/uint.H:58: note: candidates are: Foam::Ostream& Foam::operator<<(Foam::Ostream&, unsigned int)
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/Ostream.H:203: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, Foam::IOstream& (*)(Foam::IOstream&)) <near match>
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/Ostream.H:197: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, Foam::Ostream& (*)(Foam::Ostream&)) <near match>
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/IOstream.H:537: note: Foam::IOstream& Foam::operator<<(Foam::IOstream&, Foam::IOstream& (*)(Foam::IOstream&)) <near match>
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/Scalar.H:260: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, Foam::doubleScalar)
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/Scalar.H:260: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, Foam::floatScalar)
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/bool.H:51: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, bool)
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/int.H:59: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, int)
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/string.H:196: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, const std::string&) <near match>
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/char.H:52: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, const char*) <near match>
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/char.H:51: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, char)
/Apps/openfoam/OpenFOAM/OpenFOAM-1.4.1-dev/src/OpenFOAM/lnInclude/IOstream.H:99: note: Foam::Ostream& Foam::operator<<(Foam::Ostream&, const Foam::IOstream::streamFormat&) <near match>
../gtopenfoamLib/FoamCalls.cpp:200: warning: use of old-style cast


So apparently, we have some issues with pass 64-bit integer with MPI.

Here is my question:
What is the quickest way to patch the PStream class to enable the int64_t type? Any pointer will help.

allenzhao November 1, 2010 17:18

My current work around is following function:

/*-----------------------------------------------/
OpenFOAM's PStream does not support int64_t data
type. Following 3 functions are utility functions
to divide INTEGER8 to 2 INTERGER or conbine 2
INTEGER data to INTEGER8 data.
------------------------------------------------*/
static INTEGER HiInteger8(INTEGER8 lNnumber)
{
return (INTEGER) ((lNnumber >> 32) & 0xFFFFFFFF);
}

static INTEGER LoInteger8(INTEGER8 lNnumber)
{
return (INTEGER) (lNnumber & 0xFFFFFFFF);
}

static INTEGER8 ToInteger8(INTEGER nHigh, INTEGER nLow)
{
return ((((INTEGER8)nHigh) << 32) | nLow);
}

But it will be ideal is PStream class can handle it by default.


All times are GMT -4. The time now is 06:08.