starpu_mpi_early_request.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2014 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014 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 <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. static struct _starpu_mpi_req **_starpu_mpi_app_req_hashmap = NULL;
  24. static int _starpu_mpi_app_req_hashmap_count = 0;
  25. void _starpu_mpi_early_request_init(int world_size)
  26. {
  27. int k;
  28. _starpu_mpi_app_req_hashmap = malloc(world_size * sizeof(struct _starpu_mpi_req *));
  29. for(k=0 ; k<world_size ; k++) _starpu_mpi_app_req_hashmap[k] = NULL;
  30. }
  31. void _starpu_mpi_early_request_free()
  32. {
  33. free(_starpu_mpi_app_req_hashmap);
  34. }
  35. int _starpu_mpi_early_request_count()
  36. {
  37. return _starpu_mpi_app_req_hashmap_count;
  38. }
  39. void _starpu_mpi_early_request_check_termination()
  40. {
  41. STARPU_ASSERT_MSG(_starpu_mpi_early_request_count() == 0, "Number of receive requests left is not zero");
  42. }
  43. struct _starpu_mpi_req* _starpu_mpi_early_request_find(int mpi_tag, int source)
  44. {
  45. struct _starpu_mpi_req* req;
  46. HASH_FIND_INT(_starpu_mpi_app_req_hashmap[source], &mpi_tag, req);
  47. return req;
  48. }
  49. void _starpu_mpi_early_request_add(struct _starpu_mpi_req *req)
  50. {
  51. struct _starpu_mpi_req *test_req;
  52. test_req = _starpu_mpi_early_request_find(req->mpi_tag, req->srcdst);
  53. if (test_req == NULL)
  54. {
  55. HASH_ADD_INT(_starpu_mpi_app_req_hashmap[req->srcdst], mpi_tag, req);
  56. _starpu_mpi_app_req_hashmap_count ++;
  57. _STARPU_MPI_DEBUG(3, "Adding request %p with tag %d in the application request hashmap[%d]\n", req, req->mpi_tag, req->srcdst);
  58. }
  59. else
  60. {
  61. _STARPU_MPI_DEBUG(3, "[Error] request %p with tag %d already in the application request hashmap[%d]\n", req, req->mpi_tag, req->srcdst);
  62. int seq_const = starpu_data_get_sequential_consistency_flag(req->data_handle);
  63. if (seq_const && req->sequential_consistency)
  64. {
  65. STARPU_ASSERT_MSG(!test_req, "[Error] request %p with tag %d wanted to be added to the application request hashmap[%d], 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->mpi_tag, req->srcdst, test_req);
  66. }
  67. else
  68. {
  69. STARPU_ASSERT_MSG(!test_req, "[Error] request %p with tag %d wanted to be added to the application request hashmap[%d], 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->mpi_tag, req->srcdst, test_req);
  70. }
  71. }
  72. }
  73. void _starpu_mpi_early_request_delete(struct _starpu_mpi_req *req)
  74. {
  75. struct _starpu_mpi_req *test_req;
  76. test_req = _starpu_mpi_early_request_find(req->mpi_tag, req->srcdst);
  77. if (test_req != NULL)
  78. {
  79. HASH_DEL(_starpu_mpi_app_req_hashmap[req->srcdst], req);
  80. _starpu_mpi_app_req_hashmap_count --;
  81. _STARPU_MPI_DEBUG(3, "Deleting application request %p with tag %d from the application request hashmap[%d]\n", req, req->mpi_tag, req->srcdst);
  82. }
  83. else
  84. {
  85. _STARPU_MPI_DEBUG(3, "[Warning] request %p with tag %d is NOT in the application request hashmap[%d]\n", req, req->mpi_tag, req->srcdst);
  86. }
  87. }