C++最简单的多线程实现
来源:互联网 发布:php开源crm统 编辑:程序博客网 时间:2024/06/07 09:22
之前跑实验的时候师兄给我炫了一招,虽然一直知道师兄代码很腻害,所以学到新东西也是要记下来好。这里将一种最简单的C++多线程实现方法,特点就是简单粗暴。代码如下,需要包括"omp.h"头文件。
#include<iostream>#include"omp.h"using namespace std;int main(int argc, char * argv[]){#pragma omp parallel for //This line of code is the definition of using multi-threadfor(int i=0; i<5; i++){cout << "I am the "<< i<< endl;}}
在ubuntu环境下可以把上述文件存为test.cpp,可以用命令行也可以直接操作啊,现在的linux环境真是方便= =
Then compile and run the test.cpp file in Linux
g++ -fopenmp test.cpp // that -fopenmp is most important./a.out
Then you can see the result
在linux环境下编译然后用VS运行的结果来忽悠大家?不能忍...请大家海涵......
And tips:
The code of Learning Graph Matching in PAMI cannot be make properly is the reason for the second command, there's no -fopenmp in it.
Thus you need to add this in the Makefile archive.
0 0
- C++最简单的多线程实现
- 最简单的多线程
- linux c最简单多线程例子:
- C语言 压栈的最简单实现
- C#,Castle,NHibernate,Oracle,最简单的实现
- c语言实现最简单的写文件操作
- Linux C 实现最简单的ICMP_ECHO请求报文发送
- 多线程~~简单的线程创建,C语言实现
- c语言 多线程的简单实现 线程锁
- 多线程~~简单的线程创建,C语言实现
- 多线程专题之最简单的线程
- 最简单的 python 多线程示例
- 创建一个最简单的windows多线程
- 最简单的多线程样例
- pthread最简单的多线程编程-001
- pthread最简单的多线程编程-002
- pthread最简单的多线程编程-003
- pthread最简单的多线程编程-004
- 每2秒钟刷新查看MySQL进程proceslist状态
- Android中一些要写入的权限
- 静态单链表
- 使用storyboard实现页面跳转,简单的数据传递
- 第十一周项目二——求最大公约数(2)
- C++最简单的多线程实现
- 博客开张,解决问题记录
- java多线程向数据库中加载数据
- STM32神舟III号 驱动直流电机学习(二)
- 制作&&修改CentOS Livecd
- UILabe动态设置高度
- 牛顿迭代法实现平方根函数sqrt
- android ListView 几个重要属性
- debug03:“case expressions must be constant expression”报错的破解