Question: Complete the findMin method in the ParallelHW1 class. I think the SampleThread class is correct. If it's not please let me know public class Parallel

Complete the findMin method in the ParallelHW1 class. I think the SampleThread class is correct. If it's not please let me know

public class Parallel {

public static final int NUM_THREADS = 4;

public static final int SIZE1 = 12;

public static final int SIZE2 = 15;

public static void main(String[] args) {

int[] array1 = { 10, 20, 30, 40, 50, 0, 70, 80, 90, 100, 110, 120 };

//int[] array2 = { 10, 20, 30, 40, 50, 60, 70, 80, 90, -10, 110, 120, 0, -20, -5 };

System.out.println("The smallest number is: " + findMin(array1, SIZE1));

System.out.println("The smallest number is: " + findMin(array2, SIZE2))

}

/**

* Creates multiple threads to find the smallest value in an array

* @param array1 array of values to be processed

* @param length number of array elements

*/

public static int findMin(int[] array1, int length) {

}

}

//

// Sample Thread subclass to implement scalar

// multiplication of an array

//

--------------------------------------------------------------------------------------------------------------------------------------------------------------

public class SampleThread extends java.lang.Thread {

int lo; // will control array access

int hi; // will control array access

int smallest; // smallest element

int[] array;

//

// Constructor to initialize low and high indices to be

// manipulated by this thread, as well as array and factor

// to be multiplied.

//

public SampleThread(int[] a, int l, int h) {

array = a;

lo = l;

hi = h;

smallest = array[0];

}

//

// Finds the smallest value in an array

//

public void run() // override must have this type

{

for (int i = lo; i

if(array[i]

smallest = array[i];

}

}

System.out.println("From " + lo + " to " + hi + " the smallest value is " + smallest);

}

}

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 Programming Questions!