多在AndroidAndroid

2023-09-05 06:41:28 作者:只是难过不能陪你一起老

我已经执行了一些测试,在Android上,以验证有多好一个算法(如FFT)的性能,如果是并行可以得到改善。我使用的pthread用JNI(FFTW)和Java线程(从JTransforms)实现的算法。非但没有利用如预期的线程更好的表现,我已经得到了使用串行算法更好的结果。目前还不清楚我为什么我有这些结果,因为我想执行的多核器件的测试。看来,使用Android系统的调度算法是从Linux使用一个有点不同,你的运气了,如果你想使用一个以上的CPU做多处理在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.

例与FFTW: 该JNI code在 https://github.com/maxrosan /DspBenchmarking/blob/master/jni/fftw_jni.c 及其接口是https://github.com/maxrosan/DspBenchmarking/blob/master/src/br/usp/ime/dspbenchmarking/algorithms/fftw/FFTW.java.

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'.

例与纯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.

推荐答案

如果你的程序有运行在持续时期内多个CPU密集型线程,内核将转向线程独立内核。否则,内核是由两件事情的动机:

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的内核打开时关闭可能的,只有让他们在CPU的要求,需要他们。究竟是什么构成了持续时间,从相同也可以不同。

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.

我放在一起的样本code两位演示中使用多个内核( C版,的Java版本)。

I put together two bits of sample code that demonstrate multiple cores in use (C version, Java version).

通过一个根深蒂固的设备,有 systrace 支持,你可以看到图形其中线程每个内核上运行。

With a rooted device that has systrace support you can actually see graphically which thread is running on each core.

更新: 我想这可能有助于有一个例子,所以我包裹着我MultiCore.java测试里面一个示例应用程序并运行它在4.3的Nexus 4在systrace。我创建了一个网页,解释结果。

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.