starpu_mpi_select_node.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014, 2015 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 int _current_policy = STARPU_MPI_NODE_SELECTION_MOST_R_DATA;
  25. int starpu_mpi_node_selection_get_current_policy()
  26. {
  27. return _current_policy;
  28. }
  29. int starpu_mpi_node_selection_set_current_policy(int policy)
  30. {
  31. #ifdef STARPU_DEVEL
  32. #warning need to check the policy is valid
  33. #endif
  34. _current_policy = policy;
  35. return 0;
  36. }
  37. int _starpu_mpi_select_node_with_most_R_data(int me, int nb_nodes, struct starpu_data_descr *descr, int nb_data)
  38. {
  39. size_t *size_on_nodes;
  40. size_t max_size;
  41. int i;
  42. int xrank = 0;
  43. (void)me;
  44. size_on_nodes = (size_t *)calloc(1, nb_nodes * sizeof(size_t));
  45. for(i= 0 ; i<nb_data ; i++)
  46. {
  47. starpu_data_handle_t data = descr[i].handle;
  48. enum starpu_data_access_mode mode = descr[i].mode;
  49. if (mode & STARPU_R)
  50. {
  51. int rank = starpu_data_get_rank(data);
  52. size_on_nodes[rank] += data->ops->get_size(data);
  53. }
  54. }
  55. max_size = 0;
  56. for(i=0 ; i<nb_nodes ; i++)
  57. {
  58. if (size_on_nodes[i] > max_size)
  59. {
  60. max_size = size_on_nodes[i];
  61. xrank = i;
  62. }
  63. }
  64. free(size_on_nodes);
  65. return xrank;
  66. }
  67. int _starpu_mpi_select_node(int me, int nb_nodes, struct starpu_data_descr *descr, int nb_data, int policy)
  68. {
  69. int current_policy = policy == STARPU_MPI_NODE_SELECTION_CURRENT_POLICY ? _current_policy : policy;
  70. if (current_policy == STARPU_MPI_NODE_SELECTION_MOST_R_DATA)
  71. return _starpu_mpi_select_node_with_most_R_data(me, nb_nodes, descr, nb_data);
  72. else
  73. STARPU_ABORT_MSG("Node selection policy <%d> unknown\n", current_policy);
  74. }