sendrecv_bench.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * Send-receive benchmark where peers exchange data at the same time.
  18. * Inspired a lot from NewMadeleine examples/benchmarks/nm_bench_bidir.c
  19. */
  20. #include <starpu_mpi.h>
  21. #include "helper.h"
  22. #include "abstract_sendrecv_bench.h"
  23. static inline void man()
  24. {
  25. fprintf(stderr, "Options:\n");
  26. fprintf(stderr, "\t-h --help display this help\n");
  27. fprintf(stderr, "\t-p pause workers during benchmark\n");
  28. fprintf(stderr, "\t--bidir full-duplex communications\n");
  29. exit(EXIT_SUCCESS);
  30. }
  31. int main(int argc, char **argv)
  32. {
  33. int ret, rank, worldsize;
  34. int pause_workers = 0;
  35. int i = 0;
  36. int bidir = 0;
  37. for (i = 1; i < argc; i++)
  38. {
  39. if (strcmp(argv[i], "-p") == 0)
  40. {
  41. pause_workers = 1;
  42. printf("Workers will be paused during benchmark.\n");
  43. }
  44. else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
  45. {
  46. man();
  47. }
  48. if (strcmp(argv[i], "--bidir") == 0)
  49. {
  50. bidir = 1;
  51. printf("Communications will be full-duplex.\n");
  52. }
  53. else
  54. {
  55. fprintf(stderr,"Unrecognized option %s\n", argv[i]);
  56. man();
  57. }
  58. }
  59. ret = starpu_mpi_init_conf(&argc, &argv, 1, MPI_COMM_WORLD, NULL);
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  61. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  62. starpu_mpi_comm_size(MPI_COMM_WORLD, &worldsize);
  63. if (worldsize < 2)
  64. {
  65. if (rank == 0)
  66. FPRINTF(stderr, "We need 2 processes.\n");
  67. starpu_mpi_shutdown();
  68. return STARPU_TEST_SKIPPED;
  69. }
  70. if (pause_workers)
  71. {
  72. /* Pause workers for this bench: all workers polling for tasks has a strong impact on performances */
  73. starpu_pause();
  74. }
  75. sendrecv_bench(rank, NULL, bidir);
  76. if (pause_workers)
  77. {
  78. starpu_resume();
  79. }
  80. starpu_mpi_shutdown();
  81. return 0;
  82. }