Question: Multi-threading and multi-core CPU scheduling Code: /* * Multi-Threading application * */ package multithreading; import java.util.Random; public class MultiThreading extends Thread { private int id;

Multi-threading and multi-core CPU scheduling

Multi-threading and multi-core CPU scheduling Code: /* * Multi-Threading application * */

package multithreading; import java.util.Random; public class MultiThreading extends Thread { private int

Code:

/* * 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

}

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 Describe the modifications necessary for the MultiThreading.java application so that the processing of the 100 million calculations are divided threads. Hint: Make use of the thread id member variable to distinguish between threads in the run method. Describe how the data array is shared between threads. up equally between two and then four Task B2: Theoretical speedup - (5 marks) The theoretical speed-up of an algorithm on a parallel computing platform is given by Amdahl's law, originally formulated by Gene Amdahl in the 1960s. speedup - P percentage of parallel code N number of processor cores Calculate the theoretical speedup for 2 and 4 CPU core systems, assuming that 95% of the code could be parallelised Task B3: Actual measurements (10 marks) Run the application and take measurements (max time to completion for all threads when the processing is divided between 1,2 and 4 threads. Take the max time to completion for each of those three configurations and populate the table below. Each of the modifications requires a change of the source code. Make sure the system does not run in power saving mode which would adversely affect the measurements. C15220 Operating Systems Assignment 3/4 Proposed table layout: Threads Time to complete (sec 2 Copy the data into an Excel spreadsheet and plot a line graph. Copy the table and the line graph into your answer sheet. Task B4: Analysis -(10 marks) Comment on the efficiency of the application's ability to process the data in parallel. Calculate the speedups from your measurements from task B3 for two and four threads compared to one thread. Compare and discuss the theoretical values from task B2 to the measured values from task B3. Provide an explanation for your observations. What are the potential limitations for parallel processing? Discuss Amdahl's Law in this context and refer to the source code as well. Describe the modifications necessary for the MultiThreading.java application so that the processing of the 100 million calculations are divided threads. Hint: Make use of the thread id member variable to distinguish between threads in the run method. Describe how the data array is shared between threads. up equally between two and then four Task B2: Theoretical speedup - (5 marks) The theoretical speed-up of an algorithm on a parallel computing platform is given by Amdahl's law, originally formulated by Gene Amdahl in the 1960s. speedup - P percentage of parallel code N number of processor cores Calculate the theoretical speedup for 2 and 4 CPU core systems, assuming that 95% of the code could be parallelised Task B3: Actual measurements (10 marks) Run the application and take measurements (max time to completion for all threads when the processing is divided between 1,2 and 4 threads. Take the max time to completion for each of those three configurations and populate the table below. Each of the modifications requires a change of the source code. Make sure the system does not run in power saving mode which would adversely affect the measurements. C15220 Operating Systems Assignment 3/4 Proposed table layout: Threads Time to complete (sec 2 Copy the data into an Excel spreadsheet and plot a line graph. Copy the table and the line graph into your answer sheet. Task B4: Analysis -(10 marks) Comment on the efficiency of the application's ability to process the data in parallel. Calculate the speedups from your measurements from task B3 for two and four threads compared to one thread. Compare and discuss the theoretical values from task B2 to the measured values from task B3. Provide an explanation for your observations. What are the potential limitations for parallel processing? Discuss Amdahl's Law in this context and refer to the source code as well

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!