checkpoints.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 <starpu_mpi_checkpoint.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_template;
  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. STARPU_MPI_INIT();
  69. starpu_variable_data_register(&h, STARPU_MAIN_RAM, (uintptr_t)&val2, sizeof(int));
  70. starpu_vector_data_register(h_array, STARPU_MAIN_RAM, (uintptr_t)array, ARRAY_SIZE, sizeof(int));
  71. for (int i=0 ; i<ARRAY_SIZE ; i++)
  72. {
  73. starpu_variable_data_register(&h_array[i], STARPU_MAIN_RAM, (uintptr_t)&array[i], sizeof(int));
  74. }
  75. starpu_mpi_checkpoint_template_register(&cp_template, 123486,
  76. STARPU_VALUE, &val, sizeof(int), backup_of(me), backuped_by(me),
  77. STARPU_DATA_ARRAY, h_array, ARRAY_SIZE, 1,
  78. STARPU_R, &h, 1,
  79. 0);
  80. FPRINTF(stderr, "registered!\n");
  81. _starpu_mpi_checkpoint_template_print(cp_template);
  82. starpu_shutdown();
  83. return 0;
  84. }
  85. int test_checkpoint_submit(int argc, char* argv[])
  86. {
  87. starpu_data_handle_t handle0, handle1;
  88. starpu_mpi_checkpoint_template_t cp_template;
  89. int val0 = 0;
  90. int val1 = 0;
  91. FPRINTF(stderr, "Go\n");
  92. STARPU_MPI_INIT();
  93. FPRINTF_MPI(stderr, "Init ok - my rnk %d - size %d\n", me, nb_nodes);
  94. starpu_variable_data_register(&handle0, STARPU_MAIN_RAM, (uintptr_t)&val0, sizeof(int));
  95. starpu_variable_data_register(&handle1, STARPU_MAIN_RAM, (uintptr_t)&val1, sizeof(int));
  96. starpu_mpi_data_register(handle0, 100, 0);
  97. starpu_mpi_data_register(handle1, 200, 1);
  98. starpu_mpi_checkpoint_template_register(&cp_template, 321,
  99. STARPU_R, &handle0, 1,
  100. STARPU_R, &handle1, 0,
  101. 0);
  102. switch (me)
  103. {
  104. case 0:
  105. val0 = 42;
  106. break;
  107. case 1:
  108. val1 = 1000;
  109. break;
  110. default:
  111. STARPU_ABORT_MSG("Test code with only two node communicator.\n");
  112. break;
  113. }
  114. FPRINTF_MPI(stderr, "Submitting\n");
  115. starpu_mpi_checkpoint_template_submit(cp_template);
  116. FPRINTF_MPI(stderr, "Submitted\n");
  117. sleep(10);
  118. FPRINTF_MPI(stderr, "Bye!\n");
  119. starpu_shutdown();
  120. return 0;
  121. }
  122. int main(int argc, char* argv[])
  123. {
  124. //pseudotest_checkpoint_template_register(argc, argv);
  125. test_checkpoint_submit(argc, argv);
  126. return 0;
  127. }