Using GDB I can't seem to print the value of shared variables within OpenMP threads. For example, using the following program:
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int priv, tid, pub = 100;
#pragma omp parallel private(priv, tid) num_threads(2)
{
tid = omp_get_thread_num();
priv = tid * 10;
#pragma omp sections
{
#pragma omp section
{
printf("SECTION 0: tid=%d, priv=%d, pub=%d
", tid, priv, pub);
}
#pragma omp section
{
printf("SECTION 1: tid=%d, priv=%d, pub=%d
", tid, priv, pub);
}
}
}
return EXIT_SUCCESS;
}
In GDB, if I break at line 15 (the printf of section 0), and I try to print the value of "pub", I get the ?No symbol "pub" in current context.? message:
Breakpoint 1, main._omp_fn.0 () at omp_simplesec.c:15
15 printf("SECTION 0: tid=%d, priv=%d, pub=%d
", tid, priv, pub);
(gdb) print pub
No symbol "pub" in current context.
I am compiling with GCC, and tried different debugging flags (-g3 -ggdb3 -gstabs3 -gstabs+3), without success. I also tried disabling all optimizations with -O0, again with no success. However, I can see the value of private variables by using the -gstabs+ flag.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…