From a82b48504a17969d2f9efea60e72921cd446c796 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Fri, 2 Oct 2015 01:25:15 -0700 Subject: [PATCH] Allocate workers dynamically. --- src/kernel.cpp | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/kernel.cpp b/src/kernel.cpp index 79d8e58..55904e1 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -519,14 +519,16 @@ bool ScanMidstateForward(SHA256_CTX &ctx, uint32_t nBits, uint32_t nInputTxTime, { // TODO: custom threads amount + uint32_t nThreads = boost::thread::hardware_concurrency(); + uint32_t nBegin = SearchInterval.first; uint32_t nEnd = SearchInterval.second; uint32_t nPart = (nEnd - nBegin) / 4; - ScanMidstateWorker workers[4]; + ScanMidstateWorker *workers = new ScanMidstateWorker[nThreads]; boost::thread_group group; - for(int i = 0; i<4; i++) + for(size_t i = 0; i < nThreads; i++) { uint32_t nIntervalBegin = nBegin + nPart * i; uint32_t nIntervalEnd = nBegin + nPart * (i + 1); @@ -540,12 +542,14 @@ bool ScanMidstateForward(SHA256_CTX &ctx, uint32_t nBits, uint32_t nInputTxTime, group.join_all(); solutions.clear(); - for(int i = 0; i<4; i++) + for(size_t i = 0; i < nThreads; i++) { std::vector > ws = workers[i].GetSolutions(); solutions.insert(solutions.end(), ws.begin(), ws.end()); } + delete [] workers; + if (solutions.size() == 0) { // no solutions -- 1.7.1