GDB debugging OpenMP Multi-threaded Routines Sample Introduction

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.