Multithreaded Merge Sort
Merge-Sort : The Serial Version
We have
Merge − Sort (A, p, r)
Observation: Sort elements in A [p...r]
1. if (p < r) then
2. q = (p+r)/2
3. Merge − Sort (A, p, q)
4. Merge − Sort (A, q + 1, r)
5. Merge (A, p, q, r)
Merge-Sort : The Parallel Version
We have
Merge − Sort (A, p, r)
Observation: Sort elements in A [p...r]
1. if (p < r) then
2. q = (p+r)/2
3. spawn Merge − Sort (A, p, q)
4. Merge − Sort (A, q + 1, r) // Not necessary to spawn this
5. sync
6. Merge (A, p, q, r)
We have
Merge − Sort (A, p, r)
Observation: Sort elements in A [p...r]
1. if (p < r) then
2. q = (p+r)/2
3. Merge − Sort (A, p, q)
4. Merge − Sort (A, q + 1, r)
5. Merge (A, p, q, r)
Merge-Sort : The Parallel Version
We have
Merge − Sort (A, p, r)
Observation: Sort elements in A [p...r]
1. if (p < r) then
2. q = (p+r)/2
3. spawn Merge − Sort (A, p, q)
4. Merge − Sort (A, q + 1, r) // Not necessary to spawn this
5. sync
6. Merge (A, p, q, r)
Comments
Post a Comment