insert_task_count.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014 Centre National de la Recherche Scientifique
  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. static struct starpu_codelet increment_cl =
  33. {
  34. #ifdef STARPU_USE_CUDA
  35. .cuda_funcs = {increment_cuda},
  36. #endif
  37. .cpu_funcs = {increment_cpu},
  38. .nbuffers = 1,
  39. .modes = {STARPU_RW}
  40. };
  41. int main(int argc, char **argv)
  42. {
  43. int ret, rank, size;
  44. int token = 0;
  45. starpu_data_handle_t token_handle;
  46. MPI_Init(NULL, NULL);
  47. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  48. MPI_Comm_size(MPI_COMM_WORLD, &size);
  49. if (size < 2)
  50. {
  51. if (rank == 0)
  52. FPRINTF(stderr, "We need at least 2 processes.\n");
  53. MPI_Finalize();
  54. return STARPU_TEST_SKIPPED;
  55. }
  56. ret = starpu_init(NULL);
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  58. ret = starpu_mpi_init(NULL, NULL, 0);
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  60. if (rank == 1)
  61. starpu_vector_data_register(&token_handle, 0, (uintptr_t)&token, 1, sizeof(token));
  62. else
  63. starpu_vector_data_register(&token_handle, -1, (uintptr_t)NULL, 1, sizeof(token));
  64. starpu_mpi_data_register(token_handle, 12, 1);
  65. int nloops = NITER;
  66. int loop;
  67. FPRINTF_MPI("Start with token value %d\n", token);
  68. for (loop = 0; loop < nloops; loop++)
  69. {
  70. starpu_mpi_insert_task(MPI_COMM_WORLD, &increment_cl,
  71. STARPU_RW, token_handle,
  72. STARPU_EXECUTE_ON_NODE, 0,
  73. 0);
  74. }
  75. starpu_task_wait_for_all();
  76. starpu_data_unregister(token_handle);
  77. starpu_mpi_shutdown();
  78. starpu_shutdown();
  79. FPRINTF_MPI("Final value for token %d\n", token);
  80. MPI_Finalize();
  81. if (rank == 1)
  82. {
  83. STARPU_ASSERT_MSG(token == nloops, "token==%d != expected_value==%d\n", token, nloops);
  84. }
  85. else
  86. {
  87. STARPU_ASSERT_MSG(token == 0, "token==%d != expected_value==0\n", token);
  88. }
  89. return 0;
  90. }