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.
-
2Since you are running in VM, there is no concept of core affinity. TO do so, you would have to go native and use the NDK. – Simon Jan 08 '15 at 19:32
-
Where did you get the assumption he's running on a VM? – Dave S Jan 08 '15 at 19:37
-
@DaveS He explicitly stated "application". If you are aware of a way to run an app outside of a VM on Android, I'd be delighted to hear about it. – Simon Jan 08 '15 at 19:41
-
Sure they run on the JVM but that doesn't prevent you from taking advantage of multiple cores, you just can't explicitly specify which core to run on. http://stackoverflow.com/questions/14918624/how-can-i-make-sure-my-threads-processes-are-running-on-different-cores?rq=1 – Dave S Jan 08 '15 at 19:45
-
@DaveS I didn't say you can't take advantage of multiple cores. I said that "there is no concept of core affinity". Because of this, you cannot control the sequencing and slicing of threads. The OP explicitly states that they want to avoid sequential execution. Without control over affinity, there is no way to guarantee this. To get control requires custom code. – Simon Jan 08 '15 at 19:49
-
Fair enough when I asked the question I was thinking of an explicit VM that would be outside the normal app development process not JVM. – Dave S Jan 08 '15 at 19:51
-
I am using native code, but this native code is called from a thread. I create e.g thread 2 for task 2 and I use many jni calls inside the tread. Please could you elaborate on how to use the NDK to choose cores ? (I am assuming you run a specific c++ function from the JNI part on the core of your choice) – huehuehuehue Jan 08 '15 at 21:09
3 Answers
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.

- 3,378
- 1
- 20
- 34
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

- 5,308
- 3
- 32
- 61
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?

- 1
- 1