android - 多核安卓

标签 android multicore

我已经运行简单的并行算法绘制 mandelbrot 集来测试 Nexus 7(Tegra 3、4+1 内核)上的并行计算。运行几次后,串行时间为 1.5 秒,并行时间为 1.0 秒,但并行和串行在 1.3 秒时非常接近。

正方形是700x700像素,我用的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 启动多个内核来完成任务。

根据与 Google 的快速对话,可能是内核处于休眠状态,等待计算真正长时间运行(几秒),然后内核才打开……这是真的吗?如果是这样,是否有来自 Java(无 JNI)的 API 调用可以先发制人地唤醒内核?

最佳答案

这听起来像是 RenderScript 的候选者.简而言之,它允许您执行计算量大的操作,利用所有可用的加速资源(多核、GPU 计算、dsp 等)。来自文档:

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 代码,但您不必将其分解成多个部分,因为并行化将为您处理。

如所述,从 Android 代码使用 RenderScript 非常简单 here .

关于android - 多核安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15873768/

相关文章:

java - 应用程序退出时 MediaPlayer 不会停止

java - Erlang 比单线程 Java 快之前需要多少个 CPU

android - 如何在 Activity 中成功地将内容显示为来自 RunningFragment 类的 Fragment?

Android:在 SurfaceView 和 OpenGL 之间做出选择(GLSurfaceView)

android - Android Studio 3.3 中没有消息 View

Android NDK 使用多核 cpu

cpu-architecture - 两个进程可以在一个 CPU 内核上同时运行吗?

android - 我的自定义适配器 (android) 怎么了?

java - 多线程 Java 应用程序中的性能

linux - 2个线程可以并发运行吗?或者只有 1 个? (考虑到超线程的可能性)