checkpoints.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013-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. #include <starpu_mpi.h>
  17. #include "helper.h"
  18. #include <mpi_failure_tolerance/starpu_mpi_checkpoint_template.h>
  19. #define ARRAY_SIZE 12
  20. #define STARPU_MPI_INIT(void) do{struct starpu_conf conf; int ret; \
  21. starpu_conf_init(&conf); \
  22. conf.nmic = 0; \
  23. conf.nmpi_ms = 0; \
  24. ret = starpu_init(NULL); \
  25. if (STARPU_UNLIKELY(ret == -ENODEV)) \
  26. { \
  27. return 77; \
  28. } \
  29. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); \
  30. if (starpu_cpu_worker_get_count() < 1) \
  31. { \
  32. FPRINTF(stderr, "This application requires at least 1 cpu worker\n"); \
  33. starpu_shutdown(); \
  34. return 77; \
  35. } \
  36. starpu_mpi_init(&argc, &argv, 1); \
  37. starpu_mpi_comm_size(MPI_COMM_WORLD, &nb_nodes); \
  38. starpu_mpi_comm_rank(MPI_COMM_WORLD, &me); \
  39. }while(0)
  40. int nb_nodes;
  41. int me;
  42. int backup_of(int _me)
  43. {
  44. return (_me+1)%nb_nodes;
  45. }
  46. int backuped_by(int _me)
  47. {
  48. return (_me-1)%nb_nodes;
  49. }
  50. int pseudotest_checkpoint_template_register(int argc, char* argv[])
  51. {
  52. starpu_data_handle_t h;
  53. starpu_data_handle_t h_array[ARRAY_SIZE];
  54. starpu_mpi_checkpoint_template_t cp_template1, cp_template2;
  55. int val = 42;
  56. int val2 = 1234;
  57. int array[ARRAY_SIZE];
  58. int ret;
  59. //init array
  60. for (int i=0 ; i<ARRAY_SIZE ; i++)
  61. {
  62. array[i] = i*1111+42;
  63. }
  64. for (int i=0 ; i<ARRAY_SIZE ; i++)
  65. {
  66. h_array[i] = NULL;
  67. }
  68. FPRINTF(stderr, "Go\n");
  69. STARPU_MPI_INIT();
  70. FPRINTF_MPI(stderr, "Init ok - my rnk %d - size %d\n", me, nb_nodes);
  71. starpu_variable_data_register(&h, STARPU_MAIN_RAM, (uintptr_t)&val2, sizeof(int));
  72. starpu_vector_data_register(h_array, STARPU_MAIN_RAM, (uintptr_t)array, ARRAY_SIZE, sizeof(int));
  73. for (int i=0 ; i<ARRAY_SIZE ; i++)
  74. {
  75. starpu_variable_data_register(&h_array[i], STARPU_MAIN_RAM, (uintptr_t)&array[i], sizeof(int));
  76. }
  77. starpu_mpi_checkpoint_template_register(&cp_template1, 123486,
  78. STARPU_VALUE, &val, sizeof(int), 84, backup_of,
  79. STARPU_R, &h, 1,
  80. 0);
  81. FPRINTF(stderr, "registered!\n");
  82. _starpu_mpi_checkpoint_template_print(cp_template1);
  83. starpu_mpi_checkpoint_template_create(&cp_template2, 98765);
  84. starpu_mpi_checkpoint_template_add_entry(&cp_template2, STARPU_R, &h, 1);
  85. starpu_mpi_checkpoint_template_add_entry(&cp_template2, STARPU_VALUE, &val, sizeof(int), 84, backup_of);
  86. starpu_mpi_checkpoint_template_freeze(&cp_template2);
  87. FPRINTF(stderr, "registered 2!\n");
  88. _starpu_mpi_checkpoint_template_print(cp_template1);
  89. starpu_shutdown();
  90. return 0;
  91. }
  92. int test_checkpoint_submit(int argc, char* argv[])
  93. {
  94. starpu_data_handle_t handle0, handle1;
  95. starpu_mpi_checkpoint_template_t cp_template;
  96. int val0 = 0;
  97. int val1 = 0;
  98. FPRINTF(stderr, "Go\n");
  99. STARPU_MPI_INIT();
  100. FPRINTF_MPI(stderr, "Init ok - my rnk %d - size %d\n", me, nb_nodes);
  101. starpu_variable_data_register(&handle0, STARPU_MAIN_RAM, (uintptr_t)&val0, sizeof(int));
  102. starpu_variable_data_register(&handle1, STARPU_MAIN_RAM, (uintptr_t)&val1, sizeof(int));
  103. starpu_mpi_data_register(handle0, 100, 0);
  104. starpu_mpi_data_register(handle1, 200, 1);
  105. starpu_mpi_checkpoint_template_register(&cp_template, 321,
  106. STARPU_R, handle0, 1,
  107. STARPU_R, handle1, 0,
  108. 0);
  109. switch (me)
  110. {
  111. case 0:
  112. val0 = 42;
  113. break;
  114. case 1:
  115. val1 = 1000;
  116. break;
  117. default:
  118. STARPU_ABORT_MSG("Test code with only two node communicator.\n");
  119. break;
  120. }
  121. FPRINTF_MPI(stderr, "Submitting\n");
  122. starpu_mpi_submit_checkpoint_template(cp_template);
  123. FPRINTF_MPI(stderr, "Submitted\n");
  124. sleep(10);
  125. FPRINTF_MPI(stderr, "Bye!\n");
  126. starpu_shutdown();
  127. return 0;
  128. }
  129. int main(int argc, char* argv[])
  130. {
  131. pseudotest_checkpoint_template_register(argc, argv);
  132. //test_checkpoint_submit(argc, argv);
  133. return 0;
  134. }