Assignment - 3


This assignment tests your skills in CUDA C programming with two simple exercises. Download the CUDA C Toolkit from NVIDIA Website and use the nvcc compiler. Run your programs on a system with an NVIDIA GPU.
  1. Write a program to print all prime numbers upto the number input by the user. Your program should ask the user to input a number N. It should then check all numbers 2 ... N if it is a prime and then print it if it is. A number is prime if it is not divisible by any odd number in the range 3 ... sqrt(N).

    After writing the program, do the following experiments.

    1. Start with a single block and multiple threads. Find the time taken for the program as you vary the number of threads.
    2. Run the program with a single thread but vary the number of blocks. Again do a timing analysis.
    3. Vary both the number of blocks and threads. See if there is an optimal choice.
    In all the cases, plot the time taken against the parameter being varied.
  2. Write a program to test if a given number (N) is a prime. Use the same test for checking if a number is prime as that in Question 1 above. Do similar timing analysis experiments as in Question 1.

    If the problem proves a little tricky for parallel reduce implementation, try counting the number of factors of N. If the number of factors is 0, then N is a prime.