insert_task_count.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-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. #include <starpu_mpi.h>
  17. #include "helper.h"
  18. #ifdef STARPU_QUICK_CHECK
  19. # define NITER 32
  20. #elif !defined(STARPU_LONG_CHECK)
  21. # define NITER 256
  22. #else
  23. # define NITER 2048
  24. #endif
  25. #ifdef STARPU_USE_CUDA
  26. extern void increment_cuda(void *descr[], void *_args);
  27. #endif
  28. void increment_cpu(void *descr[], void *_args)
  29. {
  30. (void)_args;
  31. int *tokenptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  32. (*tokenptr)++;
  33. }
  34. static struct starpu_codelet increment_cl =
  35. {
  36. #ifdef STARPU_USE_CUDA
  37. .cuda_funcs = {increment_cuda},
  38. #endif
  39. .cpu_funcs = {increment_cpu},
  40. .nbuffers = 1,
  41. .modes = {STARPU_RW},
  42. .model = &starpu_perfmodel_nop,
  43. };
  44. int main(int argc, char **argv)
  45. {
  46. int ret, rank, size;
  47. int token = 0;
  48. starpu_data_handle_t token_handle;
  49. int mpi_init;
  50. MPI_INIT_THREAD(&argc, &argv, MPI_THREAD_SERIALIZED, &mpi_init);
  51. ret = starpu_mpi_init_conf(&argc, &argv, mpi_init, MPI_COMM_WORLD, NULL);
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  53. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  54. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  55. if (size < 2 || (starpu_cpu_worker_get_count() + starpu_cuda_worker_get_count() == 0))
  56. {
  57. if (rank == 0)
  58. {
  59. if (size < 2)
  60. FPRINTF(stderr, "We need at least 2 processes.\n");
  61. else
  62. FPRINTF(stderr, "We need at least 1 CPU or CUDA worker.\n");
  63. }
  64. starpu_mpi_shutdown();
  65. if (!mpi_init)
  66. MPI_Finalize();
  67. return STARPU_TEST_SKIPPED;
  68. }
  69. if (rank == 1)
  70. starpu_vector_data_register(&token_handle, 0, (uintptr_t)&token, 1, sizeof(token));
  71. else
  72. starpu_vector_data_register(&token_handle, -1, (uintptr_t)NULL, 1, sizeof(token));
  73. starpu_mpi_data_register(token_handle, 12, 1);
  74. int nloops = NITER;
  75. int loop;
  76. FPRINTF_MPI(stderr, "Start with token value %d\n", token);
  77. for (loop = 0; loop < nloops; loop++)
  78. {
  79. if (loop % 2)
  80. starpu_mpi_task_insert(MPI_COMM_WORLD, &increment_cl,
  81. STARPU_RW|STARPU_SSEND, token_handle,
  82. STARPU_EXECUTE_ON_NODE, 0,
  83. 0);
  84. else
  85. starpu_mpi_task_insert(MPI_COMM_WORLD, &increment_cl,
  86. STARPU_RW, token_handle,
  87. STARPU_EXECUTE_ON_NODE, 0,
  88. 0);
  89. }
  90. starpu_task_wait_for_all();
  91. starpu_data_unregister(token_handle);
  92. starpu_mpi_shutdown();
  93. FPRINTF_MPI(stderr, "Final value for token %d\n", token);
  94. if (!mpi_init)
  95. MPI_Finalize();
  96. #ifndef STARPU_SIMGRID
  97. if (rank == 1)
  98. {
  99. STARPU_ASSERT_MSG(token == nloops, "token==%d != expected_value==%d\n", token, nloops);
  100. }
  101. else
  102. {
  103. STARPU_ASSERT_MSG(token == 0, "token==%d != expected_value==0\n", token);
  104. }
  105. #endif
  106. return 0;
  107. }