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?
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.
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
Related
So I am developing an application, which has a 'strong' parallel structure, and since time is important for me, I thought about creating 4 threads for each 'subwork' (assuming running on 4 cores device). If the 4 subworks are executed sequentially it will be a great loss of potential.
The OS will handle which threads run on which cores. All you need to do is use AsyncTasks or threads to set it up for parallel processing and it will take advantage of it if it can. You can find a more information on the topic in this qualcomm blog post.
I do not believe that you have access to the individual cores - this is handled by the Android kernel. However, as long as you implement your 4 "threads" as Java Thread you should be fine, seeing as they can execute concurrently independant of your main Android Activity. You can find additional information on using a Thread in Android here: http://developer.android.com/reference/java/lang/Thread.html
You cannot control the kernel yourself (without root) i belive, but android should use all the threads itself, so you dont need to do anything at your end.
This might help, if you want to run many activityes at the same time - Can you have two activities running at the same time?
I'm running a multi-threaded C++ application (freesoft.org's tablebase generator 'hoffman') on a dual core ARM7 running Android 4.1.2 with a Linux 3.0.8 kernel. Compilation was with gcc 4.6.3 on Ubuntu 12.04 using linuxonandroid.
I've been experimenting with using pthread_setaffinity_np() to force the different threads onto different cores. I don't want to do this, but it seems like I must.
Over the course of an hour, playing with different combinations of things, I measured the following run times for a dual threaded benchmark:
with pthread_setaffinity_np(): 10.818, 10.803, 10.814, 11.077, 11.013, 10.952 seconds
without pthread_setaffinity_np(): 20.366, 19.263, 19.539, 16.764, 19.365, 19.661, 19.330 seconds
It seems that the non-standard GNU pthread_setaffinity_np() is absolutely required to get my C++11 program to actually put its threads onto different cores. 'top' confirms that one of my two cores is sitting idle otherwise.
Is this right? Can anybody offer a better solution?
This question already has answers here:
Stresstest Memory on Android
(2 answers)
Closed 3 years ago.
I've been reading up on the Android dalvik, and I was curious as to how one would go about stress testing the Dalvik to evaluate its stability. I understand the Dalvik is meant for memory an processor constrained devices. So would allocating a lot of memory/increasing frequency of some CPU cores and then launching multiple applications be a way to test the stability?
I also understand that each independent process gets itsown instance of the Dalvik. So another possibility to stress the Dalvik would be to launch multiple applications that share a single process and a single instance of the Dalvik and see how stable the Dalvik is.
I would like to to know if either of these are good ways to measure the stability of the Dalvik. If both of them are good ways, which one would be a better test?
Thanks!
It's difficult to stress every part of a VM all at once.
You can write memory stress tests that exercise the heap and the garbage collector, synchronization stress tests (like the JSR-166 java.util.concurrent test suite), CPU stress tests that do lots of integer and floating-point computations on different cores simultaneously. And so on.
The trick is to write a test that does what you think it does -- a surprising number of "multi-core" tests end up single-threaded because of unexpected dependencies -- and whose results can be evaluated for correctness. A test that successfully causes instability isn't useful unless that fact is communicated to the user in some way. Making the VM crash is a pretty good way. :-)
Running multiple apps and services in the same process is theoretically possible but rare in practice. I don't think you'd actually be able to stress the system out any better this way, since only one app is in the foreground at a time, and if you're making requests of a service one thread will wait for the response while the other runs. You're better off just have one app with multiple threads, so you can control exactly what each does and how they interact.
Before you can do any of this, you need to define the scope of "stability". Simply running many apps isn't going to turn up anything, since there are hundreds of millions of devices running billions of instances of Dalvik with essentially no failures due to the VM itself (but any number due to bugs in apps, the framework, 3rd-party libraries, etc). Dalvik hasn't changed much since Android 4.0 (Ice Cream Sandwich) shipped two years back.
Is there any way of creating a process or thread in a specific core in Android?
edited for more info: the idea is that having two cores, I would like to run 2 different processes or threads in 2 different cores. Specifically, what I want to do is use 100% of the CPU of the phone, no matter how many cores the phone has.
Is there any way of creating a process or thread in a specific core in Android?
No, sorry.
the idea is that having two cores, I would like to run 2 different processes or threads in 2 different cores.
That is for the OS to decide, not you.
Specifically, what I want to do is use 100% of the CPU of the phone, no matter how many cores the phone has.
No developer should have that as an objective, outside of benchmarking applications and the like.
The same code for Android (1Ghz Snapdragon) executes 2 time faster, than on my PC (in desktop application) with 3.3 Ghz Core 2 Duo (class from PC was copied to Android project). Tested with Win7 and Debian. Time mesured by System.currentTimeMillis() for only one (main) calculating method. Why it's happend and what can I do to fix it?
UPD1. First application running on real android device, second - in JRE
UPD2. In that part of applications, that I try to compare, used only simple math and operations with BigDecimal (multiply, sqrt, divide and so on). Idea - calculate pi by gauss-legendre algorithm
You're going to need to be more specific about what you're doing to monitor this. There are a large number of factors at play that could influence this. If you're running on the emulator, forget it -- it's incredibly slow, there's really no comparison there. However, I get the feeling you're talking about one application running in the JVM as a standard Java application and another application running on Dalvik, but there, you really can't compare either. Different frameworks have different libraries and different calls that are implemented in different ways. Not to mention Dalvik is optimized differently than the standard JVM and so on.
You'll need to give us more information in order for us to attempt to give you an explanation, but I suspect you're trying to compare two things that really can't be compared.
I think because the Android device has a different processor architecture than your PC, so the CPU on your PC needs to emulate the Android, so it would do much more processing.