starpu_mpi_helper.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2015, 2017 Université de Bordeaux
  4. * Copyright (C) 2010, 2012, 2014, 2016 CNRS
  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, int 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, int 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, int 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,
  59. starpu_data_handle_t *data_handle, int *dest, int *data_tag, int *prio,
  60. MPI_Comm *comm, starpu_tag_t tag)
  61. {
  62. if (!array_size)
  63. return 0;
  64. struct arg_array *arg;
  65. _STARPU_MPI_MALLOC(arg, sizeof(struct arg_array));
  66. arg->array_size = array_size;
  67. arg->tag = tag;
  68. unsigned elem;
  69. for (elem = 0; elem < array_size; elem++)
  70. {
  71. int p = 0;
  72. if (prio)
  73. p = prio[elem];
  74. starpu_mpi_isend_detached_prio(data_handle[elem], dest[elem], data_tag[elem], p, comm[elem], starpu_mpi_array_unlock_callback, arg);
  75. }
  76. return 0;
  77. }
  78. int starpu_mpi_isend_array_detached_unlock_tag(unsigned array_size,
  79. starpu_data_handle_t *data_handle, int *dest, int *data_tag,
  80. MPI_Comm *comm, starpu_tag_t tag)
  81. {
  82. return starpu_mpi_isend_array_detached_unlock_tag_prio(array_size, data_handle, dest, data_tag, NULL, comm, tag);
  83. }
  84. int starpu_mpi_irecv_array_detached_unlock_tag(unsigned array_size, starpu_data_handle_t *data_handle, int *source, int *data_tag, MPI_Comm *comm, starpu_tag_t tag)
  85. {
  86. if (!array_size)
  87. return 0;
  88. struct arg_array *arg;
  89. _STARPU_MPI_MALLOC(arg, sizeof(struct arg_array));
  90. arg->array_size = array_size;
  91. arg->tag = tag;
  92. unsigned elem;
  93. for (elem = 0; elem < array_size; elem++)
  94. {
  95. starpu_mpi_irecv_detached(data_handle[elem], source[elem], data_tag[elem], comm[elem], starpu_mpi_array_unlock_callback, arg);
  96. }
  97. return 0;
  98. }