我正在尝试在 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/