starpu_mpi_stats.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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()
  27. {
  28. #ifdef STARPU_COMM_STATS
  29. int i;
  30. if (!getenv("STARPU_SILENT")) fprintf(stderr,"Warning: StarPU was configured with --enable-comm-stats, which slows down a bit\n");
  31. MPI_Comm_size(MPI_COMM_WORLD, &world_size);
  32. _STARPU_MPI_DEBUG("allocating for %d nodes\n", world_size);
  33. comm_amount = (size_t **) calloc(1, world_size * sizeof(size_t *));
  34. for(i=0 ; i<world_size ; i++)
  35. {
  36. comm_amount[i] = (size_t *) calloc(1, world_size * sizeof(size_t));
  37. }
  38. #endif /* STARPU_COMM_STATS */
  39. }
  40. void _starpu_mpi_comm_amounts_free()
  41. {
  42. #ifdef STARPU_COMM_STATS
  43. int i;
  44. for(i=0 ; i<world_size ; i++)
  45. {
  46. free(comm_amount[i]);
  47. }
  48. free(comm_amount);
  49. #endif /* STARPU_COMM_STATS */
  50. }
  51. void _starpu_mpi_comm_amounts_inc(MPI_Comm comm __attribute__ ((unused)),
  52. unsigned dst __attribute__ ((unused)), MPI_Datatype datatype __attribute__ ((unused)))
  53. {
  54. #ifdef STARPU_COMM_STATS
  55. int src, size;
  56. MPI_Comm_rank(comm, &src);
  57. MPI_Type_size(datatype, &size);
  58. _STARPU_MPI_DEBUG("adding %d from %d to %d\n", size, src, dst);
  59. comm_amount[src][dst] += size;
  60. #endif /* STARPU_COMM_STATS */
  61. }
  62. void _starpu_mpi_comm_amounts_display()
  63. {
  64. #ifdef STARPU_COMM_STATS
  65. unsigned src, dst;
  66. size_t sum = 0;
  67. for (dst = 0; dst < world_size; dst++)
  68. for (src = 0; src < world_size; src++)
  69. {
  70. sum += comm_amount[src][dst];
  71. }
  72. fprintf(stderr, "\nCommunication transfers stats:\nTOTAL transfers %f B\t%f MB\n", (float)sum, (float)sum/1024/1024);
  73. for (dst = 0; dst < world_size; dst++)
  74. for (src = 0; src < world_size; src++)
  75. {
  76. if (comm_amount[src][dst])
  77. {
  78. fprintf(stderr, "\t%d <-> %d\t%f B\t%f MB\n",
  79. src, dst, (float)comm_amount[src][dst] + (float)comm_amount[dst][src],
  80. ((float)comm_amount[src][dst] + (float)comm_amount[dst][src])/(1024*1024));
  81. fprintf(stderr, "\t\t%d -> %d\t%f B\t%f MB\n",
  82. src, dst, (float)comm_amount[src][dst],
  83. ((float)comm_amount[src][dst])/(1024*1024));
  84. fprintf(stderr, "\t\t%d -> %d\t%f B\t%f MB\n",
  85. dst, src, (float)comm_amount[dst][src],
  86. ((float)comm_amount[dst][src])/(1024*1024));
  87. }
  88. }
  89. #endif /* STARPU_COMM_STATS */
  90. }