Run a single thread synchronously

This commit is contained in:
tevador 2018-12-23 15:12:54 +01:00
parent c05947db09
commit 03913d0e81

View file

@ -206,19 +206,29 @@ int main(int argc, char** argv) {
else { else {
RandomX::Cache* cache = dataset.cache; RandomX::Cache* cache = dataset.cache;
RandomX::datasetAlloc(dataset); RandomX::datasetAlloc(dataset);
auto perThread = RandomX::DatasetBlockCount / threadCount; if (threadCount > 1) {
auto remainder = RandomX::DatasetBlockCount % threadCount; auto perThread = RandomX::DatasetBlockCount / threadCount;
for (int i = 0; i < threadCount; ++i) { auto remainder = RandomX::DatasetBlockCount % threadCount;
auto count = perThread + (i == threadCount - 1 ? remainder : 0); for (int i = 0; i < threadCount; ++i) {
if (softAes) { auto count = perThread + (i == threadCount - 1 ? remainder : 0);
threads.push_back(std::thread(&RandomX::datasetInit<true>, cache, dataset, i * perThread, count)); if (softAes) {
threads.push_back(std::thread(&RandomX::datasetInit<true>, cache, dataset, i * perThread, count));
}
else {
threads.push_back(std::thread(&RandomX::datasetInit<false>, cache, dataset, i * perThread, count));
}
} }
else { for (int i = 0; i < threads.size(); ++i) {
threads.push_back(std::thread(&RandomX::datasetInit<false>, cache, dataset, i * perThread, count)); threads[i].join();
} }
} }
for (int i = 0; i < threads.size(); ++i) { else {
threads[i].join(); if (softAes) {
RandomX::datasetInit<true>(cache, dataset, 0, RandomX::DatasetBlockCount);
}
else {
RandomX::datasetInit<false>(cache, dataset, 0, RandomX::DatasetBlockCount);
}
} }
delete cache; delete cache;
threads.clear(); threads.clear();
@ -238,11 +248,16 @@ int main(int argc, char** argv) {
} }
std::cout << "Running benchmark (" << programCount << " programs) ..." << std::endl; std::cout << "Running benchmark (" << programCount << " programs) ..." << std::endl;
sw.restart(); sw.restart();
for (int i = 0; i < vms.size(); ++i) { if (threadCount > 1) {
threads.push_back(std::thread(&mine, vms[i], std::ref(atomicNonce), std::ref(result), programCount, i)); for (int i = 0; i < vms.size(); ++i) {
threads.push_back(std::thread(&mine, vms[i], std::ref(atomicNonce), std::ref(result), programCount, i));
}
for (int i = 0; i < threads.size(); ++i) {
threads[i].join();
}
} }
for (int i = 0; i < threads.size(); ++i) { else {
threads[i].join(); mine(vms[0], std::ref(atomicNonce), std::ref(result), programCount, 0);
} }
double elapsed = sw.getElapsed(); double elapsed = sw.getElapsed();
std::cout << "Calculated result: "; std::cout << "Calculated result: ";