starpu_mpi_stats.c 2.5 KB

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