欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

安卓使用ndk native编程使用 openmp

程序员文章站 2022-06-16 10:06:10
代码#include "omp.h"#pragma omp parallel for环境配置cppFlags "-fopenmp "target_link_libraries( # Specifies the target library. native-lib # Links the target library to the log library ....
代码
#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循环, 频繁操作内存反而慢, 也许可以改成每个线程操作一个连续的地址,彼此不要重叠。

本文地址:https://blog.csdn.net/a302792317/article/details/111030160

相关标签: android