insert_task_owner2.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012, 2015 Université Bordeaux
  4. * Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu_mpi.h>
  18. #include <math.h>
  19. #include "helper.h"
  20. void func_cpu(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  21. {
  22. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  23. int *x1 = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  24. int *x2 = (int *)STARPU_VARIABLE_GET_PTR(descr[2]);
  25. int *y = (int *)STARPU_VARIABLE_GET_PTR(descr[3]);
  26. FPRINTF(stderr, "-------> CODELET VALUES: %d %d nan %d\n", *x0, *x1, *y);
  27. *x2 = *y;
  28. *y = (*x0 + *x1) * 100;
  29. *x1 = 12;
  30. FPRINTF(stderr, "-------> CODELET VALUES: %d %d %d %d\n", *x0, *x1, *x2, *y);
  31. }
  32. /* Dummy cost function for simgrid */
  33. static double cost_function(struct starpu_task *task STARPU_ATTRIBUTE_UNUSED, unsigned nimpl STARPU_ATTRIBUTE_UNUSED)
  34. {
  35. return 0.000001;
  36. }
  37. static struct starpu_perfmodel dumb_model =
  38. {
  39. .type = STARPU_COMMON,
  40. .cost_function = cost_function
  41. };
  42. struct starpu_codelet mycodelet =
  43. {
  44. .cpu_funcs = {func_cpu},
  45. .nbuffers = 4,
  46. .modes = {STARPU_R, STARPU_RW, STARPU_W, STARPU_W},
  47. .model = &dumb_model
  48. };
  49. int main(int argc, char **argv)
  50. {
  51. int rank, size, err;
  52. int x[3], y=0;
  53. int oldx[3];
  54. int i, ret=0;
  55. starpu_data_handle_t data_handles[4];
  56. ret = starpu_init(NULL);
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  58. ret = starpu_mpi_init(&argc, &argv, 1);
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  60. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  61. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  62. if (starpu_cpu_worker_get_count() == 0)
  63. {
  64. if (rank == 0)
  65. FPRINTF(stderr, "We need at least 1 CPU worker.\n");
  66. starpu_mpi_shutdown();
  67. starpu_shutdown();
  68. return STARPU_TEST_SKIPPED;
  69. }
  70. if (rank == 0)
  71. {
  72. for(i=0 ; i<3 ; i++)
  73. {
  74. x[i] = 10*(i+1);
  75. oldx[i] = 10*(i+1);
  76. starpu_variable_data_register(&data_handles[i], STARPU_MAIN_RAM, (uintptr_t)&x[i], sizeof(x[i]));
  77. }
  78. y = -1;
  79. starpu_variable_data_register(&data_handles[3], -1, (uintptr_t)NULL, sizeof(int));
  80. }
  81. else
  82. {
  83. for(i=0 ; i<3 ; i++)
  84. {
  85. x[i] = -1;
  86. starpu_variable_data_register(&data_handles[i], -1, (uintptr_t)NULL, sizeof(int));
  87. }
  88. y=200;
  89. starpu_variable_data_register(&data_handles[3], STARPU_MAIN_RAM, (uintptr_t)&y, sizeof(int));
  90. }
  91. for(i=0 ; i<3 ; i++)
  92. {
  93. starpu_mpi_data_register(data_handles[i], i, 0);
  94. }
  95. starpu_mpi_data_register(data_handles[3], 3, 1);
  96. FPRINTF(stderr, "[%d][init] VALUES: %d %d %d %d\n", rank, x[0], x[1], x[2], y);
  97. err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  98. STARPU_R, data_handles[0], STARPU_RW, data_handles[1],
  99. STARPU_W, data_handles[2],
  100. STARPU_W, data_handles[3],
  101. STARPU_EXECUTE_ON_NODE, 1, 0);
  102. STARPU_CHECK_RETURN_VALUE(err, "starpu_mpi_task_insert");
  103. starpu_task_wait_for_all();
  104. int *values = malloc(4 * sizeof(int));
  105. for(i=0 ; i<4 ; i++)
  106. {
  107. starpu_mpi_get_data_on_node_detached(MPI_COMM_WORLD, data_handles[i], 0, NULL, NULL);
  108. if (rank == 0)
  109. {
  110. starpu_data_acquire(data_handles[i], STARPU_R);
  111. values[i] = *((int *)starpu_data_get_local_ptr(data_handles[i]));
  112. starpu_data_release(data_handles[i]);
  113. }
  114. starpu_data_unregister(data_handles[i]);
  115. }
  116. if (rank == 0)
  117. {
  118. FPRINTF(stderr, "[%d][local ptr] VALUES: %d %d %d %d\n", rank, values[0], values[1], values[2], values[3]);
  119. if (values[0] != oldx[0] || values[1] != 12 || values[2] != 200 || values[3] != ((oldx[0] + oldx[1]) * 100))
  120. {
  121. FPRINTF(stderr, "[%d][error] values[0] %d != x[0] %d && values[1] %d != 12 && values[2] %d != 200 && values[3] %d != ((x[0] %d + x[1] %d) * 100)\n",
  122. rank, values[0], oldx[0], values[1], values[2], values[3], oldx[0], oldx[1]);
  123. ret = 1;
  124. }
  125. else
  126. {
  127. FPRINTF(stderr, "[%d] correct computation\n", rank);
  128. }
  129. }
  130. FPRINTF(stderr, "[%d][end] VALUES: %d %d %d %d\n", rank, x[0], x[1], x[2], y);
  131. free(values);
  132. starpu_mpi_shutdown();
  133. starpu_shutdown();
  134. return (rank == 0) ? ret : 0;
  135. }