gdb 调试openmp多线程程序 示例介绍
2015-11-15 15:09
495 查看
2014-05-21 11:46 427人阅读 评论(0) 收藏 举报
[html] view
plaincopy
首先一个简单程序源代码:
[html] view
plaincopy
[html] view
plaincopy
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <omp.h>
4 int main(int argc, char * argv[]){
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++)
10 {
11 k=10;
12 m=10;
13 n=k+m;
14 printf("i=%d,n=%d,thread_id=%d\n",i,n, omp_get_thread_num());
15 if(k>1)
16 printf("OK\n");
17 }
18 return 1;
19 }
编译成 test_omp
step 1:gdb test_omp
step 2:break 15
step 3:run
[html] view
plaincopy
(gdb) r
Starting program: /home/xqc/gmptest/test_omp
[Thread debugging using libthread_db enabled]
i=0,threads_num=1
i=0,thread_id=0
[New Thread 0x7ffff740f700 (LWP 17108)]
[New Thread 0x7ffff6c0e700 (LWP 17109)]
[New Thread 0x7ffff640d700 (LWP 17110)]
Breakpoint 1, main.omp_fn.0 (.omp_data_i=0x7fffffffe3b0) at test_omp.c:15
15 k=10;
(gdb)
[html] view
plaincopy
(gdb) info threads
4 Thread 0x7ffff640d700 (LWP 17110) main.omp_fn.0 (.omp_data_i=0x7fffffffe3b0) at test_omp.c:15
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) main.omp_fn.0 (.omp_data_i=0x7fffffffe3b0) at test_omp.c:15
(gdb)
step4: thread 2
[html] view
plaincopy
(gdb) thread 2
[Switching to thread 2 (Thread 0x7ffff740f700 (LWP 17108))]#0 main.omp_fn.0 (.omp_data_i=0x7fffffffe3b0)
at test_omp.c:15
15 k=10;
(gdb)
至此,就可以对thread 2号线程进行debug了。
[html] view
plaincopy
首先一个简单程序源代码:
[html] view
plaincopy
[html] view
plaincopy
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <omp.h>
4 int main(int argc, char * argv[]){
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++)
10 {
11 k=10;
12 m=10;
13 n=k+m;
14 printf("i=%d,n=%d,thread_id=%d\n",i,n, omp_get_thread_num());
15 if(k>1)
16 printf("OK\n");
17 }
18 return 1;
19 }
编译成 test_omp
step 1:gdb test_omp
step 2:break 15
step 3:run
[html] view
plaincopy
(gdb) r
Starting program: /home/xqc/gmptest/test_omp
[Thread debugging using libthread_db enabled]
i=0,threads_num=1
i=0,thread_id=0
[New Thread 0x7ffff740f700 (LWP 17108)]
[New Thread 0x7ffff6c0e700 (LWP 17109)]
[New Thread 0x7ffff640d700 (LWP 17110)]
Breakpoint 1, main.omp_fn.0 (.omp_data_i=0x7fffffffe3b0) at test_omp.c:15
15 k=10;
(gdb)
[html] view
plaincopy
(gdb) info threads
4 Thread 0x7ffff640d700 (LWP 17110) main.omp_fn.0 (.omp_data_i=0x7fffffffe3b0) at test_omp.c:15
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) main.omp_fn.0 (.omp_data_i=0x7fffffffe3b0) at test_omp.c:15
(gdb)
step4: thread 2
[html] view
plaincopy
(gdb) thread 2
[Switching to thread 2 (Thread 0x7ffff740f700 (LWP 17108))]#0 main.omp_fn.0 (.omp_data_i=0x7fffffffe3b0)
at test_omp.c:15
15 k=10;
(gdb)
至此,就可以对thread 2号线程进行debug了。
相关文章推荐
- shell入门-特殊符号
- Tomcat7中NIO处理分析(一)
- 内存对齐的初步讲解--linux和windows平台下内存分配的差异
- shell常用命令
- CodeTyphon32中自带例子源码:类似Photoshop的分层处理图像
- linux中头文件的位置
- Nginx 知识
- Nginx重定向[Rewrite]配置
- samba服务器配置
- shell-bash学习03 别名、日期、函数
- Linux常用命令
- Linux alien命令
- Linux cpulimit命令
- Linux安装nginx
- Lodop(V6.x)使用说明及样例
- Ubuntu启用休眠hibernate
- nginx location匹配规则
- linux跨平台共享之samba 配置方法
- 信息安全系统设计基础实验一:Linux开发环境的配置和使用(135317、135337)
- Swing中弹出对话框的几种方式_JOptionPane.showMessageDialog等详解