insert_task_owner2.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <math.h>
  18. void func_cpu(void *descr[], __attribute__ ((unused)) void *_args)
  19. {
  20. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  21. int *x1 = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  22. int *x2 = (int *)STARPU_VARIABLE_GET_PTR(descr[2]);
  23. int *y = (int *)STARPU_VARIABLE_GET_PTR(descr[3]);
  24. // fprintf(stderr, "-------> CODELET VALUES: %d %d %d %d\n", *x0, *x1, *x2, *y);
  25. //
  26. // *x2 = 45;
  27. // *y = 144;
  28. //
  29. fprintf(stderr, "-------> CODELET VALUES: %d %d %d %d\n", *x0, *x1, *x2, *y);
  30. *y = (*x0 + *x1) * -100;
  31. *x1 = 12;
  32. *x2 = 24;
  33. fprintf(stderr, "-------> CODELET VALUES: %d %d %d %d\n", *x0, *x1, *x2, *y);
  34. }
  35. starpu_codelet mycodelet = {
  36. .where = STARPU_CPU,
  37. .cpu_func = func_cpu,
  38. .nbuffers = 4
  39. };
  40. int main(int argc, char **argv)
  41. {
  42. int rank, size, err;
  43. int x[3], y=0;
  44. int i;
  45. starpu_data_handle data_handles[4];
  46. starpu_init(NULL);
  47. starpu_mpi_initialize_extended(1, &rank, &size);
  48. if (rank == 0) {
  49. for(i=0 ; i<3 ; i++) {
  50. x[i] = -10*(i+1);
  51. starpu_variable_data_register(&data_handles[i], 0, (uintptr_t)&x[i], sizeof(x[i]));
  52. starpu_data_set_rank(data_handles[i], rank);
  53. }
  54. y = -40;
  55. starpu_variable_data_register(&data_handles[3], -1, (uintptr_t)NULL, sizeof(int));
  56. starpu_data_set_rank(data_handles[3], 1);
  57. }
  58. else if (rank == 1) {
  59. for(i=0 ; i<3 ; i++) {
  60. x[i] = -20;
  61. starpu_variable_data_register(&data_handles[i], -1, (uintptr_t)NULL, sizeof(int));
  62. starpu_data_set_rank(data_handles[i], 0);
  63. }
  64. y=-20;
  65. starpu_variable_data_register(&data_handles[3], 0, (uintptr_t)&y, sizeof(int));
  66. starpu_data_set_rank(data_handles[3], rank);
  67. }
  68. fprintf(stderr, "[%d] VALUES: %d %d %d %d\n", rank, x[0], x[1], x[2], y);
  69. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet,
  70. STARPU_R, data_handles[0], STARPU_RW, data_handles[1],
  71. STARPU_W, data_handles[2],
  72. STARPU_W, data_handles[3],
  73. STARPU_EXECUTE, 1, 0);
  74. assert(err == 0);
  75. starpu_task_wait_for_all();
  76. if (rank == 0) {
  77. for(i=0 ; i<3 ; i++) {
  78. starpu_data_acquire(data_handles[i], STARPU_R);
  79. }
  80. }
  81. else if (rank == 1) {
  82. starpu_data_acquire(data_handles[3], STARPU_R);
  83. }
  84. fprintf(stderr, "[%d] VALUES: %d %d %d %d\n", rank, x[0], x[1], x[2], y);
  85. starpu_mpi_shutdown();
  86. starpu_shutdown();
  87. return 0;
  88. }