Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this problem, only complete part 2. I have already submitted part 1 in a pre

ID: 3672689 • Letter: F

Question

For this problem, only complete part 2. I have already submitted part 1 in a previous question.

Multi-threading:

1. Write a program (using Java) to write data to the disk.

a. Generate an array of random byte values (0-255) resulting in data set 1 megabyte in size.

b. Write the array to the disk using the file write system call.

c. Measure the elapsed time to complete the process.

2. Re-architect the program (in Java) to use multi-threading. Allow the user to specify the number of threads to execute at the command prompt.

a. Use the threads to parallelize the generation of the array and the writing of the data to the disk. Each thread should merge its dataset with the existing dataset in the file so that the final dataset is 1 MB in size on the disk.

b. Execute the program using 1, 10, 100, 250 and 1000 threads. Measure the process completion time for each execution.

c. Generate a chart (in Excel or a similar program) that shows the benefit of multi-threading the process. Which thread count results in the best efficiency in this application?

Explanation / Answer

1. save matrix to a array

save matrix to disk

I have the following 10000000x2 matrix:

Now I want to save this matrix to int[][] array:

The output:

Now I want to save this matrix to disk:

I have the following 10000000x2 matrix:

  0        0  1        1  2        2  ..       ..  10000000 10000000  

Now I want to save this matrix to int[][] array:

  import com.google.common.base.Stopwatch;    static void memory(int size) throws Exception {      System.out.println("Memory");        Stopwatch s = Stopwatch.createStarted();        int[][] l = new int[size][2];      for (int i = 0; i < size; i++) {          l[i][0] = i;          l[i][1] = i;      }        System.out.println("Keeping " + size + " rows in-memory: " + s.stop());  }    public static void main(String[] args) throws Exception {      int size = 10000000;      memory(size);      memory(size);      memory(size);      memory(size);      memory(size);  }  

The output:

  Keeping 10000000 rows in-memory: 2,945 s  Keeping 10000000 rows in-memory: 408,1 ms  Keeping 10000000 rows in-memory: 761,5 ms  Keeping 10000000 rows in-memory: 543,7 ms  Keeping 10000000 rows in-memory: 408,2 ms  

Now I want to save this matrix to disk:

  import com.google.common.base.Stopwatch;  import java.io.BufferedOutputStream;  import java.io.FileOutputStream;    static void file(int size, int fileIndex) throws Exception {      Stopwatch s = Stopwatch.createStarted();        FileOutputStream outputStream = new FileOutputStream("D:\file" + fileIndex);      BufferedOutputStream buf = new BufferedOutputStream(outputStream);      for (int i = 0; i < size; i++) {          buf.write(bytes(i));          buf.write(bytes(i));      }        buf.close();      outputStream.close();        System.out.println("Writing " + size + " rows: " + s.stop());  }    public static void main(String[] args) throws Exception {      int size = 10000000;      file(size, 1);      file(size, 2);      file(size, 3);      file(size, 4);      file(size, 5);  }  
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote