|
@@ -1,30 +1,30 @@
|
|
1
|
+#include <stdio.h>
|
|
2
|
+#include <omp.h>
|
1
|
3
|
#include "d2p.h"
|
2
|
4
|
#include "common.h"
|
3
|
5
|
#include "d2s.h"
|
4
|
6
|
|
5
|
|
-void merge_sort_sub_par(int* array, unsigned l, unsigned h, unsigned threads)
|
|
7
|
+void merge_sort_sub_par(int* array, unsigned l, unsigned h)
|
6
|
8
|
{
|
7
|
9
|
if (l < h) {
|
8
|
10
|
unsigned m = (l + h) / 2;
|
9
|
|
- if (threads > 1) {
|
10
|
|
- unsigned n = threads / 2;
|
11
|
|
- #pragma omp parallel sections
|
12
|
|
- {
|
13
|
|
- #pragma omp section
|
14
|
|
- merge_sort_sub_par(array, l, m, n);
|
15
|
|
- #pragma omp section
|
16
|
|
- merge_sort_sub_par(array, m + 1, h, threads - n);
|
17
|
|
- }
|
18
|
|
- }
|
19
|
|
- else {
|
20
|
|
- merge_sort_sub_seq(array, l, m);
|
21
|
|
- merge_sort_sub_seq(array, m + 1, h);
|
22
|
|
- }
|
|
11
|
+ #pragma omp task
|
|
12
|
+ merge_sort_sub_par(array, l, m);
|
|
13
|
+ #pragma omp task
|
|
14
|
+ merge_sort_sub_par(array, m + 1, h);
|
|
15
|
+ #pragma omp taskwait
|
23
|
16
|
merge_sort_merge_seq(array, l, m, h);
|
24
|
17
|
}
|
25
|
18
|
}
|
26
|
19
|
|
27
|
20
|
void merge_sort_par(int* array, unsigned s, unsigned threads)
|
28
|
21
|
{
|
29
|
|
- merge_sort_sub_par(array, 0, s - 1, threads);
|
|
22
|
+ omp_set_num_threads(threads);
|
|
23
|
+#pragma omp parallel
|
|
24
|
+ {
|
|
25
|
+#pragma omp single
|
|
26
|
+ {
|
|
27
|
+ merge_sort_sub_par(array, 0, s - 1);
|
|
28
|
+ }
|
|
29
|
+ }
|
30
|
30
|
}
|