mpi_complex.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // We send a dummy variable only to check communication with predefined datatypes
  46. int foo=12;
  47. starpu_data_handle_t foo_handle;
  48. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  49. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  50. starpu_mpi_send(handle, 1, 10, MPI_COMM_WORLD);
  51. starpu_variable_data_register(&foo_handle, 0, (uintptr_t)&foo, sizeof(foo));
  52. starpu_mpi_send(foo_handle, 1, 10, MPI_COMM_WORLD);
  53. starpu_complex_data_register(&handle2, -1, real2, imaginary2, 2);
  54. starpu_mpi_recv(handle2, 1, 11, MPI_COMM_WORLD, &status);
  55. starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
  56. starpu_insert_task(&cl_compare, STARPU_R, handle, STARPU_R, handle2, 0);
  57. }
  58. else if (rank == 1)
  59. {
  60. double real[2] = {0.0, 0.0};
  61. double imaginary[2] = {0.0, 0.0};
  62. starpu_data_handle_t handle;
  63. MPI_Status status;
  64. // We send a dummy variable only to check communication with predefined datatypes
  65. int foo=12;
  66. starpu_data_handle_t foo_handle;
  67. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  68. starpu_mpi_recv(handle, 0, 10, MPI_COMM_WORLD, &status);
  69. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  70. starpu_variable_data_register(&foo_handle, -1, (uintptr_t)NULL, sizeof(foo));
  71. starpu_mpi_recv(foo_handle, 0, 10, MPI_COMM_WORLD, &status);
  72. starpu_mpi_send(handle, 0, 11, MPI_COMM_WORLD);
  73. }
  74. }
  75. starpu_task_wait_for_all();
  76. starpu_mpi_shutdown();
  77. starpu_shutdown();
  78. return ret;
  79. }