1

I am using openmp in my program, but instead of speeding up things its slowing down. My guess is that its because it spawns thread everytime in the loop openmp is used. Is there way to spawn threads once in the program.

pythonic
  • 20,589
  • 43
  • 136
  • 219
  • 1
    There's about a gazzilion other things that could be slowing it down besides spawning threads. Can you provide some more detail? Such as a particular loop? – Mysticial May 15 '12 at 15:41
  • Possible duplicate of http://stackoverflow.com/questions/10589798/openmp-create-threads-only-once – Hristo Iliev May 15 '12 at 15:45
  • This question has already been answer [here](http://stackoverflow.com/questions/8132565/how-do-i-ask-openmp-to-create-threads-only-once-at-each-run-of-the-program). Basically, most OpenMP runtime create threads only at the beginning of the program. So there must be another reason for the slowdown. – betabandido May 15 '12 at 17:17
  • 1
    Awakening a thread from the pool and assigning job to it takes some time although not as much as creating it anew. That's what the `OMP_WAIT_POLICY` environment switch is for - setting it to `ACTIVE` _may_ make threads busy wait instead (thus keeping high CPU usage even in serial regions of the code) which _may_ decrease the overhead but not remove it completely. – Hristo Iliev May 16 '12 at 10:16

1 Answers1

1

you should definitely provide the code, per other comments.

Generally, openMP applications are designed to run between 1-4x as many threads as their are processors.

For anyone who is interested in controlling the number of threads spawned, from : https://computing.llnl.gov/tutorials/openMP/

How Many Threads?

The number of threads in a parallel region is determined by the following factors, in order of precedence:

  • Evaluation of the IF clause
  • Setting of the NUM_THREADS clause
  • Use of the omp_set_num_threads() library function
  • Setting of the OMP_NUM_THREADS environment variable
  • Implementation default - usually the number of CPUs on a node, though it could be dynamic (see next bullet).

Threads are numbered from 0 (master thread) to N-1

An example of how to set the number threads environment variable :

export OMP_NUM_THREADS=8

Hope it helps.

Austin
  • 1,122
  • 2
  • 10
  • 27