starpu_mpi_stats.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-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. #include <starpu_mpi_stats.h>
  17. #include <common/config.h>
  18. #include <stdio.h>
  19. #include <starpu_mpi_private.h>
  20. #include <starpu_util.h>
  21. /* measure the amount of data transfers between each pair of MPI nodes */
  22. static size_t *comm_amount;
  23. static int world_size;
  24. static int stats_enabled=0;
  25. static double time_init;
  26. void _starpu_mpi_comm_amounts_init(MPI_Comm comm)
  27. {
  28. stats_enabled = starpu_get_env_number("STARPU_COMM_STATS");
  29. if (stats_enabled == -1)
  30. {
  31. stats_enabled = 0;
  32. }
  33. if (stats_enabled == 0)
  34. return;
  35. _STARPU_DISP("Warning: StarPU is executed with STARPU_COMM_STATS=1, which slows down a bit\n");
  36. starpu_mpi_comm_size(comm, &world_size);
  37. _STARPU_MPI_DEBUG(1, "allocating for %d nodes\n", world_size);
  38. _STARPU_MPI_CALLOC(comm_amount, world_size, sizeof(size_t));
  39. time_init = starpu_timing_now();
  40. }
  41. void _starpu_mpi_comm_amounts_shutdown()
  42. {
  43. if (stats_enabled == 0)
  44. return;
  45. free(comm_amount);
  46. }
  47. void _starpu_mpi_comm_amounts_inc(MPI_Comm comm, unsigned dst, MPI_Datatype datatype, int count)
  48. {
  49. int src, size;
  50. if (stats_enabled == 0)
  51. return;
  52. starpu_mpi_comm_rank(comm, &src);
  53. MPI_Type_size(datatype, &size);
  54. _STARPU_MPI_DEBUG(1, "[%d] adding %d to %d\n", src, count*size, dst);
  55. comm_amount[dst] += count*size;
  56. }
  57. void starpu_mpi_comm_amounts_retrieve(size_t *comm_amounts)
  58. {
  59. if (stats_enabled == 0)
  60. return;
  61. memcpy(comm_amounts, comm_amount, world_size * sizeof(size_t));
  62. }
  63. void _starpu_mpi_comm_amounts_display(FILE *stream, int node)
  64. {
  65. int dst;
  66. size_t sum = 0;
  67. if (stats_enabled == 0)
  68. return;
  69. double time = starpu_timing_now() - time_init;
  70. for (dst = 0; dst < world_size; dst++)
  71. {
  72. sum += comm_amount[dst];
  73. }
  74. 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);
  75. for (dst = 0; dst < world_size; dst++)
  76. {
  77. if (comm_amount[dst])
  78. fprintf(stream, "[starpu_comm_stats][%d:%d]\t%f B\t%f MB\t %f B/s\t %f MB/s\n",
  79. node, dst, (float)comm_amount[dst], ((float)comm_amount[dst])/(1024*1024),
  80. (float)comm_amount[dst]/(float)time, ((float)comm_amount[dst])/(1024*1024)/(float)time);
  81. }
  82. }