mpi_complex.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. void display_foo_codelet(void *descr[], __attribute__ ((unused)) void *_args)
  20. {
  21. int *foo = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. fprintf(stderr, "foo = %d\n", *foo);
  23. }
  24. struct starpu_codelet foo_display =
  25. {
  26. .cpu_funcs = {display_foo_codelet, NULL},
  27. .nbuffers = 1,
  28. .modes = {STARPU_R}
  29. };
  30. int main(int argc, char **argv)
  31. {
  32. int rank, nodes;
  33. int ret;
  34. int compare;
  35. ret = starpu_init(NULL);
  36. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  37. ret = starpu_mpi_init(&argc, &argv, 1);
  38. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  39. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  40. MPI_Comm_size(MPI_COMM_WORLD, &nodes);
  41. if (nodes < 2)
  42. {
  43. fprintf(stderr, "This program needs at least 2 nodes\n");
  44. ret = 77;
  45. }
  46. else
  47. {
  48. if (rank == 0)
  49. {
  50. double real[2] = {4.0, 2.0};
  51. double imaginary[2] = {7.0, 9.0};
  52. starpu_data_handle_t handle;
  53. double real2[2] = {14.0, 12.0};
  54. double imaginary2[2] = {17.0, 19.0};
  55. starpu_data_handle_t handle2;
  56. int *compare_ptr = &compare;
  57. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  58. starpu_complex_data_register(&handle2, -1, real2, imaginary2, 2);
  59. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  60. starpu_mpi_isend_detached(handle, 1, 10, MPI_COMM_WORLD, NULL, NULL);
  61. starpu_mpi_irecv_detached(handle2, 1, 20, MPI_COMM_WORLD, NULL, NULL);
  62. starpu_insert_task(&cl_display, STARPU_R, handle2, 0);
  63. starpu_insert_task(&cl_compare, STARPU_R, handle, STARPU_R, handle2, STARPU_VALUE, &compare_ptr, sizeof(compare_ptr), 0);
  64. {
  65. // We send a dummy variable only to check communication with predefined datatypes
  66. int foo=12;
  67. starpu_data_handle_t foo_handle;
  68. starpu_variable_data_register(&foo_handle, 0, (uintptr_t)&foo, sizeof(foo));
  69. starpu_mpi_isend_detached(foo_handle, 1, 40, MPI_COMM_WORLD, NULL, NULL);
  70. starpu_insert_task(&foo_display, STARPU_R, foo_handle, 0);
  71. }
  72. }
  73. else if (rank == 1)
  74. {
  75. double real[2] = {0.0, 0.0};
  76. double imaginary[2] = {0.0, 0.0};
  77. starpu_data_handle_t handle;
  78. starpu_complex_data_register(&handle, 0, real, imaginary, 2);
  79. starpu_mpi_irecv_detached(handle, 0, 10, MPI_COMM_WORLD, NULL, NULL);
  80. starpu_insert_task(&cl_display, STARPU_R, handle, 0);
  81. starpu_mpi_isend_detached(handle, 0, 20, MPI_COMM_WORLD, NULL, NULL);
  82. {
  83. // We send a dummy variable only to check communication with predefined datatypes
  84. int foo=12;
  85. starpu_data_handle_t foo_handle;
  86. starpu_variable_data_register(&foo_handle, -1, (uintptr_t)NULL, sizeof(foo));
  87. starpu_mpi_irecv_detached(foo_handle, 0, 40, MPI_COMM_WORLD, NULL, NULL);
  88. starpu_insert_task(&foo_display, STARPU_R, foo_handle, 0);
  89. }
  90. }
  91. }
  92. starpu_task_wait_for_all();
  93. starpu_mpi_shutdown();
  94. starpu_shutdown();
  95. if (rank == 0) return !compare; else return ret;
  96. }