starpu_mpi_helper.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2012 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_t 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_t 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. {
  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 *mpi_tag,
  56. MPI_Comm *comm, starpu_tag_t tag)
  57. {
  58. struct arg_array *arg = malloc(sizeof(struct arg_array));
  59. arg->array_size = array_size;
  60. arg->tag = tag;
  61. unsigned elem;
  62. for (elem = 0; elem < array_size; elem++)
  63. {
  64. starpu_mpi_isend_detached(data_handle[elem], dest[elem],
  65. mpi_tag[elem], comm[elem],
  66. starpu_mpi_array_unlock_callback, arg);
  67. }
  68. return 0;
  69. }
  70. int starpu_mpi_irecv_array_detached_unlock_tag(unsigned array_size, starpu_data_handle_t *data_handle, int *source, int *mpi_tag, MPI_Comm *comm, starpu_tag_t tag)
  71. {
  72. struct arg_array *arg = malloc(sizeof(struct arg_array));
  73. arg->array_size = array_size;
  74. arg->tag = tag;
  75. unsigned elem;
  76. for (elem = 0; elem < array_size; elem++)
  77. {
  78. starpu_mpi_irecv_detached(data_handle[elem], source[elem],
  79. mpi_tag[elem], comm[elem],
  80. starpu_mpi_array_unlock_callback, arg);
  81. }
  82. return 0;
  83. }