# PSDEstimator using multiple cores even when n\_jobs=1

**URL:** <https://mne.discourse.group/t/psdestimator-using-multiple-cores-even-when-n-jobs-1/1560>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [July 2, 2018, 11:51am UTC](https://mne.discourse.group/t/psdestimator-using-multiple-cores-even-when-n-jobs-1/1560 "2018-07-02T11:51:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [July 2, 2018, 11:51am UTC](https://mne.discourse.group/t/psdestimator-using-multiple-cores-even-when-n-jobs-1/1560/1 "2018-07-02T11:51:15Z")

</div>

External Email - Use Caution

Hi all,

I found a problem in mne.decoding.PSDEstimator.transform() method. In  
short, it does not respect the attribute "n\_jobs". This problem does not  
exist in MNE 0.14 and only exists in MNE 0.15 and above. I tested only on  
stable versions.

Normally, I restrict the PSD estimation to use a single core (n\_jobs=1)  
because there are many other time-critical processes running together in  
the system. In MNE 0.15 and above, the transform() function uses up to 4  
cores equivalent (over 50% total usage on an 8-core system). This is in  
contrast with the same function in MNE 0.14, where only 1 core is used as  
expected.

The following minimal code replicates the problem.

import numpy as npimport mneimport time  
mne.set\_log\_level('WARNING')

psde = mne.decoding.PSDEstimator(sfreq=512, fmin=1, fmax=40, n\_jobs=1)  
iterations = 1000  
w = np.random.rand(1, 64, 256)print('Start %d iteratinos' % iterations)  
t\_start = time.time()for i in range(iterations):  
&nbsp;&nbsp;&nbsp;&nbsp;psd = psde.transform(w)print('Took %.3f seconds' % (time.time() - t\_start))

In Windows 10 Pro with i7-4790K CPU (8 logical cores), I ran the above code  
5 times each with 1000 computations. In the idle period, the cpu usage was  
maximum 3%.

\*Results\*  
- mne 0.14: CPU usage 17% (equivalent to approx. 1 core = 12.5%)  
10.461, 10.755, 10.861, 10.843, 10.636 seconds.  
Average: 10.711s per 1000 computations.

- mne 0.15, 0.16: CPU usage 56% (equivalent to approx. 4 cores = 50%)  
11.608, 10.737, 10.734, 11.283, 10.909 seconds.  
Average: 11.054s per 1000 computations.

So, I don't see much difference in computation time but the CPU usage was  
4x higher in MNE 0.15 and above. It seems to me that there's a bug in  
PSDEstimator class that always prefers to use multiple cores even when  
n\_jobs=1, causing a lot of overhead by forced multiprocessing.

Please have a look and fix this issue. Thanks!

Best,  
Kyuhwa Lee  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20180702/bc5b70df/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20180702/bc5b70df/attachment.html)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [July 3, 2018, 8:59pm UTC](https://mne.discourse.group/t/psdestimator-using-multiple-cores-even-when-n-jobs-1/1560/2 "2018-07-03T20:59:41Z")

</div>

External Email - Use Caution

hi Kyuhwa,

even with n\_jobs=1 if you use a multithreaded linear algebra library like  
MKL or openblas you will use more than 1 core.

to prevent this you should read about the environment variable :  
OMP\_NUM\_THREADS

HTH  
Alex
