This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Limit CPU usage to one thread on cluster

0 votes

Hi,

I'm running a dolfin script on a cluster. I found out that this since job uses a CPU >> 100%, so it's not restricted to a single thread, which makes the running very inefficient and make the process claim way too much space on the cluster. I tried several things: I added

export OPENBLAS_NUM_THREADS=1

to my bash_profile and bashrc files. This works for non-dolfin code, but not for dolfin. I also tried something like

dolfin.parameters["num_threads"] = 1

following http://fenicsproject.org/qa/4078/dg-solve-in-parallel.
Both don't really help.
My question is: where to put the num_threads lines to make them effective? Is there a different way to limit CPU usage for dolfin jobs on a cluster to single thread per job?

Thanks,

Adriaan

asked Dec 4, 2015 by Adriaan FEniCS Novice (660 points)

1 Answer

+2 votes
 
Best answer

If you set OMP_NUM_THREADS=1 in your environment variables, it should work for DOLFIN too.

answered Dec 4, 2015 by chris_richardson FEniCS Expert (31,740 points)
selected Dec 4, 2015 by Adriaan

I did add that to my bash files and restarted, but didn't help.

Are you sure the environment variables are applied when you start your parallel job? On most systems, setting OMP_NUM_THREADS=1 works. Maybe you can check your environment variables from within DOLFIN, e.g. by using os.environ

This helped me out! I added

import os
os.environ['OMP_NUM_THREADS'] = '1'

and all jobs are perfectly restricted to one thread.

Thanks a lot for the quick reply!

...