openMP is not creating threads in visual studio

后端 未结 4 1938
旧时难觅i
旧时难觅i 2020-12-06 16:26

My openMP version did not give any speed boost. I have a dual core machine and the CPU usage is always 50%. So I tried the sample program given in Wiki. Looks like the openM

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 17:17

    If you want to test out your program with more than one thread, there are several constructs for specifying the number of threads in an OpenMP parallel region. They are, 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

    It sounds like your implementation is defaulting to one thread (assuming you don't have OMP_NUM_THREADS=1 set in your environment).

    To test with 4 threads, for instance, you could add num_threads(4) to your #pragma omp parallel directive.

    As the other answer noted, you won't really see any "speedup" because you aren't exploiting any parallelism. But it is reasonable to want to run a "hello world" program with several threads to test it out.

提交回复
热议问题