Browse Source

switched to tasks

master
Robin Thoni 8 years ago
parent
commit
bdc6c2319d
2 changed files with 17 additions and 17 deletions
  1. 16
    16
      d2p.c
  2. 1
    1
      d2p.h

+ 16
- 16
d2p.c View File

1
+#include <stdio.h>
2
+#include <omp.h>
1
 #include "d2p.h"
3
 #include "d2p.h"
2
 #include "common.h"
4
 #include "common.h"
3
 #include "d2s.h"
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
   if (l < h) {
9
   if (l < h) {
8
     unsigned m = (l + h) / 2;
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
     merge_sort_merge_seq(array, l, m, h);
16
     merge_sort_merge_seq(array, l, m, h);
24
   }
17
   }
25
 }
18
 }
26
 
19
 
27
 void merge_sort_par(int* array, unsigned s, unsigned threads)
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
 }

+ 1
- 1
d2p.h View File

1
 #ifndef D2P_H
1
 #ifndef D2P_H
2
 #define D2P_H
2
 #define D2P_H
3
 
3
 
4
-void merge_sort_sub_par(int* array, unsigned l, unsigned h, unsigned threads);
4
+void merge_sort_sub_par(int* array, unsigned l, unsigned h);
5
 void merge_sort_par(int* array, unsigned s, unsigned threads);
5
 void merge_sort_par(int* array, unsigned s, unsigned threads);
6
 
6
 
7
 #endif
7
 #endif

Loading…
Cancel
Save