policy_selection2.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-2017 CNRS
  4. * Copyright (C) 2017 Inria
  5. * Copyright (C) 2015-2018 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu_mpi.h>
  19. #include "helper.h"
  20. void func_cpu(void *descr[], void *_args)
  21. {
  22. (void)_args;
  23. int *data0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  24. int *data1 = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  25. int *data2 = (int *)STARPU_VARIABLE_GET_PTR(descr[2]);
  26. *data1 += *data0;
  27. *data2 += *data0;
  28. }
  29. struct starpu_codelet mycodelet =
  30. {
  31. .cpu_funcs = {func_cpu},
  32. .nbuffers = 3,
  33. .modes = {STARPU_R, STARPU_W, STARPU_W},
  34. .model = &starpu_perfmodel_nop,
  35. };
  36. int main(int argc, char **argv)
  37. {
  38. int ret;
  39. int i;
  40. int rank, size;
  41. int data[3];
  42. starpu_data_handle_t handles[3];
  43. int mpi_init;
  44. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  45. (void)mpi_init;
  46. ret = starpu_mpi_init_conf(NULL, NULL, 0, MPI_COMM_WORLD, NULL);
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  48. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  49. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  50. if ((size < 3) || (starpu_cpu_worker_get_count() == 0))
  51. {
  52. if (rank == 0)
  53. {
  54. if (size < 3)
  55. FPRINTF(stderr, "We need at least 3 processes.\n");
  56. else
  57. FPRINTF(stderr, "We need at least 1 CPU worker.\n");
  58. }
  59. starpu_mpi_shutdown();
  60. if (!mpi_init)
  61. MPI_Finalize();
  62. return STARPU_TEST_SKIPPED;
  63. }
  64. data[0] = 12;
  65. starpu_variable_data_register(&handles[0], STARPU_MAIN_RAM, (uintptr_t)&data[0], sizeof(int));
  66. starpu_mpi_data_register(handles[0], 10, 0);
  67. data[1] = 12;
  68. starpu_variable_data_register(&handles[1], STARPU_MAIN_RAM, (uintptr_t)&data[1], sizeof(int));
  69. starpu_mpi_data_register(handles[1], 20, 1);
  70. data[2] = 12;
  71. starpu_variable_data_register(&handles[2], STARPU_MAIN_RAM, (uintptr_t)&data[2], sizeof(int));
  72. starpu_mpi_data_register(handles[2], 30, 2);
  73. starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  74. STARPU_R, handles[2], STARPU_W, handles[0], STARPU_W, handles[1],
  75. 0);
  76. for(i=0 ; i<2 ; i++) starpu_data_acquire(handles[i], STARPU_R);
  77. FPRINTF_MPI(stderr, "data[%d,%d,%d] = %d,%d,%d\n", 0, 1, 2, data[0], data[1], data[2]);
  78. for(i=0 ; i<2 ; i++) starpu_data_release(handles[i]);
  79. #ifndef STARPU_SIMGRID
  80. if (rank == 2)
  81. {
  82. STARPU_ASSERT_MSG(data[0] == 2*data[2] && data[1] == 2*data[2], "Computation incorrect. data[%d] (%d) != 2*data[%d] (%d) && data[%d] (%d) != 2*data[%d] (%d)\n",
  83. 0, data[0], 2, data[2], 1, data[1], 2, data[2]);
  84. }
  85. #endif
  86. for(i=0 ; i<2 ; i++) starpu_data_acquire(handles[i], STARPU_W);
  87. for(i=0 ; i<2 ; i++) data[i] = 12;
  88. for(i=0 ; i<2 ; i++) starpu_data_release(handles[i]);
  89. // Let StarPU choose the node
  90. starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  91. STARPU_R, handles[2], STARPU_W, handles[0], STARPU_W, handles[1],
  92. STARPU_EXECUTE_ON_NODE, 1,
  93. 0);
  94. for(i=0 ; i<2 ; i++) starpu_data_acquire(handles[i], STARPU_R);
  95. FPRINTF_MPI(stderr, "data[%d,%d,%d] = %d,%d,%d\n", 0, 1, 2, data[0], data[1], data[2]);
  96. for(i=0 ; i<2 ; i++) starpu_data_release(handles[i]);
  97. #ifndef STARPU_SIMGRID
  98. if (rank == 1)
  99. {
  100. STARPU_ASSERT_MSG(data[0] == 2*data[2] && data[1] == 2*data[2], "Computation incorrect. data[%d] (%d) != 2*data[%d] (%d) && data[%d] (%d) != 2*data[%d] (%d)\n",
  101. 0, data[0], 2, data[2], 1, data[1], 2, data[2]);
  102. }
  103. #endif
  104. for(i=0 ; i<3 ; i++) starpu_data_unregister(handles[i]);
  105. starpu_mpi_shutdown();
  106. if (!mpi_init)
  107. MPI_Finalize();
  108. return 0;
  109. }