starpu_mpi_stats.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Centre National de la Recherche Scientifique
  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. //#define STARPU_MPI_VERBOSE 1
  20. #include <starpu_mpi_private.h>
  21. /* measure the amount of data transfers between each pair of MPI nodes */
  22. #ifdef STARPU_COMM_STATS
  23. static size_t *comm_amount;
  24. static int world_size;
  25. #endif /* STARPU_COMM_STATS */
  26. void _starpu_mpi_comm_amounts_init(MPI_Comm comm)
  27. {
  28. #ifdef STARPU_COMM_STATS
  29. if (!getenv("STARPU_SILENT")) fprintf(stderr,"Warning: StarPU was configured with --enable-comm-stats, which slows down a bit\n");
  30. MPI_Comm_size(comm, &world_size);
  31. _STARPU_MPI_DEBUG("allocating for %d nodes\n", world_size);
  32. comm_amount = (size_t *) calloc(world_size, sizeof(size_t));
  33. #endif /* STARPU_COMM_STATS */
  34. }
  35. void _starpu_mpi_comm_amounts_free()
  36. {
  37. #ifdef STARPU_COMM_STATS
  38. free(comm_amount);
  39. #endif /* STARPU_COMM_STATS */
  40. }
  41. void _starpu_mpi_comm_amounts_inc(MPI_Comm comm __attribute__ ((unused)),
  42. unsigned dst __attribute__ ((unused)),
  43. MPI_Datatype datatype __attribute__ ((unused)),
  44. int count __attribute__ ((unused)))
  45. {
  46. #ifdef STARPU_COMM_STATS
  47. int src, size;
  48. MPI_Comm_rank(comm, &src);
  49. MPI_Type_size(datatype, &size);
  50. _STARPU_MPI_DEBUG("[%d] adding %d to %d\n", src, count*size, dst);
  51. comm_amount[dst] += count*size;
  52. #endif /* STARPU_COMM_STATS */
  53. }
  54. void _starpu_mpi_comm_amounts_display(int node)
  55. {
  56. #ifdef STARPU_COMM_STATS
  57. unsigned dst;
  58. size_t sum = 0;
  59. for (dst = 0; dst < world_size; dst++)
  60. {
  61. sum += comm_amount[dst];
  62. }
  63. fprintf(stderr, "\n[%d] Communication transfers stats:\nTOTAL transfers %f B\t%f MB\n", node, (float)sum, (float)sum/1024/1024);
  64. for (dst = 0; dst < world_size; dst++)
  65. {
  66. if (comm_amount[dst])
  67. {
  68. fprintf(stderr, "\t%d -> %d\t%f B\t%f MB\n",
  69. node, dst, (float)comm_amount[dst], ((float)comm_amount[dst])/(1024*1024));
  70. }
  71. }
  72. #endif /* STARPU_COMM_STATS */
  73. }