I have run simple parallel algorithm drawing the mandelbrot set to test parallel computations on a Nexus 7 (Tegra 3, 4+1 cores). After running several times I get 1.5 seconds for serial and 1.0 for parallel, but parallel and serial come really close to each other at 1.3 seconds.
The square is 700x700 pixels, and the mandelbrot code I use is from
http://rosettacode.org/wiki/Mandelbrot_set#Java
The parallel implementation runs two halves of mandelbrot like this
public void mandelbrotParallel() {
Thread t1 = new Thread(new Runnable() {
public void run() {
mandelbrotOne();
}
});
Thread t2 = new Thread(new Runnable() {
public void run() {
mandelbrotTwo();
}
});
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mHandler.post(new Runnable() {
public void run() {
v.setBmp(bmp);
v.invalidate();
}
});
}
I have run a simple vector addition before and found similar anecdotal results (no scientific rigor). So I wonder if there is anything special one has to do to get Android to fire up multiple cores to get a task done.
Based on quick conversations with Google, it could be that the cores are dormant and wait for the computation to be truly long running (multiple seconds) before the cores are turned on... Is this true ? If so, are there API calls from Java (no JNI) that can be done to preemptively wake up the cores ?
This sounds like a candidate for RenderScript. In a nutshell, it allows you to do computationally expensive operations that take advantage of all available acceleration resources (multiple cores, GPU compute, dsp, etc). From the docs:
Renderscript gives your apps the ability to run operations with automatic parallelization across all available processor cores. It also supports different types of processors such as the CPU, GPU or DSP. Renderscript is useful for apps that do image processing, mathematical modeling, or any operations that require lots of mathematical computation.
You'd have to rewrite your Mandelbrot code in C, but you won't have to break it apart into pieces since parallelization will be taken care of for you.
Using RenderScript from Android code is straightforward as described here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With