First, a simple program source code:
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <omp.h> 4 int main (int argc, char * ar Gv[]) { 5 int i, k,m,n; 6 printf ("i=%d,threads_num=%d\n", I, Omp_get_num_threads ()); 7 printf ("i=%d,thread_id=%d\n", I, Omp_get_thread_num ()); 8 #pragma omp parallel for 9 for (i=0;i<4;i++) Ten {one k=10; m=10; n=k+m; printf ("i=% D,n=%d,thread_id=%d\n ", I,n, Omp_get_thread_num ()); if (k>1) printf ("ok\n"); + 1; 19}
Compile into Test_omp
Step 1:gdb Test_omp
Step 2:break 15
Step 3:run
(GDB) rstarting program:/home/xqc/gmptest/test_omp [Thread Debugging using libthread_db enabled]i=0,threads_num=1i=0, Thread_id=0[new thread 0x7ffff740f700 (LWP 17108)][new thread 0x7ffff6c0e700 (LWP 17109)][new thread 0x7ffff640d700 (LWP 1 7110)]breakpoint 1, main.omp_fn.0 (. omp_data_i=0x7fffffffe3b0) at test_omp.c:1515 k=10; (gdb)
(GDB) Info Threads 4 Thread 0x7ffff640d700 (LWP 17110) main.omp_fn.0 (. omp_data_i=0x7fffffffe3b0) at Test_omp.c : 3 Thread 0x7ffff6c0e700 (LWP 17109) main.omp_fn.0 (. omp_data_i=0x7fffffffe3b0) at Test_omp.c:15 2 Thread 0x7ffff740f700 (LWP 17108) main.omp_fn.0 (. omp_data_i=0x7fffffffe3b0) at test_omp.c:15* 1 Thread 0x7ffff7fdf780 (LWP 17105)
Step4:thread 2
(GDB) thread 2[switching to thread 2 (thread 0x7ffff740f700 (LWP 17108))] #0 main.omp_fn.0 (. omp_data_i= 0x7fffffffe3b0) at test_omp.c:1515
At this point, you can debug the thread Line 2 line.