当执行在并行区域中停止时,where 命令会显示既包含数个运行时库调用又包含外联子例程的栈跟踪。使用编译器如何转换 OpenMP 代码中的 Fortran 示例,并且在第 15 行停止执行时,where 命令将生成以下栈跟踪。
[t@4 l@4]: where current thread: t@4 =>[1] _$d1A12.MAIN_(), line 15 in "example.f90" [2] __mt_run_my_job_(0x45720, 0xff82ee48, 0x0, 0xff82ee58, 0x0, 0x0), at 0x16860 [3] __mt_SlaveFunction_(0x45720, 0x0, 0xff82ee48, 0x0, 0x455e0, 0x1), at 0x1aaf0 |
栈的顶帧是外联函数帧。尽管代码是外联的,源代码行号仍映射回 15。其他两帧用于运行时库例程。
当执行在并行区域中停止时,来自从属线程的 where 命令并未使栈回溯至其父线程(如上例所示)。但是,主线程中的 where 命令却具有完全回溯:
[t@4 l@4]: thread t@1 t@1 (l@1) stopped in _$d1A12.MAIN_ at line 15 in file "example.f90" 15 sum = sum + a(i) [t@1 l@1]: where current thread: t@1 =>[1] _$d1A12.MAIN_(), line 15 in "example.f90" [2] __mt_run_my_job_(0x41568, 0xff82ee48, 0x0, 0xff82ee58, 0x0, 0x0), at 0x16860 [3] __mt_MasterFunction_(0x1, 0x0, 0x6, 0x0, 0x0, 0x40d78), at 0x16150 [4] MAIN(), line 12 in "example.f90" |
如果线程数不大,则可以通过以下方法确定执行如何到达从属线程中的断点:使用 threads 命令(请参见 threads 命令)列出所有线程,然后切换到各个线程以确定哪个线程是主线程。