insert_task_owner2.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013 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[], __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. int *x2 = (int *)STARPU_VARIABLE_GET_PTR(descr[2]);
  24. int *y = (int *)STARPU_VARIABLE_GET_PTR(descr[3]);
  25. //FPRINTF(stderr, "-------> CODELET VALUES: %d %d %d %d\n", *x0, *x1, *x2, *y);
  26. //*x2 = 45;
  27. //*y = 144;
  28. FPRINTF(stderr, "-------> CODELET VALUES: %d %d %d %d\n", *x0, *x1, *x2, *y);
  29. *y = (*x0 + *x1) * 100;
  30. *x1 = 12;
  31. *x2 = 24;
  32. *x0 = 36;
  33. FPRINTF(stderr, "-------> CODELET VALUES: %d %d %d %d\n", *x0, *x1, *x2, *y);
  34. }
  35. struct starpu_codelet mycodelet =
  36. {
  37. .cpu_funcs = {func_cpu, NULL},
  38. .nbuffers = 4,
  39. .modes = {STARPU_R, STARPU_RW, STARPU_W, STARPU_W}
  40. };
  41. int main(int argc, char **argv)
  42. {
  43. int rank, size, err;
  44. int x[3], y=0;
  45. int i, ret;
  46. starpu_data_handle_t data_handles[4];
  47. ret = starpu_init(NULL);
  48. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  49. ret = starpu_mpi_init(&argc, &argv, 1);
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  51. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  52. MPI_Comm_size(MPI_COMM_WORLD, &size);
  53. if (rank == 0)
  54. {
  55. for(i=0 ; i<3 ; i++)
  56. {
  57. x[i] = 10*(i+1);
  58. starpu_variable_data_register(&data_handles[i], 0, (uintptr_t)&x[i], sizeof(x[i]));
  59. }
  60. y = -1;
  61. starpu_variable_data_register(&data_handles[3], -1, (uintptr_t)NULL, sizeof(int));
  62. }
  63. else if (rank == 1)
  64. {
  65. for(i=0 ; i<3 ; i++)
  66. {
  67. x[i] = -1;
  68. starpu_variable_data_register(&data_handles[i], -1, (uintptr_t)NULL, sizeof(int));
  69. }
  70. y=200;
  71. starpu_variable_data_register(&data_handles[3], 0, (uintptr_t)&y, sizeof(int));
  72. }
  73. else
  74. {
  75. for(i=0 ; i<4 ; i++)
  76. starpu_variable_data_register(&data_handles[i], -1, (uintptr_t)NULL, sizeof(int));
  77. }
  78. FPRINTF(stderr, "[%d][init] VALUES: %d %d %d %d\n", rank, x[0], x[1], x[2], y);
  79. for(i=0 ; i<3 ; i++)
  80. {
  81. starpu_data_set_rank(data_handles[i], 0);
  82. starpu_data_set_tag(data_handles[i], i);
  83. }
  84. starpu_data_set_rank(data_handles[3], 1);
  85. starpu_data_set_tag(data_handles[3], 3);
  86. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet,
  87. STARPU_R, data_handles[0], STARPU_RW, data_handles[1],
  88. STARPU_W, data_handles[2],
  89. STARPU_W, data_handles[3],
  90. STARPU_EXECUTE_ON_NODE, 1, 0);
  91. STARPU_CHECK_RETURN_VALUE(err, "starpu_mpi_insert_task");
  92. starpu_task_wait_for_all();
  93. int *values = malloc(4 * sizeof(int *));
  94. for(i=0 ; i<4 ; i++)
  95. {
  96. starpu_mpi_get_data_on_node_detached(MPI_COMM_WORLD, data_handles[i], 0, NULL, NULL);
  97. if (rank == 0)
  98. {
  99. starpu_data_acquire(data_handles[i], STARPU_R);
  100. values[i] = *((int *)starpu_handle_get_local_ptr(data_handles[i]));
  101. starpu_data_release(data_handles[i]);
  102. }
  103. starpu_data_unregister(data_handles[i]);
  104. }
  105. FPRINTF(stderr, "[%d][local ptr] VALUES: %d %d %d %d\n", rank, values[0], values[1], values[2], values[3]);
  106. FPRINTF(stderr, "[%d][end] VALUES: %d %d %d %d\n", rank, x[0], x[1], x[2], y);
  107. free(values);
  108. starpu_mpi_shutdown();
  109. starpu_shutdown();
  110. return 0;
  111. }