mpi_complex.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 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 <interface/complex_interface.h>
  18. #include <interface/complex_codelet.h>
  19. int main(int argc, char **argv)
  20. {
  21. int rank, nodes;
  22. int ret;
  23. ret = starpu_init(NULL);
  24. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  25. starpu_mpi_initialize_extended(&rank, &nodes);
  26. if (nodes < 2)
  27. {
  28. fprintf(stderr, "This program needs at least 2 nodes\n");
  29. ret = 77;
  30. }
  31. else
  32. {
  33. if (rank == 0)
  34. {
  35. double real[2] = {4.0, 2.0};
  36. double imaginary[2] = {7.0, 9.0};
  37. starpu_data_handle_t handle;
  38. double real2[2] = {14.0, 12.0};
  39. double imaginary2[2] = {17.0, 19.0};
  40. starpu_data_handle_t handle2;
  41. MPI_Status status;
  42. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  43. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  44. starpu_mpi_send(handle, 1, 10, MPI_COMM_WORLD);
  45. starpu_complex_data_register(&handle2, -1, real2, imaginary2, 2);
  46. starpu_mpi_recv(handle2, 1, 11, MPI_COMM_WORLD, &status);
  47. starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
  48. starpu_insert_task(&cl_compare, STARPU_R, handle, STARPU_R, handle2, 0);
  49. }
  50. else if (rank == 1)
  51. {
  52. double real[2] = {0.0, 0.0};
  53. double imaginary[2] = {0.0, 0.0};
  54. starpu_data_handle_t handle;
  55. MPI_Status status;
  56. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  57. starpu_mpi_recv(handle, 0, 10, MPI_COMM_WORLD, &status);
  58. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  59. starpu_mpi_send(handle, 0, 11, MPI_COMM_WORLD);
  60. }
  61. }
  62. starpu_task_wait_for_all();
  63. starpu_mpi_shutdown();
  64. starpu_shutdown();
  65. return ret;
  66. }