starpu_mpi_helper.c 2.7 KB

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