C++最简单的多线程实现

    之前跑实验的时候师兄给我炫了一招,虽然一直知道师兄代码很腻害,所以学到新东西也是要记下来好。这里将一种最简单的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-thread
	for(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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值