package be.ac.vub.ir.mpi; import be.ac.vub.ir.util.Chrono; import be.ac.vub.ir.util.GetOpt; /** * Parallel and sequential implementation of a prime number counter */ public class CountPrimes { // Default program parameters final static int DEFAULTSIZE = 50000; public static void main(String[] args){ // *** INITIALIZE *** GetOpt options = new GetOpt("n:",args); // allows you to parse program options. // ':' means that an argument is following after the option (here: -n 1000) String ns = options.getOptionParam('n'); int arraySize = (ns != null) ? Integer.parseInt(ns) : DEFAULTSIZE ; int[] data = createAndFillArray(arraySize); // *** SEQUENTIAL RUN (master only) *** Chrono seqChrono = new Chrono(); int nbrPrimesSeq = countPrimes(data); long seqtime = seqChrono.stop(); System.out.println("Sequential solution found "+nbrPrimesSeq+" primes among "+arraySize+" odd numbers in "+seqChrono); } // *** Array Filling *** static int[] createAndFillArray(int n){ // fills with all odd numbers int[] data = new int[n]; for (int i=0;i