policy_selection2.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-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. void func_cpu(void *descr[], void *_args)
  19. {
  20. (void)_args;
  21. int *data0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. int *data1 = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  23. int *data2 = (int *)STARPU_VARIABLE_GET_PTR(descr[2]);
  24. *data1 = *data0;
  25. *data2 = *data0;
  26. }
  27. struct starpu_codelet mycodelet =
  28. {
  29. .cpu_funcs = {func_cpu},
  30. .nbuffers = 3,
  31. .modes = {STARPU_R, STARPU_W, STARPU_W},
  32. .model = &starpu_perfmodel_nop,
  33. };
  34. int main(int argc, char **argv)
  35. {
  36. int ret;
  37. int i;
  38. int rank, size;
  39. int data[3];
  40. starpu_data_handle_t handles[3];
  41. int mpi_init;
  42. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  43. (void)mpi_init;
  44. ret = starpu_mpi_init_conf(NULL, NULL, 0, MPI_COMM_WORLD, NULL);
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  46. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  47. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  48. if ((size < 3) || (starpu_cpu_worker_get_count() == 0))
  49. {
  50. if (rank == 0)
  51. {
  52. if (size < 3)
  53. FPRINTF(stderr, "We need at least 3 processes.\n");
  54. else
  55. FPRINTF(stderr, "We need at least 1 CPU worker.\n");
  56. }
  57. starpu_mpi_shutdown();
  58. if (!mpi_init)
  59. MPI_Finalize();
  60. return STARPU_TEST_SKIPPED;
  61. }
  62. data[0] = 42;
  63. starpu_variable_data_register(&handles[0], STARPU_MAIN_RAM, (uintptr_t)&data[0], sizeof(int));
  64. starpu_mpi_data_register(handles[0], 10, 0);
  65. data[1] = 42;
  66. starpu_variable_data_register(&handles[1], STARPU_MAIN_RAM, (uintptr_t)&data[1], sizeof(int));
  67. starpu_mpi_data_register(handles[1], 20, 1);
  68. data[2] = 12;
  69. starpu_variable_data_register(&handles[2], STARPU_MAIN_RAM, (uintptr_t)&data[2], sizeof(int));
  70. starpu_mpi_data_register(handles[2], 30, 2);
  71. starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  72. STARPU_R, handles[2], STARPU_W, handles[0], STARPU_W, handles[1],
  73. 0);
  74. for(i=0 ; i<2 ; i++) starpu_data_acquire(handles[i], STARPU_R);
  75. FPRINTF_MPI(stderr, "data[%d,%d,%d] = %d,%d,%d\n", 0, 1, 2, data[0], data[1], data[2]);
  76. for(i=0 ; i<2 ; i++) starpu_data_release(handles[i]);
  77. #ifndef STARPU_SIMGRID
  78. if (rank == 0)
  79. {
  80. STARPU_ASSERT_MSG(data[0] == data[2] && data[1] == data[2], "Computation incorrect. data[%d] (%d) != data[%d] (%d) && data[%d] (%d) != data[%d] (%d)\n",
  81. 0, data[0], 2, data[2], 1, data[1], 2, data[2]);
  82. }
  83. #endif
  84. for(i=0 ; i<2 ; i++) starpu_data_acquire(handles[i], STARPU_W);
  85. for(i=0 ; i<2 ; i++) data[i] = 12;
  86. for(i=0 ; i<2 ; i++) starpu_data_release(handles[i]);
  87. // Let StarPU choose the node
  88. starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  89. STARPU_R, handles[2], STARPU_W, handles[0], STARPU_W, handles[1],
  90. STARPU_EXECUTE_ON_NODE, 1,
  91. 0);
  92. for(i=0 ; i<2 ; i++) starpu_data_acquire(handles[i], STARPU_R);
  93. FPRINTF_MPI(stderr, "data[%d,%d,%d] = %d,%d,%d\n", 0, 1, 2, data[0], data[1], data[2]);
  94. for(i=0 ; i<2 ; i++) starpu_data_release(handles[i]);
  95. #ifndef STARPU_SIMGRID
  96. if (rank == 1)
  97. {
  98. STARPU_ASSERT_MSG(data[0] == data[2] && data[1] == data[2], "Computation incorrect. data[%d] (%d) != data[%d] (%d) && data[%d] (%d) != data[%d] (%d)\n",
  99. 0, data[0], 2, data[2], 1, data[1], 2, data[2]);
  100. }
  101. #endif
  102. for(i=0 ; i<3 ; i++) starpu_data_unregister(handles[i]);
  103. starpu_mpi_shutdown();
  104. if (!mpi_init)
  105. MPI_Finalize();
  106. return 0;
  107. }