starpu_mpi_helper.c 2.7 KB

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