starpu_mpi_cache_stats.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014 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_cache_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_cache_amount;
  22. static int world_size;
  23. static int stats_enabled=0;
  24. void _starpu_mpi_cache_stats_init(MPI_Comm comm)
  25. {
  26. stats_enabled = starpu_get_env_number("STARPU_MPI_CACHE_STATS");
  27. if (stats_enabled == -1)
  28. {
  29. stats_enabled = 0;
  30. }
  31. if (stats_enabled == 0) return;
  32. if (!getenv("STARPU_SILENT")) fprintf(stderr,"Warning: StarPU is executed with STARPU_MPI_CACHE_STATS=1, which slows down a bit\n");
  33. MPI_Comm_size(comm, &world_size);
  34. _STARPU_MPI_DEBUG(1, "allocating for %d nodes\n", world_size);
  35. comm_cache_amount = (size_t *) calloc(world_size, sizeof(size_t));
  36. }
  37. void _starpu_mpi_cache_stats_free()
  38. {
  39. if (stats_enabled == 0) return;
  40. free(comm_cache_amount);
  41. }
  42. void _starpu_mpi_cache_stats_update(int src, unsigned dst, starpu_data_handle_t data_handle, int count)
  43. {
  44. size_t size;
  45. if (stats_enabled == 0) return;
  46. size = starpu_data_get_size(data_handle);
  47. if (count == 1)
  48. {
  49. fprintf(stderr, "[starpu_mpi_cache_stats][%d] adding %ld to %d\n", src, (long)size, dst);
  50. }
  51. else // count == -1
  52. {
  53. fprintf(stderr, "[starpu_mpi_cache_stats][%d] removing %ld from %d\n", src, (long)size, dst);
  54. }
  55. comm_cache_amount[dst] += count * size;
  56. }