MCPcopy Create free account
hub / github.com/RootHarold/Lycoris / BP_Multi_Thread

Method BP_Multi_Thread

LycorisNet/sources/individual.cpp:228–302  ·  view source on GitHub ↗

Multi threaded version of back propagation.

Source from the content-addressed store, hash-verified

226
227 // Multi threaded version of back propagation.
228 void Individual::BP_Multi_Thread() {
229 auto individualSize = getSize() + 1;
230 if (args->batchFlag) {
231 args->batchData = new float *[args->batchSize];
232
233 for (uint32_t i = 0; i < args->batchSize; ++i) {
234 args->batchData[i] = new float[individualSize];
235 }
236
237 args->midData = new float[individualSize];
238
239 args->batchFlag = false;
240 }
241
242 auto start = new uint32_t[args->cpuNum];
243 auto end = new uint32_t[args->cpuNum];
244 auto part = args->batchSize / args->cpuNum;
245 auto temp = args->cpuNum - 1;
246 for (uint32_t i = 0; i < temp; ++i) {
247 start[i] = i * part;
248 end[i] = (i + 1) * part;
249 }
250 start[temp] = temp * part;
251 end[temp] = args->batchSize;
252
253 std::vector<std::thread> threads;
254 for (uint32_t i = 0; i < args->cpuNum; ++i) {
255 threads.emplace_back(std::thread(&Individual::BP_Multi_Thread_Core, this, start[i], end[i]));
256 }
257 for (auto &thread : threads) {
258 thread.join();
259 }
260
261 part = (individualSize) / args->cpuNum;
262 for (uint32_t i = 0; i < temp; ++i) {
263 start[i] = i * part;
264 end[i] = (i + 1) * part;
265 }
266 start[temp] = temp * part;
267 end[temp] = individualSize;
268
269 threads.clear();
270 for (uint32_t i = 0; i < args->cpuNum; ++i) {
271 threads.emplace_back(
272 std::thread(&Individual::BP_Multi_Thread_Forward, this, start[i], end[i], args->midData));
273 }
274 for (auto &iter : threads) {
275 iter.join();
276 }
277
278 uint32_t data_p = 0;
279
280 for (uint32_t j = 0; j < nodeSlice->size(); ++j) {
281 auto index = (*nodeSlice)[nodeSlice->size() - 1 - j];
282 auto n = (*nodeMap)[index];
283
284 for (auto iter = n->genomeMap->begin(); iter != n->genomeMap->end(); ++iter) {
285 (*(n->genomeMap))[iter->first].delta =

Callers 1

fitMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected