Skip to content

Commit

Permalink
Self-test: multithreaded dataset initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Oct 18, 2023
1 parent ddc6986 commit 5febb8c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,26 @@ int p2pool_test()
return 1;
}

randomx_init_dataset(myDataset, myCache, 0, randomx_dataset_item_count());
{
const uint32_t numThreads = std::max(std::thread::hardware_concurrency(), 1U);
const uint32_t numItems = randomx_dataset_item_count();

std::vector<std::thread> threads;
threads.reserve(numThreads);

for (uint32_t i = 1; i < numThreads; ++i) {
const uint32_t a = (numItems * i) / numThreads;
const uint32_t b = (numItems * (i + 1)) / numThreads;

threads.emplace_back([myDataset, myCache, a, b]() { randomx_init_dataset(myDataset, myCache, a, b - a); });
}
randomx_init_dataset(myDataset, myCache, 0, numItems / numThreads);

for (std::thread& t : threads) {
t.join();
}
}

randomx_release_cache(myCache);

randomx_vm* myMachine = randomx_create_vm(flags, nullptr, myDataset);
Expand Down

0 comments on commit 5febb8c

Please sign in to comment.