36

Does single thread application use all the 4 core in a Quad-core phone. I searched this a lot and found some articles that says yes and some saying no. some articles even say the android OS doesn't utilize the 4 core.

Is android capable of using all 4 cores in an Quad core processor?

Does single thread application utilize multi core?

Prags
  • 2,457
  • 2
  • 21
  • 38
null pointer
  • 5,874
  • 4
  • 36
  • 66
  • 24
    bill gates asked a question and steve jobs edited this :) Sir Dennis Ritchie will answer this :) – Iftikar Urrhman Khan May 15 '13 at 10:24
  • 1
    I cant see Linus Torvald nearby. – N-JOY May 28 '13 at 12:14
  • 1
    While not necessarily relevant, the question is somewhat mistaken: all Android apps necessarily have multiple threads. Even in the trivial case where a novice developer may do something with no awareness of threading, there are still a number of threads created in the act of setting up an application process, and they do end up utilized. – Chris Stratton May 28 '13 at 15:43
  • 2
    Trivial programs to evaluate it are at http://bigflake.com/MultiCore.java.txt and http://bigflake.com/cpu-spinner.c.txt . There are various scenarios where the kernel will schedule all threads of a given app on a single core, but these programs show that if you try hard enough you can get all cores running. – fadden Jun 14 '13 at 17:08
  • 1
    I put MultiCore.java.txt inside a trivial app, ran it under systrace, and posted the results on http://bigflake.com/systrace/ . You can clearly see the point where the Nexus 4 shifts the work to the 3rd and 4th cores. You can also see that there's a lot going on in the system other than the app, so even a "single-threaded" app can benefit from a multi-core device. – fadden Jul 31 '13 at 22:08
  • I would not like to repeat someones other answer, but I agree with answers and discussion on this thread [Similar question](http://stackoverflow.com/questions/15936203/single-thread-program-to-make-use-of-multiple-cores) There is no valid reason why OS should not utilize all cores Hope this helps and enjoy your work. – Marko Lazić May 15 '13 at 10:26

2 Answers2

22

The answer is YES.

Android is basically built upon Linux kernel which does utilize mulit-core. As far as single-threaded-application is concerned, remember that a thread can not be executed in-parts on different cores simultaneously. So although your single-thread can be executed by different cores at different point in times, it can not be sub-divided and executed by different cores at the same time.

Having said that, please be aware that chipset manufacturers like Qualcomm are developing intelligent processors capable of sub-dividing your single-threaded app code (if and only if there are mutually exclusive parts) into multiple threads and have it run on different cores. Here again, the basic principle remains same - in order to utilize multi-core, the single thread was sub-divided into multiple threads.

To get the most out of your multi-core chip, you would rather create a multi-threaded app, with maximum possible asynchronous threads, so as to have optimum utilization of maximum number of cores. Hope this clears.

EDIT:

This also translates to - An app that does not make use of multiple asynchronous threads (or any other parallelism construct) will NOT use more than one core.

Gagan
  • 1,497
  • 1
  • 12
  • 27
  • 1
    You didn't answer the question. An app that does not make use of multiple threads (or any other construct that allows parallelism) will NOT use more than one core. – Wes Sep 12 '13 at 18:58
  • Hi Wes, I believe I did bring that point forth in last para of my answer. If only it needed para-phrasing, I've done that now. Thanks! – Gagan Sep 16 '13 at 06:45
  • -1 You're wrong. Single threaded workloads do not utilize more than one core. The web browsers are in this category, that means one core per tab, max. The answer is NO. – Rok Kralj Mar 22 '15 at 16:46
  • Hi Rok, the web browsers use separate process (not core per se) per tab. What I intended to say in para-2 is: If your single threaded application code has parts that are mutually exclusive then the new intelligent processors are capable of sub-dividing this otherwise single-threaded-code into multiple-(native)-threads and then run them on multiple cores. If only it needed para-phrasing, I've done that now. Thanks! More on parallelism here: https://developer.qualcomm.com/blog/multi-threading-android-apps-multi-core-processors-part-1-2 and https://msdn.microsoft.com/en-us/magazine/cc163340.aspx – Gagan Mar 23 '15 at 05:31
7

Yes. Android 3.0 is the first version of the platform designed to run on either single or multicore processor architectures.

Even a single-threaded application can benefit from parallel processing on different cores.

For example, if your application uses a media server, then the media processing and your UI rendering application logic can run on different cores at the same time. Also, the garbage collector can run on a different core.

Say your using graphics. To render the same your app can use multi cores. You can check the same at the link below.

https://youtu.be/vQZFaec9NpA?t=459 (Graphics and performance)

http://android-developers.blogspot.in/2010/07/multithreading-for-performance.html

Check this pdf. Scroll down to slide 22. Might be useful

http://elinux.org/images/1/11/Application-Parallelization-Android-KlaasVanGend.pdf

Prags
  • 2,457
  • 2
  • 21
  • 38
Raghunandan
  • 132,755
  • 26
  • 225
  • 256