starpu_mpi_early_request.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_req *_starpu_mpi_early_request_hash;
  24. int _starpu_mpi_early_request_hash_count;
  25. void _starpu_mpi_early_request_init()
  26. {
  27. _starpu_mpi_early_request_hash = NULL;
  28. _starpu_mpi_early_request_hash_count = 0;
  29. }
  30. void _starpu_mpi_early_request_free()
  31. {
  32. free(_starpu_mpi_early_request_hash);
  33. }
  34. int _starpu_mpi_early_request_count()
  35. {
  36. return _starpu_mpi_early_request_hash_count;
  37. }
  38. void _starpu_mpi_early_request_check_termination()
  39. {
  40. STARPU_ASSERT_MSG(_starpu_mpi_early_request_count() == 0, "Number of early requests left is not zero");
  41. }
  42. struct _starpu_mpi_req* _starpu_mpi_early_request_find(int data_tag, int source, MPI_Comm comm)
  43. {
  44. struct _starpu_mpi_node_tag node_tag;
  45. struct _starpu_mpi_req *found;
  46. memset(&node_tag, 0, sizeof(struct _starpu_mpi_node_tag));
  47. node_tag.comm = comm;
  48. node_tag.rank = source;
  49. node_tag.data_tag = data_tag;
  50. HASH_FIND(hh, _starpu_mpi_early_request_hash, &node_tag, sizeof(struct _starpu_mpi_node_tag), found);
  51. return found;
  52. }
  53. void _starpu_mpi_early_request_add(struct _starpu_mpi_req *req)
  54. {
  55. struct _starpu_mpi_req *test_req;
  56. test_req = _starpu_mpi_early_request_find(req->node_tag.data_tag, req->node_tag.rank, req->node_tag.comm);
  57. if (test_req == NULL)
  58. {
  59. HASH_ADD(hh, _starpu_mpi_early_request_hash, node_tag, sizeof(req->node_tag), req);
  60. _starpu_mpi_early_request_hash_count ++;
  61. _STARPU_MPI_DEBUG(3, "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);
  62. }
  63. else
  64. {
  65. _STARPU_MPI_DEBUG(3, "[Error] request %p with comm %p source %d tag %d already in the application request hashmap\n", req, req->node_tag.comm, req->node_tag.rank, req->node_tag.data_tag);
  66. int seq_const = starpu_data_get_sequential_consistency_flag(req->data_handle);
  67. if (seq_const && req->sequential_consistency)
  68. {
  69. STARPU_ASSERT_MSG(!test_req, "[Error] request %p with comm %p source %d tag %d wanted to be added to the application request hashmap, while another request %p with the same tag is already in it. \n Sequential consistency is activated : this is not supported by StarPU.", req, req->node_tag.comm, req->node_tag.rank, req->node_tag.data_tag, test_req);
  70. }
  71. else
  72. {
  73. STARPU_ASSERT_MSG(!test_req, "[Error] request %p with comm %p source %d tag %d wanted to be added to the application request hashmap, while another request %p with the same tag is already in it. \n Sequential consistency isn't activated for this handle : you should want to add dependencies between requests for which the sequential consistency is deactivated.", req, req->node_tag.comm, req->node_tag.rank, req->node_tag.data_tag, test_req);
  74. }
  75. }
  76. }
  77. void _starpu_mpi_early_request_delete(struct _starpu_mpi_req *req)
  78. {
  79. struct _starpu_mpi_req *test_req;
  80. test_req = _starpu_mpi_early_request_find(req->node_tag.data_tag, req->node_tag.rank, req->node_tag.comm);
  81. if (test_req != NULL)
  82. {
  83. HASH_DEL(_starpu_mpi_early_request_hash, req);
  84. _starpu_mpi_early_request_hash_count --;
  85. _STARPU_MPI_DEBUG(3, "Deleting application request %p with comm %p source %d tag %d from the application request hashmap\n", req, req->node_tag.comm, req->node_tag.rank, req->node_tag.data_tag);
  86. }
  87. else
  88. {
  89. _STARPU_MPI_DEBUG(3, "[Warning] request %p with comm %p source %d tag %d is NOT in the application request hashmap\n", req, req->node_tag.comm, req->node_tag.rank, req->node_tag.data_tag);
  90. }
  91. }