insert_task_owner2.c 3.9 KB

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