Question
Fill in the rest of this Java Code Concurrency is becoming a very important programming concept due to the explosion of multi-threaded, multi-core processors. You
Fill in the rest of this Java Code
Concurrency is becoming a very important programming concept due to the explosion of multi-threaded, multi-core processors. You are to write a simple concurrent program in JAVA. You will create a square two dimensional matrix and calculate some basic statistics while measuring the time. The specifications are as follows:
here is some starter code for you fill in:
--------------------------------------------------------------------- // This is a very small set up to get people started on using threads // We need static variable pointers in the main class so that // we can share these values with the threads. // the threads are address separate from us, so we need to share // pointers to the objects that we are sharing and updating import java.util.ArrayList; public class MythreadTest { private static ArrayList
System.out.println("Main thread exiting "); } catch (Exception e) { System.out.println(e.getMessage()); } } } // each thread should access its row based on "ind" // and leave results I would suggest in a static array that you need // to create in MythreadTest class ThreadTest implements Runnable { private int i; ThreadTest(int ind) { i = ind; } public void run() { try { MythreadTest.N += i ; // this is a global variable in MythreadTest we add stuff together; System.out.println("Thread is started " + i + "Array is " + MythreadTest.A[1][3]); Thread.sleep(1000); System.out.println("Thread is exiting " + i); } catch (Exception e) { System.out.println(e.getMessage()); } } }
---------------------------------------
The program takes1 input from the user (or on command line) 1) the dimension of the matrix- N
Your program will do the following 1) Create an NxN two dimension INTEGER matrix 2) randomly assign INTEGER values to each element in the range of between 2^(32-N) and 2^(31-N). The best way to do this is to do the following (assuming random() is in the range [0,1). ) trunc( (2^(32-N) - (2^31-N))* Random() + 2^(31-N))
This is basically : range * Random() + start_value
START TIMER NOW 3) You will create N threads, each thread is responsible for one row of the matrix 4) each thread will calculate the max, min and what it needs to report for summation/average 5) You should add a common set of arrays in the main object class to allow each thread to copy values back to the main thread. 6) Your main thread will wait on all of the children threads, and then calculate the overall max, Min and average
STOP TIMER
You will need to calculate and report the following from the matrix a) The maximum value b) The minimum value c) The average of all of the values in the matrix d) the time it took to do parts a-c
You may ONLY use INT and FLOAT for your calculation of MAX, SUM and average You MAY ONLY use DOUBLE/LONG for time values. If you use larger primitives to solve sum and average you will see 50% off for any use of these primitive data types.
Ensure your results look valid. In particular the average.
Your runtime needs to report average time run, and standard deviation.
Step 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