Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall in the class, we used two threads to compute the sum of an array to help the efficiency. In this homework, create an array

image text in transcribedRecall in the class, we used two threads to compute the sum of an array to help the efficiency. In this homework, create an array of 250,000,000 random elements, use different numbers of threads to compute the sum and compare the run times. The number of threads changes from 1 to 100. You can only try the numbers that are factors of 250,000,000 so each thread will compute the same portion of the array. This should be done using a loop. There is a global variable sum" that can be accessed by all the threads. Each of the threads will add their result to sum". You need to make sure there is no data race so it will output the correct sum. Please submit your solution on blackboard in the form of a single java file. The following picture displays part of my running result.

1. Recall in the class, we used two threads to compute the sum of an array to help the efficiency. In this homework, create an array of 250,000,000 random elements, use different numbers of threads to compute the sum and compare the run times. The number of threads changes from 1 to 100. You can only try the numbers that are factors of 250,000,000 so each thread will compute the same portion of the array. This should be done using a loop. There is a global variable "sum" that can be accessed by all the threads. Each of the threads will add their result to "sum". You need to make sure there is no data race so it will output the correct sum. Please submit your solution on blackboard in the form of a single java file. The following picture displays part of my running result. Run: Parallelism x /Library/Java/JavavirtualMachines/jdk1.8.8_201.jdk/Contents/Home/bin/java ... Using 1 threads The sum was -9341151621500 The computation took 107 milliseconds Using 2 threads The sum was -9341151621500 The computation took 54 milliseconds Using 4 threads The sum was -9341151621500 The computation took 45 milliseconds Using 5 threads The sum was -9341151621500 The computation took 47 milliseconds Using 8 threads The sum was -9341151621500 The computation took 44 milliseconds Using 10 threads The sum was -9341151621500 The computation took 45 milliseconds Using 16 threads The sum was -924115162.500

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago