insert_task_owner_data.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013, 2014, 2016, 2017 CNRS
  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. /* Dummy cost function for simgrid */
  27. static double cost_function(struct starpu_task *task STARPU_ATTRIBUTE_UNUSED, unsigned nimpl STARPU_ATTRIBUTE_UNUSED)
  28. {
  29. return 0.000001;
  30. }
  31. static struct starpu_perfmodel dumb_model =
  32. {
  33. .type = STARPU_COMMON,
  34. .cost_function = cost_function
  35. };
  36. struct starpu_codelet mycodelet =
  37. {
  38. .cpu_funcs = {func_cpu},
  39. .nbuffers = 2,
  40. .modes = {STARPU_RW, STARPU_RW},
  41. .model = &dumb_model
  42. };
  43. int main(int argc, char **argv)
  44. {
  45. int rank, size, err;
  46. int x[2];
  47. int ret, i;
  48. starpu_data_handle_t data_handles[2];
  49. int values[2];
  50. ret = starpu_init(NULL);
  51. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  52. ret = starpu_mpi_init(&argc, &argv, 1);
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  54. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  55. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  56. if (starpu_cpu_worker_get_count() == 0)
  57. {
  58. if (rank == 0)
  59. FPRINTF(stderr, "We need at least 1 CPU worker.\n");
  60. starpu_mpi_shutdown();
  61. starpu_shutdown();
  62. return STARPU_TEST_SKIPPED;
  63. }
  64. if (rank == 0)
  65. {
  66. x[0] = 11;
  67. starpu_variable_data_register(&data_handles[0], STARPU_MAIN_RAM, (uintptr_t)&x[0], sizeof(x[0]));
  68. starpu_variable_data_register(&data_handles[1], -1, (uintptr_t)NULL, sizeof(x[1]));
  69. }
  70. else if (rank == 1)
  71. {
  72. x[1] = 12;
  73. starpu_variable_data_register(&data_handles[0], -1, (uintptr_t)NULL, sizeof(x[0]));
  74. starpu_variable_data_register(&data_handles[1], STARPU_MAIN_RAM, (uintptr_t)&x[1], sizeof(x[1]));
  75. }
  76. else
  77. {
  78. starpu_variable_data_register(&data_handles[0], -1, (uintptr_t)NULL, sizeof(x[0]));
  79. starpu_variable_data_register(&data_handles[1], -1, (uintptr_t)NULL, sizeof(x[1]));
  80. }
  81. starpu_mpi_data_register(data_handles[0], 0, 0);
  82. starpu_mpi_data_register(data_handles[1], 1, 1);
  83. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  84. STARPU_RW, data_handles[0], STARPU_RW, data_handles[1],
  85. STARPU_EXECUTE_ON_DATA, data_handles[1],
  86. 0);
  87. assert(err == 0);
  88. starpu_task_wait_for_all();
  89. for(i=0 ; i<2 ; i++)
  90. {
  91. starpu_mpi_get_data_on_node_detached(MPI_COMM_WORLD, data_handles[i], 0, NULL, NULL);
  92. if (rank == 0)
  93. {
  94. starpu_data_acquire(data_handles[i], STARPU_R);
  95. values[i] = *((int *)starpu_data_get_local_ptr(data_handles[i]));
  96. starpu_data_release(data_handles[i]);
  97. }
  98. }
  99. ret = 0;
  100. if (rank == 0)
  101. {
  102. FPRINTF(stderr, "[%d][local ptr] VALUES: %d %d\n", rank, values[0], values[1]);
  103. if (values[0] != 12 || values[1] != 144)
  104. {
  105. ret = EXIT_FAILURE;
  106. }
  107. }
  108. starpu_data_unregister(data_handles[0]);
  109. starpu_data_unregister(data_handles[1]);
  110. starpu_mpi_shutdown();
  111. starpu_shutdown();
  112. return ret;
  113. }