Question
/* * Multi-Threading application * */ package multithreading; import java.util.Random; public class MultiThreading extends Thread { private int id; // thread number private static float[]
/*
* Multi-Threading application
*
*/
package multithreading;
import java.util.Random;
public class MultiThreading extends Thread
{
private int id; // thread number
private static float[] shareddata; // shared data array
public MultiThreading(int i)
{
id = i;
}
/* run method of the thread */
public void run()
{
int a;
Random generator = new Random();
System.out.println("Thread " + id + " running");
long t = System.currentTimeMillis()/1000;
for (a=0; a
System.out.println("Thread " + id + " took " + (System.currentTimeMillis()/1000 - t) + " seconds");
}
public static void main(String[] args)
{
final int N = 1; // number of threads
shareddata = new float[100000000];
System.out.println("Starting Multi-threading...");
MultiThreading[] thread = new MultiThreading[N];
for (int i = 0; i
{
/* initialise each thread */
thread[i] = new MultiThreading(i+1);
/* start each thread */
thread[i].start();
}
}
}
Part C- Multi-threading Currently the application is performing the same calculations for all threads. The aim of multi- threading is to share and distribute the processing over several CPU cores in order to reduce the overall processing time Task C1: Data capture (10 marks) Modify the MultiThreading.java application so that the processing of the 100 million calculations is divided up between two and then four threads equally. Make use of the thread id member variable to distinguish between threads in the run method Take measurements (max time to completion for all threads) and populate the table below whern the processing is divided between 1,2, and 4 threads. Take the max time to completion for each of those configurations and add them to the table below Proposed table layout Threads Time to complete (sec) 1 2 4 Copy the data into an Excel spreadsheet and plot a line graph. Copy the table and the line graph into your answer sheet. Task C2: Analysis (10 marks) Comment on the efficiency of the application's ability to process the data in parallel. Substantiate your answer by referring to the graph you plotted for task Cl and by performing some additional calculations such as for the speedup when using 2 and 4 threads. Provide an explanation for your observations. What are the potential limitations for parallel processing? Discuss Amdahl's Law in this contextStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started