checkpoints.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. if (_me==0)
  45. return 1;
  46. else
  47. return 0;
  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_mpi_data_register(h, 56, 0);
  73. fprintf(stderr, "&h: %p, h:%p\n", &h, h);
  74. for (int i=0 ; i<ARRAY_SIZE ; i++)
  75. {
  76. starpu_variable_data_register(&h_array[i], STARPU_MAIN_RAM, (uintptr_t)&array[i], sizeof(int));
  77. starpu_mpi_data_register(h_array[i], 42+i, 1); //42 to 54
  78. }
  79. starpu_mpi_checkpoint_template_register(&cp_template1, 123486, 0,
  80. STARPU_VALUE, &val, sizeof(int), 84, backup_of,
  81. STARPU_R, h, 1,
  82. 0);
  83. FPRINTF(stderr, "registered!\n");
  84. _starpu_mpi_checkpoint_template_print(cp_template1);
  85. starpu_mpi_checkpoint_template_create(&cp_template2, 98765, 0);
  86. starpu_mpi_checkpoint_template_add_entry(&cp_template2, STARPU_R, h, 1);
  87. starpu_mpi_checkpoint_template_add_entry(&cp_template2, STARPU_VALUE, &val, sizeof(int), 84, backup_of);
  88. starpu_mpi_checkpoint_template_freeze(&cp_template2);
  89. FPRINTF(stderr, "registered 2!\n");
  90. _starpu_mpi_checkpoint_template_print(cp_template1);
  91. starpu_shutdown();
  92. return 0;
  93. }
  94. int test_checkpoint_submit(int argc, char* argv[])
  95. {
  96. int ret;
  97. starpu_data_handle_t handle0, handle1;
  98. starpu_mpi_checkpoint_template_t cp_template;
  99. int val0 = 0;
  100. int val1 = 0;
  101. int stage = 10;
  102. FPRINTF(stderr, "Go\n");
  103. ret = starpu_mpi_init_conf(&argc, &argv, 1, MPI_COMM_WORLD, NULL);
  104. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  105. starpu_mpi_comm_size(MPI_COMM_WORLD, &nb_nodes);
  106. starpu_mpi_comm_rank(MPI_COMM_WORLD, &me);
  107. stage+=me;
  108. FPRINTF_MPI(stderr, "Init ok - my rnk %d - size %d\n", me, nb_nodes);
  109. starpu_variable_data_register(&handle0, STARPU_MAIN_RAM, (uintptr_t)&val0, sizeof(int));
  110. starpu_mpi_data_register(handle0, 100, 0);
  111. starpu_variable_data_register(&handle1, STARPU_MAIN_RAM, (uintptr_t)&val1, sizeof(int));
  112. starpu_mpi_data_register(handle1, 200, 1);
  113. FPRINTF_MPI(stderr, "Registering\n");
  114. starpu_mpi_checkpoint_template_register(&cp_template, 321, 0,
  115. STARPU_R, handle0, 1,
  116. STARPU_R, handle1, 0,
  117. STARPU_VALUE, &stage, sizeof(int), 300, &backup_of,
  118. STARPU_VALUE, &stage, sizeof(int), 301, &backup_of,
  119. STARPU_VALUE, &stage, sizeof(int), 302, &backup_of,
  120. 0);
  121. FPRINTF_MPI(stderr, "Registered\n");
  122. _starpu_mpi_checkpoint_template_print(cp_template);
  123. switch (me)
  124. {
  125. case 0:
  126. val0 = 42;
  127. break;
  128. case 1:
  129. val1 = 1000;
  130. break;
  131. }
  132. FPRINTF_MPI(stderr, "Submitting\n");
  133. starpu_mpi_submit_checkpoint_template(cp_template,0);
  134. FPRINTF_MPI(stderr, "Submitted\n");
  135. usleep(150000);
  136. stage++;
  137. fprintf(stderr, "\n\n");
  138. usleep(150000);
  139. if (me==0)
  140. {
  141. starpu_data_acquire(handle0, STARPU_RW);
  142. val0*=2;
  143. starpu_data_release(handle0);
  144. }
  145. if (me==1)
  146. {
  147. starpu_data_acquire(handle1, STARPU_RW);
  148. val1*=2;
  149. starpu_data_release(handle1);
  150. }
  151. FPRINTF_MPI(stderr, "Submitting\n");
  152. starpu_mpi_submit_checkpoint_template(cp_template, 0);
  153. FPRINTF_MPI(stderr, "Submitted\n");
  154. usleep(150000);
  155. fprintf(stderr, "\n\n");
  156. starpu_mpi_wait_for_all(MPI_COMM_WORLD);
  157. FPRINTF_MPI(stderr, "Bye!\n");
  158. starpu_mpi_shutdown();
  159. return 0;
  160. }
  161. int main(int argc, char* argv[])
  162. {
  163. //pseudotest_checkpoint_template_register(argc, argv);
  164. test_checkpoint_submit(argc, argv);
  165. return 0;
  166. }