insert_task_owner.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Centre National de la Recherche Scientifique
  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 <math.h>
  18. #include "helper.h"
  19. void func_cpu(void *descr[], __attribute__ ((unused)) void *_args)
  20. {
  21. int *x = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. int *y = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  23. *x = *x + 1;
  24. *y = *y + 1;
  25. }
  26. struct starpu_codelet mycodelet =
  27. {
  28. .where = STARPU_CPU,
  29. .cpu_func = func_cpu,
  30. .nbuffers = 2
  31. };
  32. #define ACQUIRE_DATA \
  33. if (rank == 0) starpu_data_acquire(data_handlesx0, STARPU_R); \
  34. if (rank == 1) starpu_data_acquire(data_handlesx1, STARPU_R); \
  35. FPRINTF(stderr, "[%d] Values: %d %d\n", rank, x0, x1);
  36. #define RELEASE_DATA \
  37. if (rank == 0) starpu_data_release(data_handlesx0); \
  38. if (rank == 1) starpu_data_release(data_handlesx1); \
  39. #define CHECK_RESULT \
  40. if (rank == 0) assert(x0 == vx0[0] && x1 == vx1[0]); \
  41. if (rank == 1) assert(x0 == vx0[1] && x1 == vx1[1]);
  42. int main(int argc, char **argv)
  43. {
  44. int ret, rank, size, err;
  45. int x0=0, x1=0, vx0[2] = {x0, x0}, vx1[2]={x1,x1};
  46. starpu_data_handle_t data_handlesx0;
  47. starpu_data_handle_t data_handlesx1;
  48. ret = starpu_init(NULL);
  49. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  50. ret = starpu_mpi_initialize_extended(&rank, &size);
  51. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_initialize_extended");
  52. if (size != 2)
  53. {
  54. if (rank == 0) FPRINTF(stderr, "We need exactly 2 processes.\n");
  55. starpu_mpi_shutdown();
  56. starpu_shutdown();
  57. return STARPU_TEST_SKIPPED;
  58. }
  59. if (rank == 0)
  60. {
  61. starpu_variable_data_register(&data_handlesx0, 0, (uintptr_t)&x0, sizeof(x0));
  62. starpu_data_set_rank(data_handlesx0, rank);
  63. starpu_data_set_tag(data_handlesx0, 0);
  64. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(int));
  65. starpu_data_set_rank(data_handlesx1, 1);
  66. starpu_data_set_tag(data_handlesx1, 1);
  67. }
  68. else if (rank == 1)
  69. {
  70. starpu_variable_data_register(&data_handlesx1, 0, (uintptr_t)&x1, sizeof(x1));
  71. starpu_data_set_rank(data_handlesx1, rank);
  72. starpu_data_set_tag(data_handlesx1, 1);
  73. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(int));
  74. starpu_data_set_rank(data_handlesx0, 0);
  75. starpu_data_set_tag(data_handlesx0, 0);
  76. }
  77. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, 0);
  78. assert(err == 0);
  79. ACQUIRE_DATA;
  80. vx1[1]++;
  81. CHECK_RESULT;
  82. RELEASE_DATA;
  83. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handlesx0, STARPU_R, data_handlesx1, 0);
  84. assert(err == 0);
  85. ACQUIRE_DATA;
  86. vx0[0] ++;
  87. CHECK_RESULT;
  88. RELEASE_DATA;
  89. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, 0);
  90. assert(err == -EINVAL);
  91. ACQUIRE_DATA;
  92. CHECK_RESULT;
  93. RELEASE_DATA;
  94. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, 1, 0);
  95. assert(err == 0);
  96. ACQUIRE_DATA;
  97. vx0[0] ++ ; vx1[1] ++;
  98. CHECK_RESULT;
  99. RELEASE_DATA;
  100. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE_ON_NODE, 0, 0);
  101. assert(err == 0);
  102. ACQUIRE_DATA;
  103. vx0[0] ++ ; vx1[1] ++;
  104. CHECK_RESULT;
  105. RELEASE_DATA;
  106. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  107. going to be ignored as the data model clearly specifies
  108. which task is going to execute the codelet */
  109. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, STARPU_EXECUTE_ON_NODE, 12, 0);
  110. assert(err == 0);
  111. ACQUIRE_DATA;
  112. vx1[1] ++;
  113. CHECK_RESULT;
  114. RELEASE_DATA;
  115. /* Here the value specified by the property STARPU_EXECUTE_ON_NODE is
  116. going to be ignored as the data model clearly specifies
  117. which task is going to execute the codelet */
  118. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_W, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE_ON_NODE, 11, 0);
  119. assert(err == 0);
  120. ACQUIRE_DATA;
  121. vx0[0] ++;
  122. CHECK_RESULT;
  123. RELEASE_DATA;
  124. starpu_task_wait_for_all();
  125. starpu_mpi_shutdown();
  126. starpu_shutdown();
  127. return 0;
  128. }