starpu_mpi_helper.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012,2014-2017 CNRS
  4. * Copyright (C) 2010,2011,2014,2015,2017 Université de Bordeaux
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu_mpi.h>
  18. #include <starpu_mpi_private.h>
  19. static void starpu_mpi_unlock_tag_callback(void *arg)
  20. {
  21. starpu_tag_t *tagptr = arg;
  22. starpu_tag_notify_from_apps(*tagptr);
  23. free(tagptr);
  24. }
  25. int starpu_mpi_isend_detached_unlock_tag_prio(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, int prio, MPI_Comm comm, starpu_tag_t tag)
  26. {
  27. starpu_tag_t *tagptr;
  28. _STARPU_MPI_MALLOC(tagptr, sizeof(starpu_tag_t));
  29. *tagptr = tag;
  30. return starpu_mpi_isend_detached_prio(data_handle, dest, data_tag, prio, comm, starpu_mpi_unlock_tag_callback, tagptr);
  31. }
  32. int starpu_mpi_isend_detached_unlock_tag(starpu_data_handle_t data_handle, int dest, starpu_mpi_tag_t data_tag, MPI_Comm comm, starpu_tag_t tag)
  33. {
  34. return starpu_mpi_isend_detached_unlock_tag_prio(data_handle, dest, data_tag, 0, comm, tag);
  35. }
  36. int starpu_mpi_irecv_detached_unlock_tag(starpu_data_handle_t data_handle, int source, starpu_mpi_tag_t data_tag, MPI_Comm comm, starpu_tag_t tag)
  37. {
  38. starpu_tag_t *tagptr;
  39. _STARPU_MPI_MALLOC(tagptr, sizeof(starpu_tag_t));
  40. *tagptr = tag;
  41. return starpu_mpi_irecv_detached(data_handle, source, data_tag, comm, starpu_mpi_unlock_tag_callback, tagptr);
  42. }
  43. struct arg_array
  44. {
  45. int array_size;
  46. starpu_tag_t tag;
  47. };
  48. static void starpu_mpi_array_unlock_callback(void *_arg)
  49. {
  50. struct arg_array *arg = _arg;
  51. int remaining = STARPU_ATOMIC_ADD(&arg->array_size, -1);
  52. if (remaining == 0)
  53. {
  54. starpu_tag_notify_from_apps(arg->tag);
  55. free(arg);
  56. }
  57. }
  58. int starpu_mpi_isend_array_detached_unlock_tag_prio(unsigned array_size, starpu_data_handle_t *data_handle, int *dest, starpu_mpi_tag_t *data_tag, int *prio, MPI_Comm *comm, starpu_tag_t tag)
  59. {
  60. if (!array_size)
  61. return 0;
  62. struct arg_array *arg;
  63. _STARPU_MPI_MALLOC(arg, sizeof(struct arg_array));
  64. arg->array_size = array_size;
  65. arg->tag = tag;
  66. unsigned elem;
  67. for (elem = 0; elem < array_size; elem++)
  68. {
  69. int p = 0;
  70. if (prio)
  71. p = prio[elem];
  72. starpu_mpi_isend_detached_prio(data_handle[elem], dest[elem], data_tag[elem], p, comm[elem], starpu_mpi_array_unlock_callback, arg);
  73. }
  74. return 0;
  75. }
  76. int starpu_mpi_isend_array_detached_unlock_tag(unsigned array_size, starpu_data_handle_t *data_handle, int *dest, starpu_mpi_tag_t *data_tag, MPI_Comm *comm, starpu_tag_t tag)
  77. {
  78. return starpu_mpi_isend_array_detached_unlock_tag_prio(array_size, data_handle, dest, data_tag, NULL, comm, tag);
  79. }
  80. int starpu_mpi_irecv_array_detached_unlock_tag(unsigned array_size, starpu_data_handle_t *data_handle, int *source, starpu_mpi_tag_t *data_tag, MPI_Comm *comm, starpu_tag_t tag)
  81. {
  82. if (!array_size)
  83. return 0;
  84. struct arg_array *arg;
  85. _STARPU_MPI_MALLOC(arg, sizeof(struct arg_array));
  86. arg->array_size = array_size;
  87. arg->tag = tag;
  88. unsigned elem;
  89. for (elem = 0; elem < array_size; elem++)
  90. {
  91. starpu_mpi_irecv_detached(data_handle[elem], source[elem], data_tag[elem], comm[elem], starpu_mpi_array_unlock_callback, arg);
  92. }
  93. return 0;
  94. }