Debugging Multi-threaded Program with Intel(R) Debugger

When debugging multi-threaded code, you can face following kinds of problem:

- Which thread I'm running with?

- How to stop to one thread?

- How to debug on one thread?

This article will provide useful tips in resolving these kinds of problem when debugging mutl-threaded program under Intel(R) Debugger.

  • Run / Continue

        When Run or Continue command is used and run to a parallel region, all threads will run at the same time as defined in your original program. For example:

$ idbc ./a.out
Intel(R) Debugger for applications running on Intel(R) 64, Version 12.1, Build [77.329.14]
------------------
object file name: ./a.out
Reading symbols from /home/ychen41/test/a.out...done.
(idb) b 86
Breakpoint 1.1 at 0x403ed5: file /home/ychen41/test/testomp.f90, line 86.
Breakpoint 1.2 at 0x403f72: file /home/ychen41/test/testomp.f90, line 86.
Breakpoint 1.3 at 0x403ff2: file /home/ychen41/test/testomp.f90, line 86.
(idb) run
Starting program: /home/ychen41/test/a.out
[New Thread 2137 (LWP 2137)]
  Range to check for Primes:           1    10000000
[New Thread 2138 (LWP 2138)]
[New Thread 2139 (LWP 2139)]
  We are using           2  thread(s)

Breakpoint 1.1, ompprime () at /home/ychen41/test/testomp.f90:86
86      do index = start, end, 2   !workshared loop
(idb) info threads
    1 initial thread 2137 (LWP 2137) [thawed] stopped at  0x403ed5 in ompprime::L_MAIN___73__par_region0_2_88 at /home/ychen41/test/testomp.f90:86 OpenMP team memberships: (5,0), (1,0)

    2 unknown thread 2138 (LWP 2138) [thawed] stopped at  0x3b8fe0b7a9 in pthread_cond_timedwait@@GLIBC_2.3.2 from /lib64/libpthread-2.12.so

*   3 openmp thread 2139 (LWP 2139) [thawed] stopped at  0x403ed5 in ompprime::L_MAIN___73__par_region0_2_88 at /home/ychen41/test/testomp.f90:86 OpenMP team memberships: (5,1)

  • Step / Next

        When command Step or Next is used, only the Current thread will run, and the other threads will be pending. For the above example,

(idb) step
The "step" command was not completed.
86      do index = start, end, 2   !workshared loop
(idb) info thread
*   1 initial thread 2137 (LWP 2137) [thawed] stopped at  0x403ed5 in ompprime::L_MAIN___73__par_region0_2_88 at /home/ychen41/test/testomp.f90:86 OpenMP team memberships: (5,0), (1,0)

    2 unknown thread 2138 (LWP 2138) [thawed] stopped at  0x3b8fe0b7a9 in pthread_cond_timedwait@@GLIBC_2.3.2 from /lib64/libpthread-2.12.so

    3 openmp thread 2139 (LWP 2139) [thawed] stopped at  0x403edb in ompprime::L_MAIN___73__par_region0_2_88 at /home/ychen41/test/testomp.f90:86 OpenMP team memberships: (5,1)

You can find only 3 openmp thread 2139 is moved forward to address 0x403edb, and 1 initial thread 2016 is unchanged. However this time the current thread has been switched to 1 initial thread 2016 (* is moved besides 1 initial thread).

  • Thread

Use Thread command to show or change your current thread. Syntax is as following:

thread [ID]

Where ID stands for the identifier of the thread to which you want to switch.

Continue the above example:

(idb) thread 3
*   3 openmp thread 2139 (LWP 2139) [thawed] stopped at  0x403edb in ompprime::L_MAIN___73__par_region0_2_88 at /home/ychen41/test/testomp.f90:86 OpenMP team memberships: (5,1)

So that current thread is moved back to 3 openmp thread 2139.

  • Info Threads

Command Info Threads help display IDs and status of currently known threads. As you can see in the above example, it lists all known threads, their status, and which thread is the current one with *.
(idb) info thread
    1 initial thread 2137 (LWP 2137) [thawed] stopped at  0x403ed5 in ompprime::L_MAIN___73__par_region0_2_88 at /home/ychen41/test/testomp.f90:86 OpenMP team memberships: (5,0), (1,0)

    2 unknown thread 2138 (LWP 2138) [thawed] stopped at  0x3b8fe0b7a9 in pthread_cond_timedwait@@GLIBC_2.3.2 from /lib64/libpthread-2.12.so

*   3 openmp thread 2139 (LWP 2139) [thawed] stopped at  0x403edb in ompprime::L_MAIN___73__par_region0_2_88 at /home/ychen41/test/testomp.f90:86 OpenMP team memberships: (5,1)
 

Pour de plus amples informations sur les optimisations de compilation, consultez notre Avertissement concernant les optimisations.