broadcast.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013,2015,2017 CNRS
  4. * Copyright (C) 2014-2015,2017-2018 Université de Bordeaux
  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 "helper.h"
  19. void wait_CPU(void *descr[], void *_args)
  20. {
  21. (void)_args;
  22. int *var = (int*) STARPU_VARIABLE_GET_PTR(descr[0]);
  23. *var = 42;
  24. starpu_sleep(1);
  25. }
  26. static struct starpu_codelet cl =
  27. {
  28. .cpu_funcs = { wait_CPU },
  29. .cpu_funcs_name = { "wait_CPU" },
  30. .nbuffers = 1,
  31. .flags = STARPU_CODELET_SIMGRID_EXECUTE,
  32. .modes = { STARPU_W },
  33. };
  34. int main(int argc, char **argv)
  35. {
  36. int ret, rank, size;
  37. starpu_data_handle_t handle;
  38. int var;
  39. int mpi_init;
  40. MPI_Status status;
  41. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  42. ret = starpu_init(NULL);
  43. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  44. ret = starpu_mpi_init(&argc, &argv, mpi_init);
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  46. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  47. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  48. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  49. if (rank == 0)
  50. {
  51. starpu_task_insert(&cl, STARPU_W, handle, 0);
  52. int n;
  53. for(n = 1 ; n < size ; n++)
  54. {
  55. FPRINTF_MPI(stderr, "sending data to %d\n", n);
  56. starpu_mpi_isend_detached(handle, n, 0, MPI_COMM_WORLD, NULL, NULL);
  57. }
  58. }
  59. else
  60. {
  61. starpu_mpi_recv(handle, 0, 0, MPI_COMM_WORLD, &status);
  62. FPRINTF_MPI(stderr, "received data\n");
  63. }
  64. starpu_data_unregister(handle);
  65. STARPU_ASSERT(var == 42);
  66. starpu_mpi_shutdown();
  67. starpu_shutdown();
  68. if (!mpi_init)
  69. MPI_Finalize();
  70. return 0;
  71. }