insert_task_owner.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. void func_cpu(void *descr[], __attribute__ ((unused)) void *_args)
  19. {
  20. int *x = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  21. int *y = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  22. *x = *x + 1;
  23. *y = *y + 1;
  24. }
  25. starpu_codelet mycodelet = {
  26. .where = STARPU_CPU,
  27. .cpu_func = func_cpu,
  28. .nbuffers = 2
  29. };
  30. #define ACQUIRE_DATA \
  31. if (rank == 0) starpu_data_acquire(data_handlesx0, STARPU_R); \
  32. if (rank == 1) starpu_data_acquire(data_handlesx1, STARPU_R); \
  33. fprintf(stderr, "[%d] Values: %d %d\n", rank, x0, x1);
  34. #define RELEASE_DATA \
  35. if (rank == 0) starpu_data_release(data_handlesx0); \
  36. if (rank == 1) starpu_data_release(data_handlesx1); \
  37. #define CHECK_RESULT \
  38. if (rank == 0) assert(x0 == vx0[0] && x1 == vx1[0]); \
  39. if (rank == 1) assert(x0 == vx0[1] && x1 == vx1[1]);
  40. int main(int argc, char **argv)
  41. {
  42. int rank, size, err;
  43. int x0=0, x1=0, vx0[2] = {x0, x0}, vx1[2]={x1,x1};
  44. starpu_data_handle data_handlesx0;
  45. starpu_data_handle data_handlesx1;
  46. starpu_init(NULL);
  47. starpu_mpi_initialize_extended(1, &rank, &size);
  48. if (rank == 0) {
  49. starpu_variable_data_register(&data_handlesx0, 0, (uintptr_t)&x0, sizeof(x0));
  50. starpu_data_set_rank(data_handlesx0, rank);
  51. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(int));
  52. starpu_data_set_rank(data_handlesx1, 1);
  53. }
  54. else if (rank == 1) {
  55. starpu_variable_data_register(&data_handlesx1, 0, (uintptr_t)&x1, sizeof(x1));
  56. starpu_data_set_rank(data_handlesx1, rank);
  57. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(int));
  58. starpu_data_set_rank(data_handlesx0, 0);
  59. }
  60. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, 0);
  61. assert(err == 0);
  62. ACQUIRE_DATA;
  63. vx1[1]++;
  64. CHECK_RESULT;
  65. RELEASE_DATA;
  66. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handlesx0, STARPU_R, data_handlesx1, 0);
  67. assert(err == 0);
  68. ACQUIRE_DATA;
  69. vx0[0] ++;
  70. CHECK_RESULT;
  71. RELEASE_DATA;
  72. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, 0);
  73. assert(err == -EINVAL);
  74. ACQUIRE_DATA;
  75. CHECK_RESULT;
  76. RELEASE_DATA;
  77. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE, 1, 0);
  78. assert(err == 0);
  79. ACQUIRE_DATA;
  80. vx0[0] ++ ; vx1[1] ++;
  81. CHECK_RESULT;
  82. RELEASE_DATA;
  83. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1, STARPU_EXECUTE, 0, 0);
  84. assert(err == 0);
  85. ACQUIRE_DATA;
  86. vx0[0] ++ ; vx1[1] ++;
  87. CHECK_RESULT;
  88. RELEASE_DATA;
  89. /* Here the value specified by the property STARPU_EXECUTE is
  90. going to be ignored as the data model clearly specifies
  91. which task is going to execute the codelet */
  92. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_R, data_handlesx0, STARPU_W, data_handlesx1, STARPU_EXECUTE, 12, 0);
  93. assert(err == 0);
  94. ACQUIRE_DATA;
  95. vx1[1] ++;
  96. CHECK_RESULT;
  97. RELEASE_DATA;
  98. /* Here the value specified by the property STARPU_EXECUTE is
  99. going to be ignored as the data model clearly specifies
  100. which task is going to execute the codelet */
  101. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_W, data_handlesx0, STARPU_R, data_handlesx1, STARPU_EXECUTE, 11, 0);
  102. assert(err == 0);
  103. ACQUIRE_DATA;
  104. vx0[0] ++;
  105. CHECK_RESULT;
  106. RELEASE_DATA;
  107. starpu_task_wait_for_all();
  108. starpu_mpi_shutdown();
  109. starpu_shutdown();
  110. return 0;
  111. }