Question: Given below is a sequential program that calculates the frequency of even values in a large array. Your task is to develop a parallel solution

Given below is a sequential program that calculates the frequency of even values in a large array. Your task is to develop a parallel solution that distributes the workload over the number of processors on the machine executing your program (construct the Threaded class and the main method to test it).
public static void main(String[] args){ int f[]= new int[1000000];
for(int j =0; j < f.length;j++) f[j]=(int)(Math.random()*100000); int freq =0;
for(int j =0; j < f.length; j++)
if(f[j]%2==0) freq++; System.out.println(freq);
}
The number of processors is given by Runtime.getRuntime().availableProcessors())

Step by Step Solution

3.55 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is the parallel solution that distributes the workload over the number of processors available in the machine executing the program as per the in... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!