insert_task_owner.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. unsigned *x = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[0]);
  21. unsigned *y = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[1]);
  22. fprintf(stdout, "VALUES: %d %d\n", *x, *y);
  23. *x = (*x + *y) / 2;
  24. }
  25. starpu_codelet mycodelet = {
  26. .where = STARPU_CPU,
  27. .cpu_func = func_cpu,
  28. .nbuffers = 2
  29. };
  30. int main(int argc, char **argv)
  31. {
  32. int rank, size;
  33. unsigned x0, x1;
  34. starpu_data_handle data_handlesx0;
  35. starpu_data_handle data_handlesx1;
  36. starpu_init(NULL);
  37. starpu_mpi_initialize_extended(1, &rank, &size);
  38. if (rank == 0) {
  39. starpu_variable_data_register(&data_handlesx0, 0, (uintptr_t)&x0, sizeof(x0));
  40. starpu_data_set_rank(data_handlesx0, rank);
  41. starpu_variable_data_register(&data_handlesx1, -1, (uintptr_t)NULL, sizeof(unsigned));
  42. starpu_data_set_rank(data_handlesx1, 1);
  43. }
  44. else if (rank == 1) {
  45. starpu_variable_data_register(&data_handlesx1, 1, (uintptr_t)&x1, sizeof(x1));
  46. starpu_data_set_rank(data_handlesx1, rank);
  47. starpu_variable_data_register(&data_handlesx0, -1, (uintptr_t)NULL, sizeof(unsigned));
  48. starpu_data_set_rank(data_handlesx0, 0);
  49. }
  50. int err = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handlesx0, STARPU_RW, data_handlesx1);
  51. if (err == -EINVAL) {
  52. fprintf(stderr, "starpu_mpi_insert_task failed as expected\n");
  53. }
  54. else {
  55. return 1;
  56. }
  57. starpu_task_wait_for_all();
  58. starpu_mpi_shutdown();
  59. starpu_shutdown();
  60. return 0;
  61. }