Debian Codegraph @

Source/Control/Loader/CTestMemoryAccessLoader.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 "CTestMemoryAccessLoader.h"
22
23
24 namespace Konclude {
25
26 namespace Control {
27
28 namespace Loader {
29
30
31 CTestMemoryAccessLoader::CTestMemoryAccessLoader() : CIntervalThread("TestMemoryAccessThread") {
32 mConfiguration = 0;
33 tester = 0;
34 startThread();
35 }
36
37
38
39 CTestMemoryAccessLoader::~CTestMemoryAccessLoader() {
40 }
41
42
43 CLoader* CTestMemoryAccessLoader::init(CLoaderFactory* loaderFactory, CConfiguration* config) {
44 mConfiguration = config;
45 return this;
46 }
47
48
49
50
51 CLoader *CTestMemoryAccessLoader::load() {
52 tester = new CConcurrentMemoryAccessTester();
53 mRemainingSteps = 1;
54 mThreadCount = 1;
55 mMaxThreadCount = 10;
56
57 mReadWriteRatioInit = mReadWriteRatio = 1;
58 mReadWriteRatioMax = 256;
59 mReadWriteRatioStepMultiplier = 4;
60
61 mAtomicOperations = false;
62
63 mArraySizeInit = mArraySize = 2621440;
64 mArraySizeStepMultiplier = 4;
65 mArraySizeMax = Q_INT64_C(671088640);
66
67 mArraySizeInit = mArraySize = 1310720;
68 mArraySizeStepMultiplier = 4;
69 mArraySizeMax = Q_INT64_C(335544320);
70
71 startTimerWithInterval(TESTTIMERID,5000);
72 tester->generateTestingStructure(mArraySize,mReadWriteRatio,mAtomicOperations,mThreadCount);
73 tester->startHashModificationTest();
74 cout<<"Starting concurrent memory access performance test.\n";
75 cout<<"----------------------\n";
76 return this;
77 }
78
79
80 bool CTestMemoryAccessLoader::processTimer(qint64 timerID) {
81 if (timerID == TESTTIMERID) {
82 if (mRemainingSteps > 0) {
83 cint64 modSteps = tester->getModificationStepsCount();
84 tester->stopHashModificationTest();
85 tester->destroyTestingStructure();
86 if (mThreadCount == 1) {
87 mOneThreadScore = modSteps;
88 }
89 cout<<""<<mThreadCount<<" \tThreads,"<<" Read Write Ratio: "<<mReadWriteRatio<<", \tMemory Size: "<<mArraySize*4/1024/1024;
90 cout<<" MByte";
91 //if (mAtomicOperations) {
92 // cout<<", \t+";
93 //} else {
94 // cout<<", \t-";
95 //}
96 //cout<<"Atomic Operations";
97 cout<<" \t>> Modification Score: \t"<<modSteps;
98 double scaleFac = (double)modSteps / (double)mOneThreadScore;
99 cout<<", \t"<<scaleFac<<"x"<<endl;
100
101
102 if (mThreadCount < mMaxThreadCount) {
103 ++mThreadCount;
104 } else {
105 mThreadCount = 1;
106 //if (!mAtomicOperations) {
107 // mAtomicOperations = true;
108 //} else {
109 // mAtomicOperations = false;
110 if (mReadWriteRatio < mReadWriteRatioMax) {
111 mReadWriteRatio *= mReadWriteRatioStepMultiplier;
112 } else {
113 mReadWriteRatio = mReadWriteRatioInit;
114 cout<<"----------------------\n";
115 if (mArraySize < mArraySizeMax) {
116 mArraySize *= mArraySizeStepMultiplier;
117 } else {
118 mArraySize = mArraySizeInit;
119 // finish analyzing
120 mRemainingSteps = 0;
121 }
122 }
123 //}
124 }
125
126 if (mRemainingSteps > 0) {
127 tester->generateTestingStructure(mArraySize,mReadWriteRatio,mAtomicOperations,mThreadCount);
128 tester->startHashModificationTest();
129 }
130
131 } else {
132 cout<<"Test finished.\n";
133 stopThread(false);
134 }
135 return true;
136 }
137 return false;
138 }
139
140
141 CLoader* CTestMemoryAccessLoader::exit() {
142 if (tester) {
143 delete tester;
144 }
145 return this;
146 }
147
148
149
150
151 }; // end namespace Loader
152
153 }; // end namespace Control
154
155 }; // end namespace Konclude