我已经运行了简单的并行算法绘制mandelbrot集来测试Nexus 7(Tegra 3,4 4核)上的并行计算.在运行几次之后,我获得1.5秒的串行和1.0的并行,但并行和串行在1.3秒时非常接近.
方块是700×700像素,我使用的mandelbrot代码来自
http://rosettacode.org/wiki/Mandelbrot_set#Java
并行实现像这样运行两半mandelbrot
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();
}
});
}
我之前运行过一个简单的向量,并发现了类似的轶事结果(没有科学严谨性).所以我想知道是否有任何特殊的事情要让Android启动多个内核来完成任务.
基于与谷歌的快速对话,可能是核心处于休眠状态并等待计算在核心打开之前真正长时间运行(多秒)……这是真的吗?如果是这样,是否有来自Java(没有JNI)的API调用可以预先唤醒核心?
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.
你必须用C语言重写你的Mandelbrot代码,但你不必将它分成几部分,因为并行化将为你处理.