sendrecv_bench.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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. /*
  17. * Basic send receive benchmark.
  18. * Inspired a lot from NewMadeleine examples/benchmarks/nm_bench_sendrecv.c
  19. */
  20. #include <starpu_mpi.h>
  21. #include "helper.h"
  22. #include "abstract_sendrecv_bench.h"
  23. int main(int argc, char **argv)
  24. {
  25. int ret, rank, worldsize;
  26. int mpi_init;
  27. int pause_workers = 0;
  28. for (int i = 1; i < argc; i++)
  29. {
  30. if (strcmp(argv[i], "-p") == 0)
  31. {
  32. pause_workers = 1;
  33. printf("Workers will be paused during benchmark.\n");
  34. }
  35. else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
  36. {
  37. fprintf(stderr, "Options:\n");
  38. fprintf(stderr, "\t-h --help display this help\n");
  39. fprintf(stderr, "\t-p pause workers during benchmark\n");
  40. exit(EXIT_SUCCESS);
  41. }
  42. else
  43. {
  44. fprintf(stderr,"Unrecognized option %s\n", argv[i]);
  45. exit(EXIT_FAILURE);
  46. }
  47. }
  48. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  49. ret = starpu_mpi_init_conf(&argc, &argv, mpi_init, MPI_COMM_WORLD, NULL);
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  51. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  52. starpu_mpi_comm_size(MPI_COMM_WORLD, &worldsize);
  53. if (worldsize < 2)
  54. {
  55. if (rank == 0)
  56. FPRINTF(stderr, "We need 2 processes.\n");
  57. starpu_mpi_shutdown();
  58. if (!mpi_init)
  59. MPI_Finalize();
  60. return STARPU_TEST_SKIPPED;
  61. }
  62. if (pause_workers)
  63. {
  64. /* Pause workers for this bench: all workers polling for tasks has a strong impact on performances */
  65. starpu_pause();
  66. }
  67. sendrecv_bench(rank, NULL);
  68. if (pause_workers)
  69. {
  70. starpu_resume();
  71. }
  72. starpu_mpi_shutdown();
  73. if (!mpi_init)
  74. MPI_Finalize();
  75. return 0;
  76. }