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.

main.c 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #define _POSIX_C_SOURCE 199309L
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include "common.h"
  6. #include "d2s.h"
  7. #include "d2p.h"
  8. int main(int argc, char** argv)
  9. {
  10. int oprint_stats = 1;
  11. int oprint_array = 1;
  12. int otest = 0;
  13. for (int i = 1; i < argc; ++i) {
  14. if (!strcmp("--no-stats", argv[i])) {
  15. oprint_stats = 0;
  16. }
  17. else if (!strcmp("--no-array", argv[i])) {
  18. oprint_array = 0;
  19. }
  20. else if (!strcmp("--test", argv[i])) {
  21. otest = 1;
  22. }
  23. }
  24. if (otest) {
  25. oprint_stats = 0;
  26. oprint_array = 1;
  27. }
  28. int* array;
  29. unsigned n;
  30. unsigned threads[3] = {0, 12, 24};
  31. unsigned threads_count = (otest ? 1 : sizeof(threads) / sizeof(*threads));
  32. do {
  33. read_input(&array, &n);
  34. if (array && n) {
  35. for (unsigned t = 0; t < threads_count; ++t) {
  36. unsigned thread_count = threads[t];
  37. struct timespec start = get_time();
  38. if (thread_count == 0) {
  39. merge_sort_seq(array, 2 * n);
  40. }
  41. else {
  42. merge_sort_par(array, 2 * n, thread_count);
  43. }
  44. struct timespec ts = get_duration(&start);
  45. if (oprint_array) {
  46. print_array(array, 2 * n);
  47. }
  48. if (oprint_stats) {
  49. printf("%3dcpu %3dthreads %6d ", get_cpu_count(), thread_count, n);
  50. print_time(&ts);
  51. printf("\n");
  52. }
  53. }
  54. }
  55. } while (array && n);
  56. return 0;
  57. }