News Course Articles

Assignment #1

 

Due Date: Next Friday 12noon.

 

Write a multi-thread program that generates prime numbers starting from 2. You need to submit 1) source code (60%), 2) executables (either Java class files or Window binaries) (20%), and 3) one pager to explain your algorithms and performance comparisons (20%).

 

A number is prime if it is divisible by 1 and the number itself and no other number. A prime number can be tested by a method called sieve as illustrated below:
 
long limit = (long)Math(2,20);
public static boolean isPrime (long num ) {
    boolean prime = true;
 
    for (long i = 2; i <= limit; i++ ) {
      if (num % i == 0 ) {
        prime = false;
        break;
      }
    }
    return prime;
}

 

Compare timing performance of the serial version, single threaded version and multi-threaded version. Please note that when you measure the performance of the code, you should not use the shell timing command such as time under UNIX or Linux. Instead, you should embed the timing statements in your code. In Java, you can do something like:

 

long ct1 = System.currentTimeMillis();

you code

long ct2 = System.currentTimeMillis();

System.out.println(the running time for your code is +(ct2-ct1));