@@ -92,35 +92,24 @@ Collection::Collection(CpuInfoInterface *cpuInfo) : cpuInfo(*cpuInfo) {
9292 collectBasicCpuInformation ();
9393}
9494
95- Collection &Collection::getSingleInstance () {
96- static CpuInfo cpuInfo;
97- static Collection collection (&cpuInfo);
98- return collection;
99- }
100-
10195unsigned Collection::getProcessorSpeedMHz () {
102- Collection &collection = getSingleInstance ();
103- return collection.processors .size () ? collection.processors [0 ].speedMHz : 0 ;
96+ return processors.size () ? processors[0 ].speedMHz : 0 ;
10497}
10598
10699unsigned Collection::getTotalNumberOfSockets () {
107- Collection &collection = getSingleInstance ();
108- return collection.totalNumberOfSockets ;
100+ return totalNumberOfSockets;
109101}
110102
111103unsigned Collection::getTotalNumberOfCpuCores () {
112- Collection &collection = getSingleInstance ();
113- return collection.totalNumberOfCpuCores ;
104+ return totalNumberOfCpuCores;
114105}
115106
116107unsigned Collection::getNumberOfProcessors () {
117- Collection &collection = getSingleInstance ();
118- return collection.processors .size ();
108+ return processors.size ();
119109}
120110
121111const Processor &Collection::getProcessor (unsigned processorId) {
122- Collection &collection = getSingleInstance ();
123- return collection.processors [processorId];
112+ return processors[processorId];
124113}
125114
126115void Collection::parseCpuInfo () {
@@ -262,14 +251,16 @@ static const char *openMpEnvVars[] = {
262251static const unsigned numberOfOpenMpEnvVars =
263252 sizeof (openMpEnvVars) / sizeof (openMpEnvVars[0 ]);
264253
265- OpenMpManager::OpenMpManager () {
254+ OpenMpManager::OpenMpManager (Collection *collection) : collection(*collection ) {
266255 getOpenMpEnvVars ();
267256 getCurrentCpuSet ();
268257 getCurrentCoreSet ();
269258}
270259
271260OpenMpManager &OpenMpManager::getInstance () {
272- static OpenMpManager openMpManager;
261+ static CpuInfo cpuInfo;
262+ static Collection collection (&cpuInfo);
263+ static OpenMpManager openMpManager (&collection);
273264 return openMpManager;
274265}
275266
@@ -325,7 +316,7 @@ void OpenMpManager::getCurrentCpuSet() {
325316
326317void OpenMpManager::getDefaultCpuSet (cpu_set_t *defaultCpuSet) {
327318 CPU_ZERO (defaultCpuSet);
328- unsigned numberOfProcessors = Collection:: getNumberOfProcessors ();
319+ unsigned numberOfProcessors = collection. getNumberOfProcessors ();
329320 for (int processorId = 0 ; processorId < numberOfProcessors; processorId++) {
330321 CPU_SET (processorId, defaultCpuSet);
331322 }
@@ -337,8 +328,8 @@ void OpenMpManager::getDefaultCpuSet(cpu_set_t *defaultCpuSet) {
337328 available. */
338329
339330void OpenMpManager::getCurrentCoreSet () {
340- unsigned numberOfProcessors = Collection:: getNumberOfProcessors ();
341- unsigned totalNumberOfCpuCores = Collection:: getTotalNumberOfCpuCores ();
331+ unsigned numberOfProcessors = collection. getNumberOfProcessors ();
332+ unsigned totalNumberOfCpuCores = collection. getTotalNumberOfCpuCores ();
342333
343334 cpu_set_t usedCoreSet;
344335 CPU_ZERO (&usedCoreSet);
@@ -356,8 +347,8 @@ void OpenMpManager::getCurrentCoreSet() {
356347}
357348
358349void OpenMpManager::selectAllCoreCpus (cpu_set_t *set, unsigned physicalCoreId) {
359- unsigned numberOfProcessors = Collection:: getNumberOfProcessors ();
360- unsigned totalNumberOfCpuCores = Collection:: getTotalNumberOfCpuCores ();
350+ unsigned numberOfProcessors = collection. getNumberOfProcessors ();
351+ unsigned totalNumberOfCpuCores = collection. getTotalNumberOfCpuCores ();
361352
362353 int processorId = physicalCoreId % totalNumberOfCpuCores;
363354 while (processorId < numberOfProcessors) {
@@ -370,7 +361,7 @@ void OpenMpManager::selectAllCoreCpus(cpu_set_t *set, unsigned physicalCoreId) {
370361}
371362
372363unsigned OpenMpManager::getPhysicalCoreId (unsigned logicalCoreId) {
373- unsigned numberOfProcessors = Collection:: getNumberOfProcessors ();
364+ unsigned numberOfProcessors = collection. getNumberOfProcessors ();
374365
375366 for (int processorId = 0 ; processorId < numberOfProcessors; processorId++) {
376367 if (CPU_ISSET (processorId, ¤tCoreSet)) {
@@ -415,16 +406,16 @@ void OpenMpManager::printVerboseInformation() {
415406 OpenMpManager &openMpManager = getInstance ();
416407
417408 LOG (INFO) << " Processor speed [MHz]: "
418- << Collection:: getProcessorSpeedMHz ();
409+ << openMpManager. collection . getProcessorSpeedMHz ();
419410
420411 LOG (INFO) << " Total number of sockets: "
421- << Collection:: getTotalNumberOfSockets ();
412+ << openMpManager. collection . getTotalNumberOfSockets ();
422413
423414 LOG (INFO) << " Total number of CPU cores: "
424- << Collection:: getTotalNumberOfCpuCores ();
415+ << openMpManager. collection . getTotalNumberOfCpuCores ();
425416
426417 LOG (INFO) << " Total number of processors: "
427- << Collection:: getNumberOfProcessors ();
418+ << openMpManager. collection . getNumberOfProcessors ();
428419
429420 LOG (INFO) << " GPU is used: "
430421 << (openMpManager.isGpuEnabled ? " yes" : " no" );
@@ -439,6 +430,11 @@ void OpenMpManager::printVerboseInformation() {
439430 << omp_get_max_threads ();
440431}
441432
433+ unsigned OpenMpManager::getProcessorSpeedMHz () {
434+ OpenMpManager &openMpManager = getInstance ();
435+ return openMpManager.collection .getProcessorSpeedMHz ();
436+ }
437+
442438#endif // _OPENMP
443439
444440} // namespace cpu
0 commit comments