Debian Codegraph @

Source/Reasoner/Kernel/Calculation/CConcurrentTaskCalculationEnvironment.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CConcurrentTaskCalculationEnvironment.h"
22
23
24 namespace Konclude {
25
26 namespace Reasoner {
27
28 namespace Kernel {
29
30 namespace Calculation {
31
32
33 CConcurrentTaskCalculationEnvironment::CConcurrentTaskCalculationEnvironment() {
34 mProcessUnit = nullptr;
35 mSchedulerUnit = nullptr;
36 mCompletorUnit = nullptr;
37 mCallbackExecuter = nullptr;
38 mStatusPropagator = nullptr;
39 mAllocationLimitation = nullptr;
40
41 mTaskCreatedDepthCountVec.resize(CTaskProcessingStatistics::VECCOUNTERSIZE);
42 mTaskProcessedDepthCountVec.resize(CTaskProcessingStatistics::VECCOUNTERSIZE);
43 mTaskRelativeIncreaseTaskPerDepthVec.resize(CTaskProcessingStatistics::VECCOUNTERSIZE);
44 mTaskTotalIncreaseTaskPerDepthVec.resize(CTaskProcessingStatistics::VECCOUNTERSIZE);
45 }
46
47 CConcurrentTaskCalculationEnvironment::~CConcurrentTaskCalculationEnvironment() {
48 qDeleteAll(mProcessorUnitList);
49 mProcessorUnitList.clear();
50 }
51
52
53 CConcurrentTaskCalculationEnvironment* CConcurrentTaskCalculationEnvironment::initSingleTaskProcessor(CSingleThreadTaskProcessorUnit* processUnit) {
54 mProcessUnit = processUnit;
55 mSchedulerUnit = mProcessUnit;
56 mCompletorUnit = mProcessUnit;
57 mProcessorUnitList.append(mProcessUnit);
58 return this;
59 }
60
61 CConcurrentTaskCalculationEnvironment* CConcurrentTaskCalculationEnvironment::initMultiTaskProcessor(CTaskProcessorSchedulerThread* schedulerUnit, CTaskProcessorCompletorThread* completorUnit) {
62 mProcessUnit = nullptr;
63 mSchedulerUnit = schedulerUnit;
64 mCompletorUnit = completorUnit;
65 mProcessorUnitList.append(schedulerUnit);
66 mProcessorUnitList.append(completorUnit);
67 mThreadUnitList.append(schedulerUnit);
68 mThreadUnitList.append(completorUnit);
69 return this;
70 }
71
72 CConcurrentTaskCalculationEnvironment* CConcurrentTaskCalculationEnvironment::appendMultiTaskProcessor(CTaskProcessorThread* processorUnit) {
73 mProcessorUnitList.append(processorUnit);
74 mThreadUnitList.append(processorUnit);
75 return this;
76 }
77
78 CConcurrentTaskCalculationEnvironment* CConcurrentTaskCalculationEnvironment::initCallbackExecuter(CSatisfiableCalculationTaskJobCallbackExecuter* callbackExecuter) {
79 mCallbackExecuter = callbackExecuter;
80 return this;
81 }
82
83 CConcurrentTaskCalculationEnvironment* CConcurrentTaskCalculationEnvironment::initStatusPropagator(CSatisfiableCalculationTaskStatusPropagator* statusPropagator) {
84 mStatusPropagator = statusPropagator;
85 return this;
86 }
87
88 CConcurrentTaskCalculationEnvironment* CConcurrentTaskCalculationEnvironment::setAllocationLimitation(CCentralizedAllocationLimitation* allocationLimitation) {
89 mAllocationLimitation = allocationLimitation;
90 return this;
91 }
92
93
94 CSatisfiableCalculationTaskJobCallbackExecuter* CConcurrentTaskCalculationEnvironment::getSatisfiableCalculationTaskJobCallbackExecuter() {
95 return mCallbackExecuter;
96 }
97
98 CSatisfiableCalculationTaskStatusPropagator* CConcurrentTaskCalculationEnvironment::getSatisfiableCalculationTaskStatusPropagator() {
99 return mStatusPropagator;
100 }
101
102 CSingleThreadTaskProcessorUnit* CConcurrentTaskCalculationEnvironment::getSingleTaskProcessorUnit() {
103 return mProcessUnit;
104 }
105
106 CTaskEventHandlerBasedScheduler* CConcurrentTaskCalculationEnvironment::getSchedulerTaskProcessorUnit() {
107 return mSchedulerUnit;
108 }
109
110 CTaskEventHandlerBasedCompletor* CConcurrentTaskCalculationEnvironment::getCompletorTaskProcessorUnit() {
111 return mCompletorUnit;
112 }
113
114 QList<CTaskEventHandlerBasedProcessor*> CConcurrentTaskCalculationEnvironment::getTaskProcessorUnitList() {
115 return mProcessorUnitList;
116 }
117
118 CCentralizedAllocationLimitation* CConcurrentTaskCalculationEnvironment::getAllocationLimitation() {
119 return mAllocationLimitation;
120 }
121
122 cint64 CConcurrentTaskCalculationEnvironment::getCalculationComputionTime() {
123 cint64 compTime = 0;
124 if (mProcessUnit) {
125 compTime += mProcessUnit->getStatisticComputionTime();
126 }
127 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
128 compTime += threadUnit->getStatisticComputionTime();
129 }
130 return compTime;
131 }
132
133 cint64 CConcurrentTaskCalculationEnvironment::getCalculationBlockingTime() {
134 cint64 compTime = 0;
135 if (mProcessUnit) {
136 compTime += mProcessUnit->getStatisticBlockingTime();
137 }
138 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
139 compTime += threadUnit->getStatisticBlockingTime();
140 }
141 return compTime;
142 }
143
144 cint64 CConcurrentTaskCalculationEnvironment::getCalculationMemoryConsumption() {
145 cint64 memComp = 0;
146 memComp = mAllocationLimitation->getAllocatedMemorySizeMaximum();
147 return memComp;
148 }
149
150 cint64 CConcurrentTaskCalculationEnvironment::getCalculationMemoryReserved() {
151 cint64 memComp = 0;
152 memComp = mAllocationLimitation->getReservedMemorySizeMaximum();
153 return memComp;
154 }
155
156
157 cint64 CConcurrentTaskCalculationEnvironment::getCalculationStatisticTasksProcessedCount() {
158 cint64 statVal = 0;
159 if (mProcessUnit) {
160 statVal += mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksProcessedCount();
161 }
162 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
163 statVal += threadUnit->getTaskProcessingStatistics()->getStatisticTasksProcessedCount();
164 }
165 return statVal;
166 }
167
168 cint64 CConcurrentTaskCalculationEnvironment::getCalculationStatisticTasksAddedCount() {
169 cint64 statVal = 0;
170 if (mProcessUnit) {
171 statVal += mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksAddedCount();
172 }
173 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
174 statVal += threadUnit->getTaskProcessingStatistics()->getStatisticTasksAddedCount();
175 }
176 return statVal;
177 }
178
179 cint64 CConcurrentTaskCalculationEnvironment::getCalculationStatisticTasksCreatedCount() {
180 cint64 statVal = 0;
181 if (mProcessUnit) {
182 statVal += mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksCreatedCount();
183 }
184 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
185 statVal += threadUnit->getTaskProcessingStatistics()->getStatisticTasksCreatedCount();
186 }
187 return statVal;
188 }
189
190 cint64 CConcurrentTaskCalculationEnvironment::getCalculationStatisticTasksCompletedCount() {
191 cint64 statVal = 0;
192 if (mProcessUnit) {
193 statVal += mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksCompletedCount();
194 }
195 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
196 statVal += threadUnit->getTaskProcessingStatistics()->getStatisticTasksCompletedCount();
197 }
198 return statVal;
199 }
200
201 cint64 CConcurrentTaskCalculationEnvironment::getCalculationStatisticTasksUpdatedCount() {
202 cint64 statVal = 0;
203 if (mProcessUnit) {
204 statVal += mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksUpdatedCount();
205 }
206 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
207 statVal += threadUnit->getTaskProcessingStatistics()->getStatisticTasksUpdatedCount();
208 }
209 return statVal;
210 }
211
212 cint64 CConcurrentTaskCalculationEnvironment::getCalculationStatisticEventsProcessedCount() {
213 cint64 statVal = 0;
214 if (mProcessUnit) {
215 statVal += mProcessUnit->getTaskProcessingStatistics()->getStatisticEventsProcessedCount();
216 }
217 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
218 statVal += threadUnit->getTaskProcessingStatistics()->getStatisticEventsProcessedCount();
219 }
220 return statVal;
221 }
222
223 cint64 CConcurrentTaskCalculationEnvironment::getCalculationStatisticTasksRequestedCount() {
224 cint64 statVal = 0;
225 if (mProcessUnit) {
226 statVal += mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksRequestedCount();
227 }
228 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
229 statVal += threadUnit->getTaskProcessingStatistics()->getStatisticTasksRequestedCount();
230 }
231 return statVal;
232 }
233
234
235 cint64 CConcurrentTaskCalculationEnvironment::getCalculationStatisticThreadsBlockedCount() {
236 cint64 statVal = 0;
237 if (mProcessUnit) {
238 statVal += mProcessUnit->getTaskProcessingStatistics()->getStatisticThreadsBlockedCount();
239 }
240 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
241 statVal += threadUnit->getTaskProcessingStatistics()->getStatisticThreadsBlockedCount();
242 }
243 return statVal;
244 }
245
246
247 double CConcurrentTaskCalculationEnvironment::getCalculationApproximatedRemainingTasksCount() {
248 double remainingTasksCount = 0;
249 for (cint64 i = 0; i < CTaskProcessingStatistics::VECCOUNTERSIZE; ++i) {
250 mTaskCreatedDepthCountVec[i] = 0;
251 mTaskProcessedDepthCountVec[i] = 0;
252 mTaskRelativeIncreaseTaskPerDepthVec[i] = 0.;
253 mTaskTotalIncreaseTaskPerDepthVec[i] = 1.;
254 }
255 if (mProcessUnit) {
256 QVector<cint64>* createdVec = mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksCreatedDepthCountVector();
257 QVector<cint64>* processedVec = mProcessUnit->getTaskProcessingStatistics()->getStatisticTasksProcessedDepthCountVector();
258 for (cint64 i = 0; i < CTaskProcessingStatistics::VECCOUNTERSIZE; ++i) {
259 mTaskCreatedDepthCountVec[i] += (*createdVec)[i];
260 mTaskProcessedDepthCountVec[i] += (*processedVec)[i];
261 }
262 }
263 foreach (CTaskProcessorThreadBase* threadUnit, mThreadUnitList) {
264 QVector<cint64>* createdVec = threadUnit->getTaskProcessingStatistics()->getStatisticTasksCreatedDepthCountVector();
265 QVector<cint64>* processedVec = threadUnit->getTaskProcessingStatistics()->getStatisticTasksProcessedDepthCountVector();
266 for (cint64 i = 0; i < CTaskProcessingStatistics::VECCOUNTERSIZE; ++i) {
267 mTaskCreatedDepthCountVec[i] += (*createdVec)[i];
268 mTaskProcessedDepthCountVec[i] += (*processedVec)[i];
269 }
270 }
271
272 for (cint64 i = 0; i < CTaskProcessingStatistics::VECCOUNTERSIZE-1; ++i) {
273 cint64 processedTaskCount = mTaskProcessedDepthCountVec[i];
274 cint64 nextDepthCreatedCount = mTaskCreatedDepthCountVec[i+1];
275 double relIncTaskRate = 0;
276 if (nextDepthCreatedCount) {
277 if (processedTaskCount < 1) {
278 processedTaskCount = 1;
279 mTaskProcessedDepthCountVec[i] = processedTaskCount;
280 }
281 relIncTaskRate = (double)nextDepthCreatedCount/(double)processedTaskCount;
282 }
283 mTaskRelativeIncreaseTaskPerDepthVec[i] = relIncTaskRate;
284 }
285
286 for (cint64 i = CTaskProcessingStatistics::VECCOUNTERSIZE-1; i >= 0; --i) {
287 double relIncValue = mTaskRelativeIncreaseTaskPerDepthVec[i];
288 if (relIncValue > 0.) {
289 double nextTotIncValue = mTaskTotalIncreaseTaskPerDepthVec[i+1];
290 if (nextTotIncValue > 0.) {
291 mTaskTotalIncreaseTaskPerDepthVec[i] = 1 + nextTotIncValue * relIncValue;
292 } else {
293 mTaskTotalIncreaseTaskPerDepthVec[i] = relIncValue;
294 }
295 }
296 }
297
298 for (cint64 i = 0; i < CTaskProcessingStatistics::VECCOUNTERSIZE-1; ++i) {
299 cint64 openTaskCount = mTaskCreatedDepthCountVec[i] - mTaskProcessedDepthCountVec[i];
300 if (openTaskCount > 0) {
301 remainingTasksCount += openTaskCount * mTaskTotalIncreaseTaskPerDepthVec[i];
302 }
303 }
304
305 QStringList debugStringList;
306 for (cint64 i = 0; i < CTaskProcessingStatistics::VECCOUNTERSIZE-1; ++i) {
307 QString depthString = QString("Depth: %1, C:%2, P:%3, +:%4, *%5").arg(i).arg(mTaskCreatedDepthCountVec[i]).arg(mTaskProcessedDepthCountVec[i])
308 .arg(mTaskRelativeIncreaseTaskPerDepthVec[i]).arg(mTaskTotalIncreaseTaskPerDepthVec[i]);
309 debugStringList.append(depthString);
310 }
311 QString debugString = debugStringList.join("\r\n");
312
313 return remainingTasksCount;
314 }
315
316
317
318 }; // end namespace Calculation
319
320 }; // end namespace Kernel
321
322 }; // end namespace Reasoner
323
324 }; // end namespace Konclude