BAGZZlash
RBE Author
- Joined
- Mar 9, 2008
- Messages
- 587 (0.09/day)
Today I accidentally stumbled over the "Eight queens puzzle". It's a game of placing n chess queens on an n×n chessboard so that no two queens threaten each other. Computationally, the challenge is to find the total number of solutions to that problem for differently sized (n) chessboards. The larger the board, the more solutions and the longer the computation time, of course. For n = 18, the number of solutions is 666,090,624. Solutions are known for n's of up to 26. For n >= 27, the number of solutions is yet unknown.
Back in 2011, takaken wrote a neat algorithm to compute the number of solutions based on multithreaded C code. I figured to turn this into a multithreaded CPU benchmark. The code computes the number of solutions for n = 18. This is because for n = 17, computation would be too fast on modern CPUs and for n = 19, users would have to wait for too long for the result.
Please download the attached file to obtain the binary package, including the source code.
I compiled the code for Windows using GCC: gcc -fopenmp Q.c -o Q.exe.
Usage is simple: Type Q [number of threads to use]. For example, run Q 8 for eight threads. If no number, a non-valid number or a number greater that the maximum hardware capability is provided, the program sets the maximum possible number of threads.
Have fun!
Back in 2011, takaken wrote a neat algorithm to compute the number of solutions based on multithreaded C code. I figured to turn this into a multithreaded CPU benchmark. The code computes the number of solutions for n = 18. This is because for n = 17, computation would be too fast on modern CPUs and for n = 19, users would have to wait for too long for the result.
Please download the attached file to obtain the binary package, including the source code.
I compiled the code for Windows using GCC: gcc -fopenmp Q.c -o Q.exe.
Usage is simple: Type Q [number of threads to use]. For example, run Q 8 for eight threads. If no number, a non-valid number or a number greater that the maximum hardware capability is provided, the program sets the maximum possible number of threads.
Have fun!

Code:
Using 1 thread(s).
Elapsed time (hh:mm:ss:cs): 21.01
Using 2 thread(s).
Elapsed time (hh:mm:ss:cs): 15.55
Using 3 thread(s).
Elapsed time (hh:mm:ss:cs): 10.38
Using 4 thread(s).
Elapsed time (hh:mm:ss:cs): 9.53
Using 5 thread(s).
Elapsed time (hh:mm:ss:cs): 9.23
Using 6 thread(s).
Elapsed time (hh:mm:ss:cs): 8.59
Using 7 thread(s).
Elapsed time (hh:mm:ss:cs): 8.27
Using 8 thread(s).
Elapsed time (hh:mm:ss:cs): 7.69