Multiprocessing on Android
I've been executing some tests on Android in order to verify how good the performance of an algorithm (like FFT) can be improved if it is parallelized. I've implemented the algorithms by using pthread with JNI (FFTW) and Java threads (from JTransforms). Instead of getting a better performance by using threads as expected, I've got better results using serial algorithm. It is unclear to me why I've got those results since I'd executed those tests on multicore devices. It seems that the scheduling algorithm used by Android system is kinda different from the one used by Linux and you're out of luck if you want to use more than one CPU to do multiprocessing on Android.
Example with FFTW: The JNI code is in https://github.com/maxrosan/DspBenchmarking/blob/master/jni/fftw_jni.c and its interface is https://github.com/maxrosan/DspBenchmarking/blob/master/src/br/usp/ime/dspbenchmarking/algorithms/fftw/FFTW.java.
The method called in tests is 'execute'.
Example with pure Java: https://github.com/maxrosan/DspBenchmarking/blob/master/src/br/usp/ime/dspbenchmarking/algorithms/jtransforms/fft/DoubleFFT_1D2TAlgorithm.java
Here the method called is 'perform'.
'execute' and 'perform' are called inside another thread.
If your program has multiple CPU-intensive threads running for a sustained period, the kernel will shift threads to separate cores. Otherwise, the kernel is motivated by two things:
Android turns cores off when possible, and only enables them when CPU demand requires them. What exactly constitutes a "sustained period" varies from device to device.
I put together two bits of sample code that demonstrate multiple cores in use (C version, Java version).
With a rooted device that has systrace support you can actually see graphically which thread is running on each core.
Update: I thought it might help to have an example, so I wrapped my MultiCore.java test inside a sample app and ran it on a 4.3 Nexus 4 under systrace. I created a page that explains the results.
链接地址: http://www.djcxy.com/p/14912.html上一篇: 内部存储的安全性如何?
下一篇: Android上的多重处理