Selaa lähdekoodia

switched to tasks

master
Robin Thoni 7 vuotta sitten
vanhempi
commit
bdc6c2319d
2 muutettua tiedostoa jossa 17 lisäystä ja 17 poistoa
  1. 16
    16
      d2p.c
  2. 1
    1
      d2p.h

+ 16
- 16
d2p.c Näytä tiedosto

@@ -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
 }

+ 1
- 1
d2p.h Näytä tiedosto

@@ -1,7 +1,7 @@
1 1
 #ifndef D2P_H
2 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 5
 void merge_sort_par(int* array, unsigned s, unsigned threads);
6 6
 
7 7
 #endif

Loading…
Peruuta
Tallenna