mpi_complex2.c 2.5 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. void display_double_codelet(void *descr[], __attribute__ ((unused)) void *_args)
  20. {
  21. double *foo = (double *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. fprintf(stderr, "foo = %f\n", *foo);
  23. }
  24. struct starpu_codelet double_display =
  25. {
  26. .cpu_funcs = {display_double_codelet, NULL},
  27. .nbuffers = 1,
  28. .modes = {STARPU_R}
  29. };
  30. void test_handle(starpu_data_handle_t handle, struct starpu_codelet *codelet, int rank)
  31. {
  32. starpu_data_set_rank(handle, 1);
  33. starpu_data_set_tag(handle, 42);
  34. if (rank == 0)
  35. {
  36. starpu_insert_task(codelet, STARPU_R, handle, 0);
  37. }
  38. starpu_mpi_get_data_on_node_detached(MPI_COMM_WORLD, handle, 0, NULL, NULL);
  39. if (rank == 0)
  40. {
  41. starpu_insert_task(codelet, STARPU_R, handle, 0);
  42. }
  43. }
  44. int main(int argc, char **argv)
  45. {
  46. int rank, nodes;
  47. int ret;
  48. ret = starpu_init(NULL);
  49. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  50. ret = starpu_mpi_init(&argc, &argv);
  51. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  52. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  53. MPI_Comm_size(MPI_COMM_WORLD, &nodes);
  54. if (nodes < 2)
  55. {
  56. fprintf(stderr, "This program needs at least 2 nodes\n");
  57. ret = 77;
  58. }
  59. else
  60. {
  61. double real[2] = {0.0, 0.0};
  62. double imaginary[2] = {0.0, 0.0};
  63. double foo=8;
  64. starpu_data_handle_t handle_complex;
  65. starpu_data_handle_t handle_var;
  66. if (rank == 1)
  67. {
  68. foo = 42;
  69. real[0] = 12.0;
  70. real[1] = 45.0;
  71. imaginary[0] = 7.0;
  72. imaginary[1] = 42.0;
  73. }
  74. starpu_complex_data_register(&handle_complex, 0, real, imaginary, 2);
  75. starpu_variable_data_register(&handle_var, 0, (uintptr_t)&foo, sizeof(double));
  76. test_handle(handle_var, &double_display, rank);
  77. test_handle(handle_complex, &cl_display, rank);
  78. }
  79. starpu_task_wait_for_all();
  80. starpu_mpi_shutdown();
  81. starpu_shutdown();
  82. return 0;
  83. }