” 写作Multi-threaded Map编程、Assignment 6: Multi-threaded Map Reduce in RustAssignment 6: Multi-threaded Map Reduce in RustDue Sunday by 11:59pmPoints 50Submitting a file uploadAvailable after May 23 at 8amStart AssignmentIntroductionIn this assignment, youll Write a program that will get you familiar with writing multi-threaded programs in Rust.Learning OutcomesWrite simple programs in Rust (Module 9, MLO 2)Compile, debug, manage and run Rust programs (Module 9, MLO 3)Explain the facility for threads provided by Rust (Module 10, MLO 2)Map ReduceAccording to the Wikipedia article on MapReduceMapReduce is a programming model and an associated implementation for processing and generating big data sets with aparallel, distributed algorithm on a cluster.A MapReduce program is composed of a map procedure, which performs filtering and sorting (such as sorting students by firstname into queues, one queue for each name), and a reduce method, which performs a summary operation (such as counting thenumber of students in each queue, yielding name frequencies).InstructionsFor this assignment, We are providing you with a single-threaded Rust programprocesses input numbers to produce a sum. The program contains extensive comments that explain the functionality and give directionson what parts of code you are allowed to change (look for comments starting with CHANGE CODE).Assignment 6: Multi-threaded Map Reduce in RustHere is a description of the program: currently the main() function does the followingGenerates data for the rest of the programCalls generate_data() to generates a vector of numbers that serves as input for the rest of the program.Partitions the dataCalls partition_data_in_two() which partitions the input numbers into two partitionsPerforms the map stepCalls map_data() for each of the two partitions, which returns the sum of all the numbers in that partition.Performs the reduce stepGathers the intermediate results produced by each call to map_data()Calls reduce_data() that sums up the intermediate results produced by the map step to produce the final sum of all the inputnumbers.You have to modify the Program to accomplish the following tasks:Modify the program to create 2 threads, each of which concurrently runs the map_data() function on one of the two partitionscreated by the program given to you.Add code for the function partition_data() to partition the data into equal-sized partitions based on the argument num_partitionsIn case num_elements is not a multiple of num_partitions, some partitions can have one more element than other partitionsAdd code to the function main() toPartition the data into equal-size partitionsCreate as many threads as the number of partitions and have each thread concurrently run the map_data() function to processone partition eachGather the intermediate results returned by each threadRun the reduce step to process the intermediate results and produce the final resultSee detailed comments in the provided program to see how you can go about making the required changes.Example UsageHere are some example executions of the program.An execution of the program with 5 partitions and 150 elements.Assignment 6: Multi-threaded Map Reduce in RustSince the number of elements is a Multiple of the number of partitions, it is required that each partition should have the samenumber of elements.However, there is no requirement about which element is put into which partition. Thus the intermediate sums in your solution can bedifferent from what is shown below../main 5 150Number of partitions = 2size of partition 0 = 75size of partition 1 = 75Intermediate sums = [2775, 8400]Sum = 11175Number of partitions = 5size of partition 0 = 30size of partition 1 = 30size of partition 2 = 30size of partition 3 = 30size of partition 4 = 30Intermediate sums = [435, 1335, 2235, 3135, 4035]Sum = 11175An execution of the program with 6 partitions and 150 elements../main 6 150Number of partitions = 2size of partition 0 = 75size of partition 1 = 75Intermediate sums = [2775, 8400]Sum = 11175Number of partitions = 6size of partition 0 = 25size of partition 1 = 25size of partition 2 = 25size of partition 3 = 25size of partition 4 = 25size of partition 5 = 25Intermediate sums = [300, 925, 1550, 2175, 2800, 3425]Sum = 11175An execution of the program with 5 partitions and 153 elements.In this example the number of elements is not a multiple of the number of partitions.Based on the requirement that some partitions can have one element more than other partitions, in this case 3 partitions must have31 elements and 2 partitions must have 30 elements.Assignment 6: Multi-threaded Map Reduce in RustIn the example shown below, the 3 partitions with 31 elements are at position 0, 1 and 2 in the vector of partitions, and the 2partitions with 30 Elements are at position 3 and 4 in that vector. However, there is no requirement about the order in which partitionsthat have one more element than other partitions appear in the vector of partitions. Thus, the order of the partitions in your solutioncan be different from what is shown below../main 5 153Number of partitions = 2size of partition 0 = 76size of partition 1 = 77Intermediate sums = [2850, 8778]Sum = 11628Number of partitions = 5size of partition 0 = 31size of partition 1 = 31size of partition 2 = 31size of partition 3 = 30size of partition 4 = 30Intermediate sums = [585, 1486, 2387, 3135, 4035]Sum = 11628HintsThe function thread::spawn()returns JoinHandleT where T is the type of thereturn value of the function the thread runs. This means thatBecause map_data() returns an integer of type usizeIf you spawn a thread that runs map_data()thread::spawn() will return a value of type JoinHandleusizeWhat to turn in?Required: Upload one file main.rs with all of your code.When you resubmit a file in Canvas, Canvas can attach a suffix to the file, e.g., the file name may become main-1.rs . Dontworry about this name change as no points will be deducted because of this.Optional: If you have any meta-comments about the program, create a file README.txt with these comments, and upload it withyour submission as a separate file (i.e., dont zip up the two files together).Grading CriteriaAssignment 6: Multi-threaded Map Reduce in Rust5/5Total Points: 50Assignment 6 RustCriteriaRatingsThis assignment is Worth 8% of your final grade. The breakup of points is given in the grading rubric.The grading will be done on os1.To test your program, we will compile the code as followsrustc main.rsWe will run the program as follows./main num_partitions num_elementsE.g.,./main 5 150This criterion is linked to a Learning OutcomeProcesses the two partitions in the provided program by creating two threadseach of which concurrently runs map_data() on one partition each.partition_data() partitions the data into Num_partitions and the sizes of the partitions are correct.Implements map-reduce using as many Concurrent threads as the number of partitions in the argument.请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。