Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
TaskAllocatorList.cc
Go to the documentation of this file.
1//
2// MIT License
3// Copyright (c) 2020 Jonathan R. Madsen
4// Permission is hereby granted, free of charge, to any person obtaining a copy
5// of this software and associated documentation files (the "Software"), to deal
6// in the Software without restriction, including without limitation the rights
7// to use, copy, modify, merge, publish, distribute, sublicense, and
8// copies of the Software, and to permit persons to whom the Software is
9// furnished to do so, subject to the following conditions:
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
12// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
13// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
15// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
17// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18//
19// ---------------------------------------------------------------
20// Tasking class implementation
21//
22
23#include <iomanip>
24
25#include "PTL/TaskAllocator.hh"
27
28using namespace PTL;
29
30//======================================================================================//
31
33TaskAllocatorList::fAllocatorList()
34{
35 static thread_local TaskAllocatorList* _instance = nullptr;
36 return _instance;
37}
38
39//======================================================================================//
40
43{
44 if(!fAllocatorList())
45 {
46 fAllocatorList() = new TaskAllocatorList;
47 }
48 return fAllocatorList();
49}
50
51//======================================================================================//
52
55{
56 return fAllocatorList();
57}
58
59//======================================================================================//
60
61TaskAllocatorList::TaskAllocatorList() {}
62
63//======================================================================================//
64
65TaskAllocatorList::~TaskAllocatorList() { fAllocatorList() = nullptr; }
66
67//======================================================================================//
68
69void
71{
72 fList.push_back(alloc);
73}
74
75//======================================================================================//
76
77void
78TaskAllocatorList::Destroy(int nStat, int verboseLevel)
79{
80 int i = 0, j = 0;
81 double tmem = 0;
82 if(verboseLevel > 0)
83 {
84 std::cout << "================== Deleting memory pools ==================="
85 << std::endl;
86 }
87 for(auto& itr : fList)
88 {
89 double mem = itr->GetAllocatedSize();
90 if(i < nStat)
91 {
92 i++;
93 tmem += mem;
94 itr->ResetStorage();
95 continue;
96 }
97 j++;
98 tmem += mem;
99 if(verboseLevel > 1)
100 {
101 std::cout << "Pool ID '" << itr->GetPoolType()
102 << "', size : " << std::setprecision(3) << mem / 1048576
103 << std::setprecision(6) << " MB" << std::endl;
104 }
105 itr->ResetStorage();
106 // delete *itr;
107 }
108 if(verboseLevel > 0)
109 {
110 std::cout << "Number of memory pools allocated: " << Size()
111 << "; of which, static: " << i << std::endl;
112 std::cout << "Dynamic pools deleted: " << j
113 << " / Total memory freed: " << std::setprecision(2) << tmem / 1048576
114 << std::setprecision(6) << " MB" << std::endl;
115 std::cout << "============================================================"
116 << std::endl;
117 }
118 fList.clear();
119}
120
121//======================================================================================//
122
123int
125{
126 return fList.size();
127}
128
129//======================================================================================//
static TaskAllocatorList * GetAllocatorListIfExist()
void Destroy(int nStat=0, int verboseLevel=0)
void Register(TaskAllocatorBase *)
static TaskAllocatorList * GetAllocatorList()
Definition: AutoLock.hh:254