simgrid_cpp.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016-2017 CNRS
  4. * Copyright (C) 2012-2018 Université de Bordeaux
  5. * Copyright (C) 2016-2017 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include <core/simgrid.h>
  20. #include <common/config.h>
  21. #ifdef STARPU_SIMGRID
  22. #ifdef STARPU_HAVE_SIMGRID_MSG_H
  23. #include <simgrid/msg.h>
  24. #else
  25. #include <msg/msg.h>
  26. #endif
  27. #include <simgrid/simix.h>
  28. #ifdef STARPU_HAVE_SIMGRID_HOST_H
  29. #include <simgrid/host.h>
  30. #endif
  31. /* thread_create function which implements inheritence of MPI privatization */
  32. /* See https://github.com/simgrid/simgrid/issues/139 */
  33. typedef struct
  34. {
  35. void_f_pvoid_t code;
  36. void *userparam;
  37. void *father_data;
  38. } thread_data_t;
  39. static int _starpu_simgrid_xbt_thread_create_wrapper(int argc STARPU_ATTRIBUTE_UNUSED, char *argv[] STARPU_ATTRIBUTE_UNUSED)
  40. {
  41. /* FIXME: Ugly work-around for bug in simgrid: the MPI context is not properly set at MSG process startup */
  42. MSG_process_sleep(0.000001);
  43. #ifdef HAVE_SMX_ACTOR_T
  44. smx_actor_t
  45. #else
  46. smx_process_t
  47. #endif
  48. self = SIMIX_process_self();
  49. #if SIMGRID_VERSION < 31300
  50. thread_data_t *t = (thread_data_t *) SIMIX_process_self_get_data(self);
  51. #else
  52. thread_data_t *t = (thread_data_t *) SIMIX_process_self_get_data();
  53. #endif
  54. simcall_process_set_data(self, t->father_data);
  55. t->code(t->userparam);
  56. simcall_process_set_data(self, NULL);
  57. free(t);
  58. return 0;
  59. }
  60. void _starpu_simgrid_xbt_thread_create(const char *name, void_f_pvoid_t code, void *param)
  61. {
  62. #if defined(HAVE_SIMCALL_PROCESS_CREATE) || defined(simcall_process_create)
  63. #ifdef HAVE_SMX_ACTOR_T
  64. smx_actor_t process STARPU_ATTRIBUTE_UNUSED;
  65. #else
  66. smx_process_t process STARPU_ATTRIBUTE_UNUSED;
  67. #endif
  68. thread_data_t *res = (thread_data_t *) malloc(sizeof(thread_data_t));
  69. res->userparam = param;
  70. res->code = code;
  71. #if SIMGRID_VERSION < 31300
  72. res->father_data = SIMIX_process_self_get_data(SIMIX_process_self());
  73. #else
  74. res->father_data = SIMIX_process_self_get_data();
  75. #endif
  76. #if SIMGRID_VERSION < 31200
  77. simcall_process_create(&process,
  78. #else
  79. process = simcall_process_create(
  80. #endif
  81. name,
  82. _starpu_simgrid_xbt_thread_create_wrapper, res,
  83. #if SIMGRID_VERSION < 31400
  84. SIMIX_host_self_get_name(),
  85. #else
  86. # if defined(HAVE_SG_HOST_SELF) || defined(sg_host_self)
  87. sg_host_self(),
  88. # else
  89. SIMIX_host_self(),
  90. # endif
  91. #endif
  92. #if SIMGRID_VERSION < 31500
  93. -1.0,
  94. #endif
  95. 0, NULL,
  96. /*props */ NULL
  97. #if SIMGRID_VERSION < 31500
  98. , 0
  99. #endif
  100. );
  101. #else
  102. STARPU_ABORT_MSG("Can't run StarPU-Simgrid-MPI with a Simgrid version which does not provide simcall_process_create and does not fix https://github.com/simgrid/simgrid/issues/139 , sorry.");
  103. #endif
  104. }
  105. #endif