Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

[SOLVED] Multi-threading slower than single thread

$
0
0
I’ve implemented a neural network where all neurons are individual QRunnable. Each neuron only has a simple calculation (sigmoid function), but the neurons are executed a couple million times. I’m running a VM with 4 cores. When I execute the neurons sequentially, my entire process takes 4 minutes. I start the neurons as follows: for(int i = 0; i < mNeurons.size(); ++i) {  mNeurons[i]->run(); } Then I tried to make my neural network multi-threaded by executing the neurons in parallel. Note that all neurons are created on startup. When using threads, my process needs about 45 minutes. This is how I run them: QThreadPool *pool = QThreadPool::globalInstance(); for(int i = 0; i < mNeurons.size(); ++i) {  pool->start(mNeurons[i]); } pool->waitForDone(); I thought there was something wrong with QThreadPool, so I decided to implement all neurons as separate threads and removing the pool. However, this didn’t influence the execution – still 45 minutes. Does anyone know why it takes so much longer to execute when calling start() instead of run()? Is there so much work done in start, before run() is executed?

Viewing all articles
Browse latest Browse all 18427

Trending Articles