insert_task_owner_data.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013, 2014 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[], STARPU_ATTRIBUTE_UNUSED void *_args)
  20. {
  21. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. int *x1 = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  23. *x0 += 1;
  24. *x1 *= *x1;
  25. }
  26. struct starpu_codelet mycodelet =
  27. {
  28. .cpu_funcs = {func_cpu},
  29. .nbuffers = 2,
  30. .modes = {STARPU_RW, STARPU_RW}
  31. };
  32. int main(int argc, char **argv)
  33. {
  34. int rank, size, err;
  35. int x[2];
  36. int ret, i;
  37. starpu_data_handle_t data_handles[2];
  38. int values[2];
  39. ret = starpu_init(NULL);
  40. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  41. ret = starpu_mpi_init(&argc, &argv, 1);
  42. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  43. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  44. MPI_Comm_size(MPI_COMM_WORLD, &size);
  45. if (rank == 0)
  46. {
  47. x[0] = 11;
  48. starpu_variable_data_register(&data_handles[0], STARPU_MAIN_RAM, (uintptr_t)&x[0], sizeof(x[0]));
  49. starpu_variable_data_register(&data_handles[1], -1, (uintptr_t)NULL, sizeof(x[1]));
  50. }
  51. else if (rank == 1)
  52. {
  53. x[1] = 12;
  54. starpu_variable_data_register(&data_handles[0], -1, (uintptr_t)NULL, sizeof(x[0]));
  55. starpu_variable_data_register(&data_handles[1], STARPU_MAIN_RAM, (uintptr_t)&x[1], sizeof(x[1]));
  56. }
  57. else
  58. {
  59. starpu_variable_data_register(&data_handles[0], -1, (uintptr_t)NULL, sizeof(x[0]));
  60. starpu_variable_data_register(&data_handles[1], -1, (uintptr_t)NULL, sizeof(x[1]));
  61. }
  62. starpu_mpi_data_register(data_handles[0], 0, 0);
  63. starpu_mpi_data_register(data_handles[1], 1, 1);
  64. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  65. STARPU_RW, data_handles[0], STARPU_RW, data_handles[1],
  66. STARPU_EXECUTE_ON_DATA, data_handles[1],
  67. 0);
  68. assert(err == 0);
  69. starpu_task_wait_for_all();
  70. for(i=0 ; i<2 ; i++)
  71. {
  72. starpu_mpi_get_data_on_node_detached(MPI_COMM_WORLD, data_handles[i], 0, NULL, NULL);
  73. if (rank == 0)
  74. {
  75. starpu_data_acquire(data_handles[i], STARPU_R);
  76. values[i] = *((int *)starpu_data_get_local_ptr(data_handles[i]));
  77. starpu_data_release(data_handles[i]); }
  78. }
  79. ret = 0;
  80. if (rank == 0)
  81. {
  82. FPRINTF(stderr, "[%d][local ptr] VALUES: %d %d\n", rank, values[0], values[1]);
  83. if (values[0] != 12 || values[1] != 144)
  84. {
  85. ret = EXIT_FAILURE;
  86. }
  87. }
  88. starpu_data_unregister(data_handles[0]);
  89. starpu_data_unregister(data_handles[1]);
  90. starpu_mpi_shutdown();
  91. starpu_shutdown();
  92. return ret;
  93. }