1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 \*---------------------------------------------------------------------------*/
33 #include "IOstreams.H"
35 #include "PackedBoolList.H"
41 template<unsigned nBits>
42 inline void reportInfo()
44 unsigned offset = PackedList<nBits>::packing();
46 unsigned useSHL = ((1u << (nBits * offset)) - 1);
47 unsigned useSHR = (~0u >> (sizeof(unsigned)*CHAR_BIT - nBits * offset));
50 << "PackedList<" << nBits << ">" << nl
51 << " max_value: " << PackedList<nBits>::max_value() << nl
52 << " packing: " << PackedList<nBits>::packing() << nl
53 << " utilization: " << (nBits * offset) << nl;
55 Info<< " Masking:" << nl
57 << unsigned(nBits * offset) << nl
59 << unsigned((sizeof(unsigned)*CHAR_BIT) - nBits * offset)
64 << PackedList<nBits>::maskLower(PackedList<nBits>::packing())
66 << " useSHL: " << useSHL << nl
67 << " useSHR: " << useSHR << nl;
71 Info<< "WARNING: different results for SHL and SHR" << nl;
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 int main(int argc, char *argv[])
84 argList::noParallel();
85 argList::validArgs.insert("file .. fileN");
87 argList::addBoolOption("mask", "report information about the bit masks");
88 argList::addBoolOption("count", "test the count() method");
89 argList::addBoolOption
92 "print an ascii representation of the storage"
95 argList args(argc, argv, false, true);
98 if (args.optionFound("mask"))
100 Info<< "bit width: " << unsigned(sizeof(unsigned)*CHAR_BIT) << endl;
120 else if (args.size() <= 1)
126 for (label argI=1; argI < args.size(); ++argI)
128 const string& srcFile = args[argI];
129 Info<< nl << "reading " << srcFile << nl;
131 IFstream ifs(srcFile);
132 List<label> rawLst(ifs);
134 PackedBoolList packLst(rawLst);
136 Info<< "size: " << packLst.size() << nl;
138 if (args.optionFound("count"))
140 unsigned int rawCount = 0;
141 forAll(rawLst, elemI)
148 Info<< "raw count: " << rawCount << nl
149 << "packed count: " << packLst.count() << nl;
152 if (args.optionFound("info"))
154 packLst.printInfo(Info);
158 IOobject::writeDivider(Info);
164 // ************************************************************************* //