cpuInfo.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2017 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "cpuInfo.H"
29 #include "IOstreams.H"
30 
31 #include <thread>
32 
33 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
38 :
39  vendor_id(),
40  model_name(),
41  cpu_family(-1),
42  model(-1),
43  cpu_MHz(0),
44  siblings(0),
45  cpu_cores(std::thread::hardware_concurrency())
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
52 {
53  if (!vendor_id.empty())
54  {
55  os.writeEntry("vendor_id", vendor_id);
56  }
57  if (!model_name.empty())
58  {
59  os.writeEntry("model_name", model_name);
60  }
61 
62  os.writeEntryIfDifferent<int>("cpu_family", -1, cpu_family);
63  os.writeEntryIfDifferent<int>("model", -1, model);
64  os.writeEntryIfDifferent<float>("cpu_MHz", 0, cpu_MHz);
65  os.writeEntryIfDifferent<int>("cpu_cores", 0, cpu_cores);
66  os.writeEntryIfDifferent<int>("siblings", 0, siblings);
67 }
68 
69 
70 // ************************************************************************* //
Foam::Ostream::writeEntryIfDifferent
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
Definition: Ostream.H:248
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
os
OBJstream os(runTime.globalPath()/outputName)
Foam::cpuInfo::cpuInfo
cpuInfo()
Construct and populate with information.
Definition: cpuInfo.C:37
cpuInfo.H
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:236
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::cpuInfo::write
void write(Ostream &os) const
Write content as dictionary entries.
Definition: cpuInfo.C:51