将 GDB 与 OpenMP 一起使用

编程入门 行业动态 更新时间:2024-10-10 03:23:37
本文介绍了将 GDB 与 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 ", tid, priv, pub); } #pragma omp section { printf("SECTION 1: tid=%d, priv=%d, pub=%d ", tid, priv, pub); } } } return EXIT_SUCCESS; }

在 GDB 中,如果我在第 15 行中断(第 0 节的 printf),并尝试打印 "pub" 的值,我会得到 «No symbol "pub" in current context.»留言:

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.

我正在使用 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.

提前致谢.

推荐答案

当我运行你的代码时,我得到了类似的结果.如果您查看回溯,它会告诉您您处于与 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

您可以通过以下方式获取 pub 的值:

You can get a value of pub by:

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

但这只会让您在并行区域之前获得 pub 的值.您应该查看 Hristo Iliev 的答案,以获得更详细和更好的情况描述.

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 一起使用

本文发布于:2023-11-25 20:23:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631221.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:GDB   OpenMP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!