insert_task_count.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2014-2017 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu_mpi.h>
  18. #include "helper.h"
  19. #ifdef STARPU_QUICK_CHECK
  20. # define NITER 32
  21. #elif !defined(STARPU_LONG_CHECK)
  22. # define NITER 256
  23. #else
  24. # define NITER 2048
  25. #endif
  26. #ifdef STARPU_USE_CUDA
  27. extern void increment_cuda(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args);
  28. #endif
  29. void increment_cpu(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  30. {
  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_nop_perf_model,
  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_init(NULL);
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  53. ret = starpu_mpi_init(&argc, &argv, mpi_init);
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  55. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  56. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  57. if (size < 2 || (starpu_cpu_worker_get_count() + starpu_cuda_worker_get_count() == 0))
  58. {
  59. if (rank == 0)
  60. {
  61. if (size < 2)
  62. FPRINTF(stderr, "We need at least 2 processes.\n");
  63. else
  64. FPRINTF(stderr, "We need at least 1 CPU or CUDA worker.\n");
  65. }
  66. starpu_mpi_shutdown();
  67. starpu_shutdown();
  68. if (!mpi_init)
  69. MPI_Finalize();
  70. return STARPU_TEST_SKIPPED;
  71. }
  72. if (rank == 1)
  73. starpu_vector_data_register(&token_handle, 0, (uintptr_t)&token, 1, sizeof(token));
  74. else
  75. starpu_vector_data_register(&token_handle, -1, (uintptr_t)NULL, 1, sizeof(token));
  76. starpu_mpi_data_register(token_handle, 12, 1);
  77. int nloops = NITER;
  78. int loop;
  79. FPRINTF_MPI(stderr, "Start with token value %d\n", token);
  80. for (loop = 0; loop < nloops; loop++)
  81. {
  82. if (loop % 2)
  83. starpu_mpi_task_insert(MPI_COMM_WORLD, &increment_cl,
  84. STARPU_RW|STARPU_SSEND, token_handle,
  85. STARPU_EXECUTE_ON_NODE, 0,
  86. 0);
  87. else
  88. starpu_mpi_task_insert(MPI_COMM_WORLD, &increment_cl,
  89. STARPU_RW, token_handle,
  90. STARPU_EXECUTE_ON_NODE, 0,
  91. 0);
  92. }
  93. starpu_task_wait_for_all();
  94. starpu_data_unregister(token_handle);
  95. starpu_mpi_shutdown();
  96. starpu_shutdown();
  97. FPRINTF_MPI(stderr, "Final value for token %d\n", token);
  98. if (!mpi_init)
  99. MPI_Finalize();
  100. #ifndef STARPU_SIMGRID
  101. if (rank == 1)
  102. {
  103. STARPU_ASSERT_MSG(token == nloops, "token==%d != expected_value==%d\n", token, nloops);
  104. }
  105. else
  106. {
  107. STARPU_ASSERT_MSG(token == 0, "token==%d != expected_value==0\n", token);
  108. }
  109. #endif
  110. return 0;
  111. }