starpu_mpi_select_node.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <stdarg.h>
  17. #include <mpi.h>
  18. #include <starpu.h>
  19. #include <starpu_data.h>
  20. #include <starpu_mpi_private.h>
  21. #include <starpu_mpi_select_node.h>
  22. #include <starpu_mpi_task_insert.h>
  23. #include <datawizard/coherency.h>
  24. static char *_default_policy = "node_with_most_R_data";
  25. char *starpu_mpi_node_selection_get_default_policy()
  26. {
  27. return _default_policy;
  28. }
  29. int starpu_mpi_node_selection_set_default_policy(char *policy)
  30. {
  31. strcpy(_default_policy, policy);
  32. return 0;
  33. }
  34. int _starpu_mpi_select_node_with_most_R_data(int me, int nb_nodes, struct starpu_data_descr *descr, int nb_data)
  35. {
  36. size_t *size_on_nodes;
  37. size_t max_size;
  38. int i;
  39. int xrank = 0;
  40. (void)me;
  41. size_on_nodes = (size_t *)calloc(1, nb_nodes * sizeof(size_t));
  42. for(i= 0 ; i<nb_data ; i++)
  43. {
  44. starpu_data_handle_t data = descr[i].handle;
  45. enum starpu_data_access_mode mode = descr[i].mode;
  46. if (mode & STARPU_R)
  47. {
  48. int rank = starpu_data_get_rank(data);
  49. size_on_nodes[rank] += data->ops->get_size(data);
  50. }
  51. }
  52. max_size = 0;
  53. for(i=0 ; i<nb_nodes ; i++)
  54. {
  55. if (size_on_nodes[i] > max_size)
  56. {
  57. max_size = size_on_nodes[i];
  58. xrank = i;
  59. }
  60. }
  61. return xrank;
  62. }
  63. int _starpu_mpi_select_node(int me, int nb_nodes, struct starpu_data_descr *descr, int nb_data, char *policy)
  64. {
  65. char *current_policy = policy ? policy : _default_policy;
  66. if (current_policy == NULL)
  67. STARPU_ABORT_MSG("Node selection policy MUST be defined\n");
  68. if (strcmp(current_policy, "node_with_most_R_data") == 0)
  69. return _starpu_mpi_select_node_with_most_R_data(me, nb_nodes, descr, nb_data);
  70. else
  71. STARPU_ABORT_MSG("Node selection policy <%s> unknown\n", current_policy);
  72. }