starpu_mpi_helper.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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.h>
  17. #include <starpu_mpi_private.h>
  18. static void starpu_mpi_unlock_tag_callback(void *arg)
  19. {
  20. starpu_tag_t *tagptr = arg;
  21. starpu_tag_notify_from_apps(*tagptr);
  22. free(tagptr);
  23. }
  24. 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)
  25. {
  26. starpu_tag_t *tagptr;
  27. _STARPU_MPI_MALLOC(tagptr, sizeof(starpu_tag_t));
  28. *tagptr = tag;
  29. return starpu_mpi_isend_detached_prio(data_handle, dest, data_tag, prio, comm, starpu_mpi_unlock_tag_callback, tagptr);
  30. }
  31. 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)
  32. {
  33. return starpu_mpi_isend_detached_unlock_tag_prio(data_handle, dest, data_tag, 0, comm, tag);
  34. }
  35. 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)
  36. {
  37. starpu_tag_t *tagptr;
  38. _STARPU_MPI_MALLOC(tagptr, sizeof(starpu_tag_t));
  39. *tagptr = tag;
  40. return starpu_mpi_irecv_detached(data_handle, source, data_tag, comm, starpu_mpi_unlock_tag_callback, tagptr);
  41. }
  42. struct arg_array
  43. {
  44. int array_size;
  45. starpu_tag_t tag;
  46. };
  47. static void starpu_mpi_array_unlock_callback(void *_arg)
  48. {
  49. struct arg_array *arg = _arg;
  50. int remaining = STARPU_ATOMIC_ADD(&arg->array_size, -1);
  51. if (remaining == 0)
  52. {
  53. starpu_tag_notify_from_apps(arg->tag);
  54. free(arg);
  55. }
  56. }
  57. 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)
  58. {
  59. if (!array_size)
  60. return 0;
  61. struct arg_array *arg;
  62. _STARPU_MPI_MALLOC(arg, sizeof(struct arg_array));
  63. arg->array_size = array_size;
  64. arg->tag = tag;
  65. unsigned elem;
  66. for (elem = 0; elem < array_size; elem++)
  67. {
  68. int p = 0;
  69. if (prio)
  70. p = prio[elem];
  71. starpu_mpi_isend_detached_prio(data_handle[elem], dest[elem], data_tag[elem], p, comm[elem], starpu_mpi_array_unlock_callback, arg);
  72. }
  73. return 0;
  74. }
  75. 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)
  76. {
  77. return starpu_mpi_isend_array_detached_unlock_tag_prio(array_size, data_handle, dest, data_tag, NULL, comm, tag);
  78. }
  79. 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)
  80. {
  81. if (!array_size)
  82. return 0;
  83. struct arg_array *arg;
  84. _STARPU_MPI_MALLOC(arg, sizeof(struct arg_array));
  85. arg->array_size = array_size;
  86. arg->tag = tag;
  87. unsigned elem;
  88. for (elem = 0; elem < array_size; elem++)
  89. {
  90. starpu_mpi_irecv_detached(data_handle[elem], source[elem], data_tag[elem], comm[elem], starpu_mpi_array_unlock_callback, arg);
  91. }
  92. return 0;
  93. }