pythonic
pythonic

Reputation: 21655

How to spawn threads once with openmp

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.

Upvotes: 1

Views: 2250

Answers (1)

Austin
Austin

Reputation: 1132

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.

Upvotes: 1

Related Questions