starpu_mpi_checkpoint.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef FT_STARPU_STARPU_MPI_CHECKPOINT_H
  17. #define FT_STARPU_STARPU_MPI_CHECKPOINT_H
  18. #include <starpu_mpi.h>
  19. #include <common/list.h>
  20. #include "starpu_mpi_private.h"
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. LIST_TYPE(_starpu_mpi_checkpoint_template_item,
  26. int type;
  27. void* ptr;
  28. int count;
  29. int backup_rank;
  30. int backup_of;
  31. );
  32. struct _starpu_mpi_checkpoint_template{
  33. struct _starpu_mpi_checkpoint_template_item_list list;
  34. int size;
  35. int cp_template_id;
  36. int pending;
  37. int frozen;
  38. starpu_pthread_mutex_t mutex;
  39. starpu_sem_t completion_sem;
  40. };
  41. static inline struct _starpu_mpi_checkpoint_template_item* _starpu_mpi_checkpoint_template_item_create(int type, void* ptr, int count, int backup_rank, int backup_of)
  42. {
  43. struct _starpu_mpi_checkpoint_template_item* item;
  44. _STARPU_MPI_CALLOC(item, 1, sizeof(struct _starpu_mpi_checkpoint_template_item));
  45. item->type = type;
  46. item->ptr = ptr;
  47. item->count = count;
  48. item->backup_rank = backup_rank;
  49. item->backup_of = backup_of;
  50. return item;
  51. }
  52. static inline starpu_mpi_checkpoint_template_t _starpu_mpi_checkpoint_template_new(int cp_id)
  53. {
  54. starpu_mpi_checkpoint_template_t _cp_template;
  55. _STARPU_MPI_CALLOC(_cp_template, 1, sizeof(struct _starpu_mpi_checkpoint_template));
  56. _cp_template->cp_template_id = cp_id;
  57. starpu_pthread_mutex_init(&_cp_template->mutex, NULL);
  58. return _cp_template;
  59. }
  60. static inline int _starpu_mpi_checkpoint_template_add_data(starpu_mpi_checkpoint_template_t cp_template, int type, void* ptr, int count, int backup_rank, int backup_of)
  61. {
  62. STARPU_ASSERT_MSG(!cp_template->frozen, "It is not possible to modify registered checkpoint template.\n");
  63. struct _starpu_mpi_checkpoint_template_item* item;
  64. item = _starpu_mpi_checkpoint_template_item_create(type, ptr, count, backup_rank, backup_of);
  65. _starpu_mpi_checkpoint_template_item_list_push_back(&cp_template->list, item);
  66. return 0;
  67. }
  68. static inline int _starpu_mpi_checkpoint_template_freeze(starpu_mpi_checkpoint_template_t _cp_template)
  69. {
  70. _cp_template->frozen = 1;
  71. _cp_template->size = _starpu_mpi_checkpoint_template_item_list_size(&_cp_template->list);
  72. starpu_sem_init(&_cp_template->completion_sem, 0, _cp_template->size-1);
  73. return _cp_template->size;
  74. }
  75. static inline struct _starpu_mpi_checkpoint_template_item* _starpu_mpi_checkpoint_template_get_first_data(starpu_mpi_checkpoint_template_t template)
  76. {
  77. return _starpu_mpi_checkpoint_template_item_list_front(&template->list);
  78. }
  79. static inline struct _starpu_mpi_checkpoint_template_item* _starpu_mpi_checkpoint_template_get_next_data(starpu_mpi_checkpoint_template_t template STARPU_ATTRIBUTE_UNUSED, struct _starpu_mpi_checkpoint_template_item* ref_data)
  80. {
  81. return _starpu_mpi_checkpoint_template_item_list_next(ref_data);
  82. }
  83. static inline struct _starpu_mpi_checkpoint_template_item* _starpu_mpi_checkpoint_template_end(starpu_mpi_checkpoint_template_t template STARPU_ATTRIBUTE_UNUSED)
  84. {
  85. return NULL;
  86. }
  87. int _starpu_mpi_checkpoint_turn_on(void);
  88. // For test purpose
  89. int _starpu_mpi_checkpoint_template_print(starpu_mpi_checkpoint_template_t cp_template);
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #endif //FT_STARPU_STARPU_MPI_CHECKPOINT_H