Using GDB with OpenMP

前端 未结 2 2083
闹比i
闹比i 2020-12-18 07:26

Using GDB I can\'t seem to print the value of shared variables within OpenMP threads. For example, using the following program:

#include 
#inclu         


        
2条回答
  •  臣服心动
    2020-12-18 08:14

    When I run your code I get similar results. If you look at the backtrace, it tells you that you are inside an OpenMP environment that is related to how GCC implements OpenMP.

    (gdb) backtrace 
    #0  main._omp_fn.0 () at tmp.c:15
    #1  0x000000000040082e in main (argc=1, argv=0x7fffffffe6c8) at tmp.c:7
    

    You can get a value of pub by:

    (gdb) up
    (gdb) print pub
    $1 = 100
    

    but this only gets you the value of pub before the parallel region. You should check the answer by Hristo Iliev for a much more detailed and better description of the situation.

提交回复
热议问题