I’m writing a program in C that uses threads to add up numbers from a partitioned array that uses some obscure command line arguments to determine how many partitions should be used.
This is a copy of the part I’m struggling with from my brief:
Divide the array into 2**n partitions (n is another command-line argument) and create
one thread to do simple sum of all values stored in one partition of the array. Each
thread can calculate which locations of the array it should search given the thread index
(0,1, … 2**n-1). For example, if n=1 and the array is size 512, then thread 0 should sum
array locations [0,255] and thread 1 should search array locations [256-511]. Each
thread should store the partial sum it produces in a global array. Note that since the
threads do not share any data, they do not need to be synchronized, however you do need
to wait until the last thread completes processing before continuing on to the next
stage.
I’ve absolutely no idea how to partition the array and why threads are even necessary for this task but seeing as it’s part of my requirements I will have to use them. If someone could help explain a little clearer and the manor in which I’d go about the partitioning and the reason for threads, I’d be most grateful. I’ve already created the array and filled it with random numbers.
Your class might be parallel processing, and this assignment lets you do parallel addition on a given array with 2^n threads.