starpu_mpi_early_request.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2014 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015 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 <stdlib.h>
  18. #include <starpu_mpi.h>
  19. #include <starpu_mpi_private.h>
  20. #include <starpu_mpi_early_request.h>
  21. #include <common/uthash.h>
  22. /** stores application requests for which data have not been received yet */
  23. struct _starpu_mpi_early_request_hashlist
  24. {
  25. struct _starpu_mpi_req_list *list;
  26. UT_hash_handle hh;
  27. struct _starpu_mpi_node_tag node_tag;
  28. };
  29. struct _starpu_mpi_early_request_hashlist *_starpu_mpi_early_request_hash;
  30. int _starpu_mpi_early_request_hash_count;
  31. void _starpu_mpi_early_request_init()
  32. {
  33. _starpu_mpi_early_request_hash = NULL;
  34. _starpu_mpi_early_request_hash_count = 0;
  35. }
  36. void _starpu_mpi_early_request_free()
  37. {
  38. free(_starpu_mpi_early_request_hash);
  39. }
  40. int _starpu_mpi_early_request_count()
  41. {
  42. return _starpu_mpi_early_request_hash_count;
  43. }
  44. void _starpu_mpi_early_request_check_termination()
  45. {
  46. STARPU_ASSERT_MSG(_starpu_mpi_early_request_count() == 0, "Number of early requests left is not zero");
  47. }
  48. struct _starpu_mpi_req* _starpu_mpi_early_request_dequeue(int data_tag, int source, MPI_Comm comm)
  49. {
  50. struct _starpu_mpi_node_tag node_tag;
  51. struct _starpu_mpi_req *found;
  52. struct _starpu_mpi_early_request_hashlist *hashlist;
  53. memset(&node_tag, 0, sizeof(struct _starpu_mpi_node_tag));
  54. node_tag.comm = comm;
  55. node_tag.rank = source;
  56. node_tag.data_tag = data_tag;
  57. _STARPU_MPI_DEBUG(100, "Looking for early_request with comm %p source %d tag %d\n", node_tag.comm, node_tag.rank, node_tag.data_tag);
  58. HASH_FIND(hh, _starpu_mpi_early_request_hash, &node_tag, sizeof(struct _starpu_mpi_node_tag), hashlist);
  59. if (hashlist == NULL)
  60. {
  61. found = NULL;
  62. }
  63. else
  64. {
  65. if (_starpu_mpi_req_list_empty(hashlist->list))
  66. {
  67. found = NULL;
  68. }
  69. else
  70. {
  71. found = _starpu_mpi_req_list_pop_front(hashlist->list);
  72. _starpu_mpi_early_request_hash_count --;
  73. }
  74. }
  75. _STARPU_MPI_DEBUG(100, "Found early_request %p with comm %p source %d tag %d\n", found, node_tag.comm, node_tag.rank, node_tag.data_tag);
  76. return found;
  77. }
  78. void _starpu_mpi_early_request_enqueue(struct _starpu_mpi_req *req)
  79. {
  80. _STARPU_MPI_DEBUG(100, "Adding request %p with comm %p source %d tag %d in the application request hashmap\n", req, req->node_tag.comm, req->node_tag.rank, req->node_tag.data_tag);
  81. struct _starpu_mpi_early_request_hashlist *hashlist;
  82. HASH_FIND(hh, _starpu_mpi_early_request_hash, &req->node_tag, sizeof(struct _starpu_mpi_node_tag), hashlist);
  83. if (hashlist == NULL)
  84. {
  85. hashlist = malloc(sizeof(struct _starpu_mpi_early_request_hashlist));
  86. hashlist->list = _starpu_mpi_req_list_new();
  87. hashlist->node_tag = req->node_tag;
  88. HASH_ADD(hh, _starpu_mpi_early_request_hash, node_tag, sizeof(hashlist->node_tag), hashlist);
  89. }
  90. _starpu_mpi_req_list_push_back(hashlist->list, req);
  91. _starpu_mpi_early_request_hash_count ++;
  92. }