starpu_mpi_stats.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2017 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. /* 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. void _starpu_mpi_comm_amounts_init(MPI_Comm comm)
  26. {
  27. stats_enabled = starpu_get_env_number("STARPU_COMM_STATS");
  28. if (stats_enabled == -1)
  29. {
  30. stats_enabled = 0;
  31. }
  32. if (stats_enabled == 0)
  33. return;
  34. _STARPU_DISP("Warning: StarPU is executed with STARPU_COMM_STATS=1, which slows down a bit\n");
  35. starpu_mpi_comm_size(comm, &world_size);
  36. _STARPU_MPI_DEBUG(1, "allocating for %d nodes\n", world_size);
  37. _STARPU_MPI_CALLOC(comm_amount, world_size, sizeof(size_t));
  38. }
  39. void _starpu_mpi_comm_amounts_shutdown()
  40. {
  41. if (stats_enabled == 0)
  42. return;
  43. free(comm_amount);
  44. }
  45. void _starpu_mpi_comm_amounts_inc(MPI_Comm comm, unsigned dst, MPI_Datatype datatype, int count)
  46. {
  47. int src, size;
  48. if (stats_enabled == 0)
  49. return;
  50. starpu_mpi_comm_rank(comm, &src);
  51. MPI_Type_size(datatype, &size);
  52. _STARPU_MPI_DEBUG(1, "[%d] adding %d to %d\n", src, count*size, dst);
  53. comm_amount[dst] += count*size;
  54. }
  55. void starpu_mpi_comm_amounts_retrieve(size_t *comm_amounts)
  56. {
  57. if (stats_enabled == 0)
  58. return;
  59. memcpy(comm_amounts, comm_amount, world_size * sizeof(size_t));
  60. }
  61. void _starpu_mpi_comm_amounts_display(FILE *stream, int node)
  62. {
  63. int dst;
  64. size_t sum = 0;
  65. if (stats_enabled == 0)
  66. return;
  67. for (dst = 0; dst < world_size; dst++)
  68. {
  69. sum += comm_amount[dst];
  70. }
  71. fprintf(stream, "\n[starpu_comm_stats][%d] TOTAL:\t%f B\t%f MB\n", node, (float)sum, (float)sum/1024/1024);
  72. for (dst = 0; dst < world_size; dst++)
  73. {
  74. if (comm_amount[dst])
  75. {
  76. fprintf(stream, "[starpu_comm_stats][%d->%d]\t%f B\t%f MB\n",
  77. node, dst, (float)comm_amount[dst], ((float)comm_amount[dst])/(1024*1024));
  78. }
  79. }
  80. }