You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

d2p.c 597B

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