insert_task_count.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2014-2015 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 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. #else
  22. # define NITER 2048
  23. #endif
  24. #ifdef STARPU_USE_CUDA
  25. extern void increment_cuda(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args);
  26. #endif
  27. void increment_cpu(void *descr[], STARPU_ATTRIBUTE_UNUSED void *_args)
  28. {
  29. int *tokenptr = (int *)STARPU_VECTOR_GET_PTR(descr[0]);
  30. (*tokenptr)++;
  31. }
  32. /* Dummy cost function for simgrid */
  33. static double cost_function(struct starpu_task *task STARPU_ATTRIBUTE_UNUSED, unsigned nimpl STARPU_ATTRIBUTE_UNUSED)
  34. {
  35. return 0.000001;
  36. }
  37. static struct starpu_perfmodel dumb_model =
  38. {
  39. .type = STARPU_COMMON,
  40. .cost_function = cost_function
  41. };
  42. static struct starpu_codelet increment_cl =
  43. {
  44. #ifdef STARPU_USE_CUDA
  45. .cuda_funcs = {increment_cuda},
  46. #endif
  47. .cpu_funcs = {increment_cpu},
  48. .nbuffers = 1,
  49. .modes = {STARPU_RW},
  50. .model = &dumb_model
  51. };
  52. int main(int argc, char **argv)
  53. {
  54. int ret, rank, size;
  55. int token = 0;
  56. starpu_data_handle_t token_handle;
  57. MPI_Init(&argc, &argv);
  58. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  59. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  60. ret = starpu_init(NULL);
  61. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  62. ret = starpu_mpi_init(NULL, NULL, 0);
  63. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  64. if (size < 2 || (starpu_cpu_worker_get_count() + starpu_cuda_worker_get_count() == 0))
  65. {
  66. if (rank == 0)
  67. {
  68. if (size < 2)
  69. FPRINTF(stderr, "We need at least 2 processes.\n");
  70. else
  71. FPRINTF(stderr, "We need at least 1 CPU or CUDA worker.\n");
  72. }
  73. starpu_mpi_shutdown();
  74. starpu_shutdown();
  75. MPI_Finalize();
  76. return STARPU_TEST_SKIPPED;
  77. }
  78. if (rank == 1)
  79. starpu_vector_data_register(&token_handle, 0, (uintptr_t)&token, 1, sizeof(token));
  80. else
  81. starpu_vector_data_register(&token_handle, -1, (uintptr_t)NULL, 1, sizeof(token));
  82. starpu_mpi_data_register(token_handle, 12, 1);
  83. int nloops = NITER;
  84. int loop;
  85. FPRINTF_MPI(stderr, "Start with token value %d\n", token);
  86. for (loop = 0; loop < nloops; loop++)
  87. {
  88. if (loop % 2)
  89. starpu_mpi_task_insert(MPI_COMM_WORLD, &increment_cl,
  90. STARPU_RW|STARPU_SSEND, token_handle,
  91. STARPU_EXECUTE_ON_NODE, 0,
  92. 0);
  93. else
  94. starpu_mpi_task_insert(MPI_COMM_WORLD, &increment_cl,
  95. STARPU_RW, token_handle,
  96. STARPU_EXECUTE_ON_NODE, 0,
  97. 0);
  98. }
  99. starpu_task_wait_for_all();
  100. starpu_data_unregister(token_handle);
  101. starpu_mpi_shutdown();
  102. starpu_shutdown();
  103. FPRINTF_MPI(stderr, "Final value for token %d\n", token);
  104. MPI_Finalize();
  105. #ifndef STARPU_SIMGRID
  106. if (rank == 1)
  107. {
  108. STARPU_ASSERT_MSG(token == nloops, "token==%d != expected_value==%d\n", token, nloops);
  109. }
  110. else
  111. {
  112. STARPU_ASSERT_MSG(token == 0, "token==%d != expected_value==0\n", token);
  113. }
  114. #endif
  115. return 0;
  116. }