用户登录
用户注册

分享至

安卓使用ndk native编程使用 openmp

  • 作者: PassBusiness
  • 来源: 51数据库
  • 2021-08-13
代码
#include "omp.h"
#pragma omp parallel for

环境配置build.gradle

        externalNativeBuild {
            cmake {
                cppFlags "-fopenmp" 
            }
        }
#CMakeList.txt
target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
        omp

如果提示缺少libomp.so.将ndk(我使用的是ndk21)里面的libomp.so复制到jniLibs/armeabi-v7a

armeabi-v7a需要自己配置选择不同的文件名.

?

对于提升效果比较,clock函数在ctime中,用于统计cpu时钟时间,在程序是单线程时,相对准确,但是如果开启多线程,则会出现很大误差。可以使用下面函数记录时间差.

gettimeofday

armv7 测试 for循环, 频繁操作内存反而慢, 也许可以改成每个线程操作一个连续的地址,彼此不要重叠。

软件
前端设计
程序设计
Java相关