linux上openmp测试

测试代码:

#include<stdio.h>
#include<stdlib.h>
#include <sys/time.h>


int main(void)
{
    int i,j;
    int sec;
    struct timeval t1, t2;


    gettimeofday(&t1, NULL);
    //#pragma omp parallel
    {
        for (i=0;i<10000;i++)
        {
            for(j=0; j<100000; j++)
                ;
        }
    }
    gettimeofday(&t2, NULL);


    sec = t2.tv_sec*1000 + t2.tv_usec/1000 -  (t1.tv_sec*1000 + t1.tv_usec/1000);
    printf("sec:%d\n", sec);


    return 0;
}


无openmp的测试代码编译方法:

arm-hisiv300-linux-gcc -o noomp_test omp_test.c -static


有openmp的测试代码编译方法:

arm-hisiv300-linux-gcc -fopenmp -o omp_test omp_test.c -static

同时将上面#pragma omp parallel打开


在设备(4核CPU)上测试结果如下:

/home # ./omp_test 
sec:1700ms
/home # ./noomp_test 
sec:5717ms

使用omp的编译比没有omp的要快很多

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值