c++ - 如何修复 OpenMP 程序的 gdb 运行中的线程数

标签 c++ multithreading gdb openmp

我正在尝试在 Mac OSX 机器上使用 gdb 调试 OpenMP C++ 程序。 (好的,技术上使用“ggdb”。)无论我将 OMP_NUM_THREADS 设置为什么,gdb 都会尝试在 8 个线程上运行代码。为什么是这样?有没有办法让我自己告诉它代码将运行的线程数?

最佳答案

Well, I guess I'm showing my ignorance, but I set it just before I start up the debugger. Am I supposed to do it within the debugger?

您应该在 gdb 中设置环境变量 OMP_NUM_THREADS:

(gdb) set environment OMP_NUM_THREADS 2

另请参阅内置帮助:

(gdb) help set environment 
Set environment variable value to give the program.
Arguments are VAR VALUE where VAR is variable name and VALUE is value.
VALUES of environment variables are uninterpreted strings.
This does not affect the program until the next "run" command.

关于c++ - 如何修复 OpenMP 程序的 gdb 运行中的线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50723675/

相关文章:

c# - 线程停止

c++ - 调试:跟踪(和区分)同一程序的两个版本的函数调用树

c++ - 链表中的节点 *next

c++ - STL bitset::count() 方法的性能如何?

java - 无法通过 UI 从 AsyncTask 发回数据

linux - 如何查看已打开套接字连接的进程的线程ID?

linux - 使用 GDB 在 Assembly 中修改后程序不会运行

c - 如何执行逐行崩溃调试来处理 c 中的 "has stopped working"错误?

c++ - 将二进制数据写入 private ofstream 会产生意想不到的结果

c++ - LoadLibrary() 文件路径