/** ![A $4^2$ Morton curve. Basilisk employs a diagnoally mirrored version, i.e. (capital) N-order curve to be precise. Image courtesy of [Asger Hoedt](http://asgerhoedt.dk/?p=276)](http://asgerhoedt.dk/wp-content/uploads/2012/10/MortonCurve-4x4.png) # Prime numbers along a Z-order space-filling curve [Stanislaw Ulam](https://en.wikipedia.org/wiki/Stanislaw_Ulam) once dicided that is was a good idea to order the prime numbers (primes) along a spiralling space-filling curve. Doing so, he discovered what is now known as the [*Ulam's spiral*](https://www.youtube.com/watch?v=iFuR97YcSLM). It is attractive to use the Basilisk toolbox to study the behaviour of primes along a Z-order space-filling curve. If you are curious what role this curve plays within Baslisk, have a look [here](The_Tree_Grid_Structure_in_Basilsik#indexing-and-mpi-load-balancing). */ #include "grid/quadtree.h" //<- For it's 2D Z-order indexing iterator #include "utils.h" //<- For visualization purposes #include "tag.h" //<- For finding connected regions. int i=9; /** ## Find primes We need to find all primes upto *n* and store them in an array *b* of length *n*. This is done by using [Eratosthenes' sieve](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes), an ancient algorithm that was not developed with computational efficientcy nor paralellization in mind. */ void getprimes(int b[],int n){ b[0]=0; //zero is not a prime b[1]=0; //one is not a prime for (int j=2;j g.gif ", "w"); /** Loop over increasingly larger grids */ for (int maxlevel=1;maxlevel<=i;maxlevel++){ init_grid(1<0) regsize[(int)field[]]++; } sprintf(name,"prime%d.dat",maxlevel); FILE * fp = fopen (name, "w"); for (m=1;m