starpu_mpi_helper.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2015 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(starpu_data_handle_t data_handle, int dest, int data_tag, 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(data_handle, dest, data_tag, comm, starpu_mpi_unlock_tag_callback, tagptr);
  31. }
  32. 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)
  33. {
  34. starpu_tag_t *tagptr;
  35. STARPU_MPI_MALLOC(tagptr, sizeof(starpu_tag_t));
  36. *tagptr = tag;
  37. return starpu_mpi_irecv_detached(data_handle, source, data_tag, comm, starpu_mpi_unlock_tag_callback, tagptr);
  38. }
  39. struct arg_array
  40. {
  41. int array_size;
  42. starpu_tag_t tag;
  43. };
  44. static void starpu_mpi_array_unlock_callback(void *_arg)
  45. {
  46. struct arg_array *arg = _arg;
  47. int remaining = STARPU_ATOMIC_ADD(&arg->array_size, -1);
  48. if (remaining == 0)
  49. {
  50. starpu_tag_notify_from_apps(arg->tag);
  51. free(arg);
  52. }
  53. }
  54. int starpu_mpi_isend_array_detached_unlock_tag(unsigned array_size,
  55. starpu_data_handle_t *data_handle, int *dest, int *data_tag,
  56. MPI_Comm *comm, starpu_tag_t tag)
  57. {
  58. if (!array_size)
  59. return 0;
  60. struct arg_array *arg;
  61. STARPU_MPI_MALLOC(arg, sizeof(struct arg_array));
  62. arg->array_size = array_size;
  63. arg->tag = tag;
  64. unsigned elem;
  65. for (elem = 0; elem < array_size; elem++)
  66. {
  67. starpu_mpi_isend_detached(data_handle[elem], dest[elem], data_tag[elem], comm[elem], starpu_mpi_array_unlock_callback, arg);
  68. }
  69. return 0;
  70. }
  71. 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)
  72. {
  73. if (!array_size)
  74. return 0;
  75. struct arg_array *arg;
  76. STARPU_MPI_MALLOC(arg, sizeof(struct arg_array));
  77. arg->array_size = array_size;
  78. arg->tag = tag;
  79. unsigned elem;
  80. for (elem = 0; elem < array_size; elem++)
  81. {
  82. starpu_mpi_irecv_detached(data_handle[elem], source[elem], data_tag[elem], comm[elem], starpu_mpi_array_unlock_callback, arg);
  83. }
  84. return 0;
  85. }