pingpong.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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. #define NITER 2048
  18. #define SIZE 16
  19. float *tab;
  20. starpu_data_handle tab_handle;
  21. int main(int argc, char **argv)
  22. {
  23. MPI_Init(NULL, NULL);
  24. int rank, size;
  25. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  26. MPI_Comm_size(MPI_COMM_WORLD, &size);
  27. if (size != 2)
  28. {
  29. if (rank == 0)
  30. fprintf(stderr, "We need exactly 2 processes.\n");
  31. MPI_Finalize();
  32. return 0;
  33. }
  34. starpu_init(NULL);
  35. starpu_mpi_initialize();
  36. tab = malloc(SIZE*sizeof(float));
  37. starpu_register_vector_data(&tab_handle, 0, (uintptr_t)tab, SIZE, sizeof(float));
  38. unsigned nloops = NITER;
  39. unsigned loop;
  40. int other_rank = (rank + 1)%2;
  41. for (loop = 0; loop < nloops; loop++)
  42. {
  43. if ((loop % 2) == rank)
  44. {
  45. starpu_mpi_send(tab_handle, other_rank, loop, MPI_COMM_WORLD);
  46. }
  47. else {
  48. MPI_Status status;
  49. starpu_mpi_recv(tab_handle, other_rank, loop, MPI_COMM_WORLD, &status);
  50. }
  51. }
  52. starpu_mpi_shutdown();
  53. starpu_shutdown();
  54. MPI_Finalize();
  55. return 0;
  56. }