insert_task_owner_data.c 3.3 KB

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