starpu_mpi_stats.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2017, 2019 CNRS
  4. * Copyright (C) 2015 Université de Bordeaux
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu_mpi_stats.h>
  18. #include <common/config.h>
  19. #include <stdio.h>
  20. #include <starpu_mpi_private.h>
  21. #include <starpu_util.h>
  22. /* measure the amount of data transfers between each pair of MPI nodes */
  23. static size_t *comm_amount;
  24. static int world_size;
  25. static int stats_enabled=0;
  26. static double time_init;
  27. void _starpu_mpi_comm_amounts_init(MPI_Comm comm)
  28. {
  29. stats_enabled = starpu_get_env_number("STARPU_COMM_STATS");
  30. if (stats_enabled == -1)
  31. {
  32. stats_enabled = 0;
  33. }
  34. if (stats_enabled == 0)
  35. return;
  36. _STARPU_DISP("Warning: StarPU is executed with STARPU_COMM_STATS=1, which slows down a bit\n");
  37. starpu_mpi_comm_size(comm, &world_size);
  38. _STARPU_MPI_DEBUG(1, "allocating for %d nodes\n", world_size);
  39. _STARPU_MPI_CALLOC(comm_amount, world_size, sizeof(size_t));
  40. time_init = starpu_timing_now();
  41. }
  42. void _starpu_mpi_comm_amounts_shutdown()
  43. {
  44. if (stats_enabled == 0)
  45. return;
  46. free(comm_amount);
  47. }
  48. void _starpu_mpi_comm_amounts_inc(MPI_Comm comm, unsigned dst, MPI_Datatype datatype, int count)
  49. {
  50. int src, size;
  51. if (stats_enabled == 0)
  52. return;
  53. starpu_mpi_comm_rank(comm, &src);
  54. MPI_Type_size(datatype, &size);
  55. _STARPU_MPI_DEBUG(1, "[%d] adding %d to %d\n", src, count*size, dst);
  56. comm_amount[dst] += count*size;
  57. }
  58. void starpu_mpi_comm_amounts_retrieve(size_t *comm_amounts)
  59. {
  60. if (stats_enabled == 0)
  61. return;
  62. memcpy(comm_amounts, comm_amount, world_size * sizeof(size_t));
  63. }
  64. void _starpu_mpi_comm_amounts_display(FILE *stream, int node)
  65. {
  66. int dst;
  67. size_t sum = 0;
  68. if (stats_enabled == 0)
  69. return;
  70. double time = starpu_timing_now() - time_init;
  71. for (dst = 0; dst < world_size; dst++)
  72. {
  73. sum += comm_amount[dst];
  74. }
  75. fprintf(stream, "\n[starpu_comm_stats][%d] TOTAL:\t%f B\t%f MB\t %f B/s\t %f MB/s\n", node, (float)sum, (float)sum/1024/1024, (float)sum/(float)time, (float)sum/1204/1024/(float)time);
  76. for (dst = 0; dst < world_size; dst++)
  77. {
  78. if (comm_amount[dst])
  79. fprintf(stream, "[starpu_comm_stats][%d:%d]\t%f B\t%f MB\t %f B/s\t %f MB/s\n",
  80. node, dst, (float)comm_amount[dst], ((float)comm_amount[dst])/(1024*1024),
  81. (float)comm_amount[dst]/(float)time, ((float)comm_amount[dst])/(1024*1024)/(float)time);
  82. }
  83. }