Objective
To take advantage of several processors you have to divide the work into independent chunks, process them separately and combine the results (map-reduce). Real threads cannot be created in the browser, so the program simulates the situation in a deterministic way.
Instructions
- Read the number of workers
kand a line with a list of integers. - Split the list into
kconsecutive chunks as equal as possible: withnelements, each chunk hasn // kand the firstn % kchunks get one more. - Each worker computes the sum of the squares of its chunk. Show
Worker i: [chunk] -> sum(the chunk is shown as a Python list; it may be empty). - At the end show
Total: t, the sum of the results of all the workers.
3
1 2 3 4 5 6 7
Worker 1: [1, 2, 3] -> 14
Worker 2: [4, 5] -> 41
Worker 3: [6, 7] -> 85
Total: 140
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise