mpi_error.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2014-2015 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2016 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu_mpi.h>
  18. #include "helper.h"
  19. #define SIZE 100
  20. int main(int argc, char **argv)
  21. {
  22. int ret, rank, size;
  23. float *tab;
  24. starpu_data_handle_t tab_handle;
  25. MPI_Init(&argc, &argv);
  26. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  27. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  28. ret = starpu_init(NULL);
  29. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  30. ret = starpu_mpi_init(NULL, NULL, 0);
  31. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  32. if (size<2)
  33. {
  34. if (rank == 0)
  35. FPRINTF(stderr, "We need at least 2 processes.\n");
  36. starpu_mpi_shutdown();
  37. starpu_shutdown();
  38. MPI_Finalize();
  39. return STARPU_TEST_SKIPPED;
  40. }
  41. if (rank == 0)
  42. {
  43. tab = calloc(SIZE, sizeof(float));
  44. starpu_vector_data_register(&tab_handle, STARPU_MAIN_RAM, (uintptr_t)tab, SIZE, sizeof(float));
  45. starpu_mpi_send(tab_handle, 1, 12, MPI_COMM_WORLD);
  46. starpu_data_unregister(tab_handle);
  47. free(tab);
  48. }
  49. else if (rank == 1)
  50. {
  51. MPI_Status status;
  52. tab = calloc(SIZE-2, sizeof(float));
  53. starpu_vector_data_register(&tab_handle, STARPU_MAIN_RAM, (uintptr_t)tab, SIZE-2, sizeof(float));
  54. starpu_mpi_recv(tab_handle, 0, 12, MPI_COMM_WORLD, &status);
  55. starpu_data_unregister(tab_handle);
  56. free(tab);
  57. }
  58. starpu_mpi_shutdown();
  59. starpu_shutdown();
  60. MPI_Finalize();
  61. return 0;
  62. }