# Parallel processing on Android device?

**URL:** <https://forum.opencv.org/t/parallel-processing-on-android-device/2362>\
**Category:** Android/Java\
**Tags:** dnn\
**Created:** [March 25, 2021, 1:49pm UTC](https://forum.opencv.org/t/parallel-processing-on-android-device/2362 "2021-03-25T13:49:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maakus](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@maakus](https://forum.opencv.org/u/maakus)\
**Post date:** [March 25, 2021, 1:49pm UTC](https://forum.opencv.org/t/parallel-processing-on-android-device/2362/1 "2021-03-25T13:49:38Z")

</div>

Hi,  
I am running the same C++ Code on different machines: Intel PC, iOS and Android. On PC and iOS, execution nicely parallelizes over several CPU cores. But not so on Android devices.

Specifically, I am running DNN inference on a detection model in ONNX format.

I have used the official releases (4.5.1) for all platforms. But I have also tried own builds for Android, based on the build scripts from the repository, optionally enabling OpenMP or Tengine. None of these ran inference in parallel.  
I have found this very related discussion regarding RaspberryPi: [How to use multi core for DNN in ARM cpu · Issue #16692 · opencv/opencv · GitHub](https://github.com/opencv/opencv/issues/16692)  
(which made me try out OpenMP), but which hasnt helped yet :-/

So the initial question is regarding expectations: is it expected to see OpenCV run inference on multiple cores on ARM-based Android smartphones devices at all? Which is the most likely (or proven) threading library for Android?

Added info:  
For my own builds, I am using clang on OSX.  
More info:  
getNumThreads() tells me OpenCV is aware of the availability of several cores – it just dont use them!

Thanks 🙂  
maakus

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 25, 2021, 5:34pm UTC](https://forum.opencv.org/t/parallel-processing-on-android-device/2362/2 "2021-03-25T17:34:06Z")

</div>

if you can get OpenCL working, that would accelerate a lot of things. opencv’s DNN module has an OpenCL backend.

---

<div class="post-metadata">

**Author:** ![maakus](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@maakus](https://forum.opencv.org/u/maakus)\
**Post date:** [March 26, 2021, 7:30am UTC](https://forum.opencv.org/t/parallel-processing-on-android-device/2362/3 "2021-03-26T07:30:51Z")

</div>

Thank you for the advice, crackwitz!  
Do you expect this to be a matter of getting my build chain to use OpenCL? Or would I need to dig into OpenCV’s cv::ocl:: implementations? I noted that there is no `VENDOR_ARM` among `VENDOR_AMD`, `VENDOR_INTEL`, … in the vendor enum: [OpenCV: cv::ocl::Device Class Reference](https://docs.opencv.org/master/d7/d9f/classcv_1_1ocl_1_1Device.html)

---

<div class="post-metadata">

**Author:** ![maakus](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@maakus](https://forum.opencv.org/u/maakus)\
**Post date:** [March 26, 2021, 9:09am UTC](https://forum.opencv.org/t/parallel-processing-on-android-device/2362/4 "2021-03-26T09:09:12Z")

</div>

I can get OpenCL to be available. But the only available device type is the GPU (Mali). No `TYPE_CPU` available – at least as far as I could get. :-/

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 26, 2021, 4:49pm UTC](https://forum.opencv.org/t/parallel-processing-on-android-device/2362/5 "2021-03-26T16:49:06Z")

</div>

and that’s good because you can already run stuff on the CPU

---

<div class="post-metadata">

**Author:** ![maakus](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@maakus](https://forum.opencv.org/u/maakus)\
**Post date:** [March 29, 2021, 11:05am UTC](https://forum.opencv.org/t/parallel-processing-on-android-device/2362/6 "2021-03-29T11:05:39Z")

</div>

When running on the CPU, is it expected to run on more than one core on Android devices, then?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 29, 2021, 4:43pm UTC](https://forum.opencv.org/t/parallel-processing-on-android-device/2362/7 "2021-03-29T16:43:35Z")

</div>

don’t know if I’d say “expected” but it should certainly be possible. OpenCV can use a ton of parallelism mechanisms. to name one, OpenMP is built into many compilers these days. you can see enabled “parallel” frameworks during cmake configuration step. my build says

```
Parallel framework: Concurrency
```
