insert_task_owner_data.c 3.1 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 <starpu_mpi_datatype.h>
  18. #include <math.h>
  19. #include "helper.h"
  20. void func_cpu(void *descr[], __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. *x0 += 1;
  25. *x1 *= *x1;
  26. }
  27. struct starpu_codelet mycodelet =
  28. {
  29. .where = STARPU_CPU,
  30. .cpu_func = func_cpu,
  31. .nbuffers = 2
  32. };
  33. int main(int argc, char **argv)
  34. {
  35. int rank, size, err;
  36. int x[2];
  37. int ret, i;
  38. starpu_data_handle_t data_handles[2];
  39. int values[2];
  40. ret = starpu_init(NULL);
  41. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  42. ret = starpu_mpi_initialize_extended(&rank, &size);
  43. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_initialize_extended");
  44. if (rank > 1)
  45. {
  46. starpu_mpi_shutdown();
  47. starpu_shutdown();
  48. return STARPU_TEST_SKIPPED;
  49. }
  50. if (rank == 0)
  51. {
  52. x[0] = 11;
  53. starpu_variable_data_register(&data_handles[0], 0, (uintptr_t)&x[0], sizeof(x[0]));
  54. starpu_data_set_rank(data_handles[0], 0);
  55. starpu_data_set_tag(data_handles[0], 0);
  56. starpu_variable_data_register(&data_handles[1], -1, (uintptr_t)NULL, sizeof(x[1]));
  57. starpu_data_set_rank(data_handles[1], 1);
  58. starpu_data_set_tag(data_handles[1],10);
  59. }
  60. else if (rank == 1)
  61. {
  62. x[1] = 12;
  63. starpu_variable_data_register(&data_handles[0], -1, (uintptr_t)NULL, sizeof(x[0]));
  64. starpu_data_set_rank(data_handles[0], 0);
  65. starpu_data_set_tag(data_handles[0], 0);
  66. starpu_variable_data_register(&data_handles[1], 0, (uintptr_t)&x[1], sizeof(x[1]));
  67. starpu_data_set_rank(data_handles[1], 1);
  68. starpu_data_set_tag(data_handles[1], 1);
  69. }
  70. err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet,
  71. STARPU_RW, data_handles[0], STARPU_RW, data_handles[1],
  72. STARPU_EXECUTE_ON_DATA, data_handles[1],
  73. 0);
  74. assert(err == 0);
  75. starpu_task_wait_for_all();
  76. for(i=0 ; i<2 ; i++)
  77. {
  78. starpu_mpi_get_data_on_node(MPI_COMM_WORLD, data_handles[i], 0);
  79. starpu_data_acquire(data_handles[i], STARPU_R);
  80. values[i] = *((int *)starpu_mpi_handle_to_ptr(data_handles[i]));
  81. }
  82. assert(values[0] == 12 && values[1] == 144);
  83. FPRINTF(stderr, "[%d][local ptr] VALUES: %d %d\n", rank, values[0], values[1]);
  84. starpu_mpi_shutdown();
  85. starpu_shutdown();
  86. return 0;
  87. }