mpi_complex.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. int compare;
  24. ret = starpu_init(NULL);
  25. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  26. ret = starpu_mpi_init(&argc, &argv);
  27. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  28. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  29. MPI_Comm_size(MPI_COMM_WORLD, &nodes);
  30. if (nodes < 2)
  31. {
  32. fprintf(stderr, "This program needs at least 2 nodes\n");
  33. ret = 77;
  34. }
  35. else
  36. {
  37. if (rank == 0)
  38. {
  39. double real[2] = {4.0, 2.0};
  40. double imaginary[2] = {7.0, 9.0};
  41. starpu_data_handle_t handle;
  42. double real2[2] = {14.0, 12.0};
  43. double imaginary2[2] = {17.0, 19.0};
  44. starpu_data_handle_t handle2;
  45. MPI_Status status;
  46. // We send a dummy variable only to check communication with predefined datatypes
  47. int foo=12;
  48. starpu_data_handle_t foo_handle;
  49. int *compare_ptr = &compare;
  50. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  51. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  52. starpu_mpi_send(handle, 1, 10, MPI_COMM_WORLD);
  53. starpu_variable_data_register(&foo_handle, 0, (uintptr_t)&foo, sizeof(foo));
  54. starpu_mpi_send(foo_handle, 1, 10, MPI_COMM_WORLD);
  55. starpu_complex_data_register(&handle2, -1, real2, imaginary2, 2);
  56. starpu_mpi_recv(handle2, 1, 11, MPI_COMM_WORLD, &status);
  57. starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
  58. starpu_insert_task(&cl_compare, STARPU_R, handle, STARPU_R, handle2, STARPU_VALUE, &compare_ptr, sizeof(compare_ptr), 0);
  59. }
  60. else if (rank == 1)
  61. {
  62. double real[2] = {0.0, 0.0};
  63. double imaginary[2] = {0.0, 0.0};
  64. starpu_data_handle_t handle;
  65. MPI_Status status;
  66. // We send a dummy variable only to check communication with predefined datatypes
  67. int foo=12;
  68. starpu_data_handle_t foo_handle;
  69. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  70. starpu_mpi_recv(handle, 0, 10, MPI_COMM_WORLD, &status);
  71. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  72. starpu_variable_data_register(&foo_handle, -1, (uintptr_t)NULL, sizeof(foo));
  73. starpu_mpi_recv(foo_handle, 0, 10, MPI_COMM_WORLD, &status);
  74. starpu_mpi_send(handle, 0, 11, MPI_COMM_WORLD);
  75. }
  76. }
  77. starpu_task_wait_for_all();
  78. starpu_mpi_shutdown();
  79. starpu_shutdown();
  80. if (rank == 0) return !compare; else return ret;
  81. }