MCPcopy Create free account
hub / github.com/chipsalliance/Surelog / compileMT_

Method compileMT_

src/DesignCompile/CompileDesign.cpp:135–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133
134template <class ObjectType, class ObjectMapType, typename FunctorType>
135void CompileDesign::compileMT_(ObjectMapType& objects, int32_t maxThreadCount) {
136 if (maxThreadCount == 0) {
137 for (const auto& itr : objects) {
138 FunctorType funct(this, itr.second, m_compiler->getDesign(),
139 m_symbolTables[0], m_errorContainers[0]);
140 funct.operator()();
141 }
142 } else {
143 // Optimize the load balance, try to even out the work in each thread by the
144 // number of VObjects
145 std::vector<uint64_t> jobSize(maxThreadCount, 0);
146 std::vector<std::vector<ObjectType*>> jobArray(maxThreadCount);
147 for (const auto& mod : objects) {
148 uint32_t size = mod.second->getSize();
149 if (size == 0) size = 100;
150 uint32_t newJobIndex = 0;
151 uint64_t minJobQueue = ULLONG_MAX;
152 for (int32_t ii = 0; ii < maxThreadCount; ii++) {
153 if (jobSize[ii] < minJobQueue) {
154 newJobIndex = ii;
155 minJobQueue = jobSize[ii];
156 }
157 }
158 jobSize[newJobIndex] += size;
159 jobArray[newJobIndex].push_back(mod.second);
160 }
161
162 if (getCompiler()->getCommandLineParser()->profile()) {
163 std::cout << "Compilation Task\n";
164 for (int32_t i = 0; i < maxThreadCount; i++) {
165 std::cout << "Thread " << i << " : \n";
166 for (uint32_t j = 0; j < jobArray[i].size(); j++) {
167 std::cout << jobArray[i][j]->getName() << "\n";
168 }
169 }
170 }
171
172 // Create the threads with their respective workloads
173 std::vector<std::thread*> threads;
174 for (int32_t i = 0; i < maxThreadCount; i++) {
175 std::thread* th = new std::thread([=] {
176 for (uint32_t j = 0; j < jobArray[i].size(); j++) {
177 FunctorType funct(this, jobArray[i][j], m_compiler->getDesign(),
178 m_symbolTables[i], m_errorContainers[i]);
179 funct.operator()();
180 }
181 });
182 threads.push_back(th);
183 }
184 for (auto* thread : threads) { // sync
185 thread->join();
186 }
187 for (auto* thread : threads) { // delete
188 delete thread;
189 }
190 }
191}
192

Callers

nothing calls this directly

Calls 6

getDesignMethod · 0.80
profileMethod · 0.80
operator()Method · 0.45
getSizeMethod · 0.45
getCommandLineParserMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected