使用GDB使用OpenMP [英] Using GDB with OpenMP
问题描述
使用GDB我似乎无法为OpenMP线程内打印共享变量的值。例如,使用下面的程序:
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\n", tid, priv, pub);
}
#pragma omp section
{
printf("SECTION 1: tid=%d, priv=%d, pub=%d\n", tid, priv, pub);
}
}
}
return EXIT_SUCCESS;
}
在GDB,如果我在第15行(第0的printf的)打破了,我尝试打印的酒馆的价值,我得到的«在目前情况下无符号酒馆。»消息:
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\n", tid, priv, pub);
(gdb) print pub
No symbol "pub" in current context.
我用gcc编译,并尝试不同的调试标志(-g3 -ggdb3 -gstabs3 -gstabs + 3),没有成功。我也尝试禁用所有优化用-O0,再没有成功。不过,我可以通过使用-gstabs +标志见私有变量的值。
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.
先谢谢了。
推荐答案
当我运行code,我得到了类似的结果。如果你看一下回溯,它会告诉你,你是关系到GCC如何实现的OpenMP的OpenMP的环境中。
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
您可以得到酒吧的值:
(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.
这篇关于使用GDB使用OpenMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!