Member-only story
This Math Problem Is 3,000 Years Old — Magic Squares
Can My PC Solve It with C++, OpenMP, and CUDA?
If you’re not a Medium member, a video version is available on YouTube.
There is a math problem that is literally ancient, and it belongs to the realm of recreational mathematics. And while doing this, we can learn a lot of interesting things. In this article, I will write about the so-called magic squares, and we will try to find them using a modern computer and a CUDA GPU. As we will see, the problem is more challenging than we may think. It will also be a fun exercise if you want to learn a bit of C++, OpenMP, multithreading, and CUDA.
Let’s get started! As usual, if you want to see a coding process in action, a video version is added at the end of the article.
1. History
First, what is a magic square? Obviously, it is a square (surprise:) of size N, filled with unique numbers from 1 to N², where the sums of the horizontal, vertical, and diagonal lines are the same.
3x3 magic squares were independently discovered in ancient China, India, Japan, and other places…








