Seven Planets Riddle: Another followup. JIT and multiprocessing!
In the previous article we have managed to boost our program using JIT, reducing execution time approximately by a factor of 50-60, utilizing only one process. But hey, I have a Core i7! Can we utilize its whole potential?
The refactored program
I had to change our previous program quite significantly. Now it looks a bit less readable, more C-like. That was required for JIT, or else it caused significant slowdowns. Here’s the full program.
The smuggler’s routes generator remained the same, we’ll use its result throughout the program. It is rather small, only 6144 entries.
As for police routes, I implemented their generation right into the loop of a child process; it is no longer a separate generator.
Since a police route is a list of 11 numbers from 0 to 6, it can be treated as a base 7 11-digit number. We can make it an int instead to make things easier for the computer.
I ran this program in 8 processes, and it took just over 3 minutes. And a bit less in 16 processes; probably because some processes finish execution faster and let the others occupy the whole available virtual core afterwards.
I haven’t managed to make it run on GPU so far, but this program work extremely fast nonetheless. Optimizing for GPU may make it even less readable, so I’ll suspend this idea for now; maybe I’ll try to do it with a different task.