mpi_complex.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ret = starpu_mpi_init(&argc, &argv);
  26. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  27. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  28. MPI_Comm_size(MPI_COMM_WORLD, &nodes);
  29. if (nodes < 2)
  30. {
  31. fprintf(stderr, "This program needs at least 2 nodes\n");
  32. ret = 77;
  33. }
  34. else
  35. {
  36. if (rank == 0)
  37. {
  38. double real[2] = {4.0, 2.0};
  39. double imaginary[2] = {7.0, 9.0};
  40. starpu_data_handle_t handle;
  41. double real2[2] = {14.0, 12.0};
  42. double imaginary2[2] = {17.0, 19.0};
  43. starpu_data_handle_t handle2;
  44. MPI_Status status;
  45. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  46. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  47. starpu_mpi_send(handle, 1, 10, MPI_COMM_WORLD);
  48. starpu_complex_data_register(&handle2, -1, real2, imaginary2, 2);
  49. starpu_mpi_recv(handle2, 1, 11, MPI_COMM_WORLD, &status);
  50. starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
  51. starpu_insert_task(&cl_compare, STARPU_R, handle, STARPU_R, handle2, 0);
  52. }
  53. else if (rank == 1)
  54. {
  55. double real[2] = {0.0, 0.0};
  56. double imaginary[2] = {0.0, 0.0};
  57. starpu_data_handle_t handle;
  58. MPI_Status status;
  59. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  60. starpu_mpi_recv(handle, 0, 10, MPI_COMM_WORLD, &status);
  61. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  62. starpu_mpi_send(handle, 0, 11, MPI_COMM_WORLD);
  63. }
  64. }
  65. starpu_task_wait_for_all();
  66. starpu_mpi_shutdown();
  67. starpu_shutdown();
  68. return ret;
  69. }