starpu_mpi_helper.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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. static void starpu_mpi_unlock_tag_callback(void *arg)
  18. {
  19. starpu_tag_t *tagptr = arg;
  20. starpu_tag_notify_from_apps(*tagptr);
  21. free(tagptr);
  22. }
  23. int starpu_mpi_isend_detached_unlock_tag(starpu_data_handle data_handle,
  24. int dest, int mpi_tag, MPI_Comm comm, starpu_tag_t tag)
  25. {
  26. starpu_tag_t *tagptr = malloc(sizeof(starpu_tag_t));
  27. *tagptr = tag;
  28. return starpu_mpi_isend_detached(data_handle, dest, mpi_tag, comm,
  29. starpu_mpi_unlock_tag_callback, tagptr);
  30. }
  31. int starpu_mpi_irecv_detached_unlock_tag(starpu_data_handle data_handle, int source, int mpi_tag, MPI_Comm comm, starpu_tag_t tag)
  32. {
  33. starpu_tag_t *tagptr = malloc(sizeof(starpu_tag_t));
  34. *tagptr = tag;
  35. return starpu_mpi_irecv_detached(data_handle, source, mpi_tag, comm,
  36. starpu_mpi_unlock_tag_callback, tagptr);
  37. }
  38. struct arg_array {
  39. int array_size;
  40. starpu_tag_t tag;
  41. };
  42. static void starpu_mpi_array_unlock_callback(void *_arg)
  43. {
  44. struct arg_array *arg = _arg;
  45. int remaining = STARPU_ATOMIC_ADD(&arg->array_size, -1);
  46. if (remaining == 0)
  47. {
  48. starpu_tag_notify_from_apps(arg->tag);
  49. free(arg);
  50. }
  51. }
  52. int starpu_mpi_isend_array_detached_unlock_tag(unsigned array_size,
  53. starpu_data_handle *data_handle, int *dest, int *mpi_tag,
  54. MPI_Comm *comm, starpu_tag_t tag)
  55. {
  56. struct arg_array *arg = malloc(sizeof(struct arg_array));
  57. arg->array_size = array_size;
  58. arg->tag = tag;
  59. unsigned elem;
  60. for (elem = 0; elem < array_size; elem++)
  61. {
  62. starpu_mpi_isend_detached(data_handle[elem], dest[elem],
  63. mpi_tag[elem], comm[elem],
  64. starpu_mpi_array_unlock_callback, arg);
  65. }
  66. return 0;
  67. }
  68. int starpu_mpi_irecv_array_detached_unlock_tag(unsigned array_size, starpu_data_handle *data_handle, int *source, int *mpi_tag, MPI_Comm *comm, starpu_tag_t tag)
  69. {
  70. struct arg_array *arg = malloc(sizeof(struct arg_array));
  71. arg->array_size = array_size;
  72. arg->tag = tag;
  73. unsigned elem;
  74. for (elem = 0; elem < array_size; elem++)
  75. {
  76. starpu_mpi_irecv_detached(data_handle[elem], source[elem],
  77. mpi_tag[elem], comm[elem],
  78. starpu_mpi_array_unlock_callback, arg);
  79. }
  80. return 0;
  81. }