There are numerous online sources detailing its use
// merge sort of N elements
// DIVIDE SECTION
// create 4 threads
parallel for d=0 to 3
{
first = d*N/4
last = (d+1)*N/4-1
sort from first to last by using thread d
}
// MERGE SECTION
RESULT=empty
iR = 0
i0 = 0, i1 = N/4, i2= N/2, i3 = 3N/4 // indexes for subarrays
serial for d=0 to N/4
{
find the smallest from SUBARRAY0[i0],..,SUBARRAY3[i3]
get the winner element E
the winner SUBARRAY index is incremented
put E in RESULT[iR]
increment iR
get the next element from winner SUBARRAY
repeat this until iR == N-1
}
Title | # Comments | Views | Activity |
---|---|---|---|
How to organize data in excel ? | 2 | 106 | |
Want to delete all my personal data | 13 | 127 | |
How to jump to matching brace in eclipse editor ? | 1 | 236 | |
sorting efficency of sorting algorithm | 30 | 83 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
20 Experts available now in Live!