insert_task_owner2.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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 <starpu_mpi_datatype.h>
  18. #include <math.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. //
  27. // *x2 = 45;
  28. // *y = 144;
  29. //
  30. fprintf(stderr, "-------> CODELET VALUES: %d %d %d %d\n", *x0, *x1, *x2, *y);
  31. *y = (*x0 + *x1) * 100;
  32. *x1 = 12;
  33. *x2 = 24;
  34. *x0 = 36;
  35. fprintf(stderr, "-------> CODELET VALUES: %d %d %d %d\n", *x0, *x1, *x2, *y);
  36. }
  37. starpu_codelet mycodelet = {
  38. .where = STARPU_CPU,
  39. .cpu_func = func_cpu,
  40. .nbuffers = 4
  41. };
  42. int main(int argc, char **argv)
  43. {
  44. int rank, size, err;
  45. int x[3], y=0;
  46. int i;
  47. starpu_data_handle data_handles[4];
  48. starpu_init(NULL);
  49. starpu_mpi_initialize_extended(&rank, &size);
  50. if (rank > 1) {
  51. starpu_mpi_shutdown();
  52. starpu_shutdown();
  53. return 0;
  54. }
  55. if (rank == 0) {
  56. for(i=0 ; i<3 ; i++) {
  57. x[i] = 10*(i+1);
  58. starpu_variable_data_register(&data_handles[i], 0, (uintptr_t)&x[i], sizeof(x[i]));
  59. starpu_data_set_rank(data_handles[i], rank);
  60. starpu_data_set_tag(data_handles[i], i);
  61. }
  62. y = -1;
  63. starpu_variable_data_register(&data_handles[3], -1, (uintptr_t)NULL, sizeof(int));
  64. starpu_data_set_rank(data_handles[3], 1);
  65. starpu_data_set_tag(data_handles[3], 3);
  66. }
  67. else if (rank == 1) {
  68. for(i=0 ; i<3 ; i++) {
  69. x[i] = -1;
  70. starpu_variable_data_register(&data_handles[i], -1, (uintptr_t)NULL, sizeof(int));
  71. starpu_data_set_rank(data_handles[i], 0);
  72. starpu_data_set_tag(data_handles[i], i);
  73. }
  74. y=200;
  75. starpu_variable_data_register(&data_handles[3], 0, (uintptr_t)&y, sizeof(int));
  76. starpu_data_set_rank(data_handles[3], rank);
  77. starpu_data_set_tag(data_handles[3], 3);
  78. }
  79. fprintf(stderr, "[%d][init] VALUES: %d %d %d %d\n", rank, x[0], x[1], x[2], y);
  80. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet,
  81. STARPU_R, data_handles[0], STARPU_RW, data_handles[1],
  82. STARPU_W, data_handles[2],
  83. STARPU_W, data_handles[3],
  84. STARPU_EXECUTE_ON_NODE, 1, 0);
  85. assert(err == 0);
  86. starpu_task_wait_for_all();
  87. int *values = malloc(4 * sizeof(int *));
  88. for(i=0 ; i<4 ; i++) {
  89. starpu_mpi_get_data_on_node(MPI_COMM_WORLD, data_handles[i], 0);
  90. starpu_data_acquire(data_handles[i], STARPU_R);
  91. values[i] = *((int *)starpu_mpi_handle_to_ptr(data_handles[i]));
  92. }
  93. fprintf(stderr, "[%d][local ptr] VALUES: %d %d %d %d\n", rank, values[0], values[1], values[2], values[3]);
  94. fprintf(stderr, "[%d][end] VALUES: %d %d %d %d\n", rank, x[0], x[1], x[2], y);
  95. starpu_mpi_shutdown();
  96. starpu_shutdown();
  97. return 0;
  98. }