My First Experiment with Parallel Processing

wonder

Expert
Licensed User
Longtime User
Context:
- My LibGDX based game engine "KZ2D".
- Hardware: PC MEmu 8-Core simulated tablet.

What was threaded:
- I paralleled the processing of two independent cycles of my game logic: Objects (coins, rockets, chests, etc) and AI Agents (enemy characters).

Variations:
- A: [Serial] default game cycle (first objects, then AI agents)
- B: [Parallel] LibGDX CallAsync
- C: [Parallel] ProBundle CallSubExtended
*All of the above were called from the LG_Render event.

Results:
- A: ~0.30 milliseconds total cycle time
- B: ~0.75 milliseconds total cycle time
- C: ~1.10 milliseconds total cycle time (with errors but no crashes)

Safety:
- LibGDX CallAsync was properly initialized and disposed outside the render event
- Do While TaskA.IsRunning OR TaskB.IsRunning : Loop
- Do Until TaskA.IsDone AND TaskB.IsDone : Loop

Conclusion:
- Serialized (single threaded) seems to be the fastest solution so far, but once I'm able to test on real hardware I'll come back with more results... Nonetheless, it doesn't make sense. Shouldn't parallel processing be faster?
 

ilan

Expert
Licensed User
Longtime User
- Serialized (single threaded) seems to be the fastest solution so far, but once I'm able to test on real hardware I'll come back with more results... Nonetheless, it doesn't make sense. Shouldn't parallel processing be faster?

logical the C option should be faster since it splits the whole process in 2 different threads.

but what could be is (i dont know i am not a pc profi) that a phone has for example 8 processors (let say galaxy 4)
4x1.6 GHz Cortex-A15 & 4x1.2 GHz Cortex-A7

so when u have a heavy task the phone is configured like this to use the faster processors for that task what will leave slower processor for other task
so if you use option A the phone automatically choose the faster processors for that task but on option C it use for the first half the faster processors and for the second the slower ones and maybe thatswhy the big differences

try to check for each task the time (on option C) and switch the subs you call and see if the time is different on each process.
 

sorex

Expert
Licensed User
Longtime User
maybe the new threads stick to the same processor as the main thread causing speed being divided by the threads?
 

JordiCP

Expert
Licensed User
Longtime User
Since you work on the wild NDK side, perhaps you can try openmp ;). I started to look at it once but couldn't figure the correct setup
 

ilan

Expert
Licensed User
Longtime User
i would like to ask you a question @wonder how do you calculate the time? the smallest unit i know is 1ms (when i use datetime.now the smallest unit i get is 1ms)
do you try the same task multiple times and divide 1ms by the times that task could perform and like this know how much 1 task take? :confused:
 
Top