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 719B

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