sendrecv_bench.c 2.4 KB

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