burst_gemm.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. /*
  17. * Program to be executed with trace recording to watch the impact of
  18. * computations (or task polling) on communications.
  19. */
  20. #include <limits.h>
  21. #include <string.h>
  22. #include <unistd.h>
  23. #include <sys/types.h>
  24. #include <starpu_mpi.h>
  25. #include <starpu_fxt.h>
  26. #include "helper.h"
  27. #include "gemm_helper.h"
  28. #include "burst_helper.h"
  29. void parse_args(int argc, char **argv)
  30. {
  31. int i;
  32. for (i = 1; i < argc; i++)
  33. {
  34. if (strcmp(argv[i], "-nblocks") == 0)
  35. {
  36. char *argptr;
  37. nslices = strtol(argv[++i], &argptr, 10);
  38. matrix_dim = 320 * nslices;
  39. }
  40. else if (strcmp(argv[i], "-size") == 0)
  41. {
  42. char *argptr;
  43. unsigned matrix_dim_tmp = strtol(argv[++i], &argptr, 10);
  44. if (matrix_dim_tmp % 320 != 0)
  45. {
  46. fprintf(stderr, "Matrix size has to be a multiple of 320\n");
  47. }
  48. else
  49. {
  50. matrix_dim = matrix_dim_tmp;
  51. nslices = matrix_dim / 320;
  52. }
  53. }
  54. else if (strcmp(argv[i], "-check") == 0)
  55. {
  56. check = 1;
  57. }
  58. else if (strcmp(argv[i], "-nreqs") == 0)
  59. {
  60. burst_nb_requests = atoi(argv[++i]);
  61. }
  62. else if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
  63. {
  64. fprintf(stderr,"Usage: %s [-nblocks n] [-size size] [-check] [-nreqs nreqs]\n", argv[0]);
  65. fprintf(stderr,"Currently selected: matrix size: %u - %u blocks - %d requests in each burst\n", matrix_dim, nslices, burst_nb_requests);
  66. exit(EXIT_SUCCESS);
  67. }
  68. else
  69. {
  70. fprintf(stderr,"Unrecognized option %s\n", argv[i]);
  71. exit(EXIT_FAILURE);
  72. }
  73. }
  74. }
  75. int main(int argc, char **argv)
  76. {
  77. int ret, mpi_init, worldsize, mpi_rank;
  78. parse_args(argc, argv);
  79. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  80. ret = starpu_mpi_init_conf(&argc, &argv, mpi_init, MPI_COMM_WORLD, NULL);
  81. if (ret == -ENODEV)
  82. return 77;
  83. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  84. starpu_mpi_comm_rank(MPI_COMM_WORLD, &mpi_rank);
  85. starpu_mpi_comm_size(MPI_COMM_WORLD, &worldsize);
  86. if (worldsize < 2)
  87. {
  88. if (mpi_rank == 0)
  89. FPRINTF(stderr, "We need 2 processes.\n");
  90. starpu_mpi_shutdown();
  91. if (!mpi_init)
  92. MPI_Finalize();
  93. return STARPU_TEST_SKIPPED;
  94. }
  95. gemm_alloc_data();
  96. if (gemm_init_data() == -ENODEV)
  97. goto enodev;
  98. burst_init_data(mpi_rank);
  99. /* Wait for everything and everybody: */
  100. starpu_task_wait_for_all();
  101. starpu_mpi_barrier(MPI_COMM_WORLD);
  102. FPRINTF(stderr, "** Burst warmup **\n");
  103. burst_all(mpi_rank);
  104. starpu_sleep(0.3); // sleep to easily distinguish different bursts in traces
  105. FPRINTF(stderr, "** Burst while there is no task available, but workers are polling **\n");
  106. burst_all(mpi_rank);
  107. starpu_sleep(0.3); // sleep to easily distinguish different bursts in traces
  108. FPRINTF(stderr, "** Burst while there is no task available, workers are paused **\n");
  109. starpu_pause();
  110. burst_all(mpi_rank);
  111. starpu_sleep(0.3); // sleep to easily distinguish different bursts in traces
  112. FPRINTF(stderr, "** Burst while workers are really working **\n");
  113. if(gemm_submit_tasks() == -ENODEV)
  114. goto enodev;
  115. starpu_resume();
  116. burst_all(mpi_rank);
  117. FPRINTF(stderr, "Burst done, now waiting for computing tasks to finish\n");
  118. /* Wait for everything and everybody: */
  119. starpu_task_wait_for_all();
  120. starpu_mpi_barrier(MPI_COMM_WORLD);
  121. enodev:
  122. gemm_release();
  123. burst_free_data(mpi_rank);
  124. starpu_mpi_shutdown();
  125. if (!mpi_init)
  126. MPI_Finalize();
  127. return ret;
  128. }