### Objective

To gain further experience writing CUDA programs.

For this lab, you will modify your CUDA program to calculate the Collatz conjecture such that it finds the natural number with the longest Collatz chain up to 10 million.

Recall that the Collatz conjecture says:

Take any natural number $n$. If $n$ is even, divide it by 2. If $n$ is odd, multiply it by 3 and add 1. If you repeat this process long enough, $n$ will eventually be equal to 1.

A CUDA program which simply uses 1 block to compute the Collatz length of the natural number $blockIdx.x + 1$ will only work when $n \leq 65,536$.

You should modify your program such that it can compute up to at least 10 million. There are at least three ways to do this:

• Using a two-dimensional block (not recommended).
• Having each block loop through more than one value in the array.
• Using multiple threads per block.

I recommend the last approach as it is simplest, and we have seen an example on doing just that.

When your program works it should output the following:

The longest collatz chain up to 10000000 is 8400511 with 685 steps.

Note that you must use unsigned longs, and not just ints, in order to get the correct answer.

### Submitting

Email me your CUDA program when it is working.