Commit d800566d authored by yazan.halloul's avatar yazan.halloul

Sequential Counter commit

parent 3f36db7f
import static org.junit.jupiter.api.Assertions.assertEquals;
import data.RangeArrayBuilder;
import parallelCounters.*;
//import parallelsummers.ParallelSummer2;
/**
* This projects is indented to show different ways of parallel programming in java
* in terms of
* # designing workers
* # executing them
* # getting and combining the results
*
* @author Ahmet Cengizhan Dirican
*/
public class Main {
public static void main(String[] args) {
int start = 0;
int finish = 10;
int[] data = RangeArrayBuilder.create(start, finish);
for (int d:data
) {
System.out.print(d+" ");
}
long result = SequentialCounter.findPrimeNumbers(data);
int threadCount = 8;
System.out.println("\nSequential Prime Number Counter: " + result);
System.out.println("Parallel Prime Number Counter 0: " + ParallelCounter0.findPrimeNumbers(data, 8));
System.out.println("Parallel Prime Number Counter 1: " + ParallelCounter1.findPrimeNumbers(data, 8));
System.out.println("Parallel Prime Number Counter 2: " + ParallelCounter2.findPrimeNumbers(data, 8));
System.out.println("Parallel Prime Number Counter 3: " + ParallelCounter3.findPrimeNumbers(data, 8));
System.out.println("Parallel Prime Number Counter 4: " + ParallelCounter4.findPrimeNumbers(data, 8));
}
}
import primeChecker.PrimeChecker;
/**
* This class provides a method to sequentially calculate the sum of an array.
*
* @author Ahmet Cengizhan Dirican
*/
public class SequentialCounter {
/**
* Returns the sum of all the element of a given array.
* @param data the integer array
* @return the sum
*/
static PrimeChecker primeChecker = new PrimeChecker();
public static long findPrimeNumbers(int[] data) {
long numberOfPrimeNumbers = 0;
for (int i = 0; i < data.length; i++) {
if(primeChecker.isPrime(data[i]))
numberOfPrimeNumbers += 1;
}
return numberOfPrimeNumbers;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment