Lecture 7 - Parallel Sorting Algorithms Flashcards
1
Q
MergeSort
A
SeqMerge ( int a[k], int b[k], int c[2k] )
{
int ap=0, bp=0, cp=0;
while ( cp < 2k ) { // assume a[k] = b[k] = ∞
if (a[ap]<b></b>
2
Q
Parallel MergeSort
A
void SParMergesort ( int *array, int n ) // in place { if (n==1) return; // nothing to sort if (depth_limit_for_recursive_parallel_decomposition_reached()) SeqMergesort( array, n ); // switch to sequential // parallel divide and conquer: in parallel do { SParMergesort ( array, n/2); SParMergesort ( array + n/2, n-n/2 ); } // now the two subarrays are sorted seq SeqMerge ( array, n/2, n-n/2 ); } void SeqMerge ( int *array, int n1, int n2 ) // sequential merge in place { // ... merge in O(n1+n2) steps ... }