cache.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-2021 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 <math.h>
  18. #include "helper.h"
  19. void func_cpu(void *descr[], void *_args)
  20. {
  21. (void)descr;
  22. (void)_args;
  23. }
  24. struct starpu_codelet mycodelet_r =
  25. {
  26. .cpu_funcs = {func_cpu},
  27. .nbuffers = 1,
  28. .modes = {STARPU_R},
  29. .model = &starpu_perfmodel_nop,
  30. };
  31. struct starpu_codelet mycodelet_w =
  32. {
  33. .cpu_funcs = {func_cpu},
  34. .nbuffers = 1,
  35. .modes = {STARPU_W},
  36. .model = &starpu_perfmodel_nop,
  37. };
  38. struct starpu_codelet mycodelet_rw =
  39. {
  40. .cpu_funcs = {func_cpu},
  41. .nbuffers = 1,
  42. .modes = {STARPU_RW},
  43. .model = &starpu_perfmodel_nop,
  44. };
  45. void test(struct starpu_codelet *codelet, enum starpu_data_access_mode mode, starpu_data_handle_t data, int rank, int in_cache)
  46. {
  47. int cache;
  48. int ret;
  49. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, codelet, mode, data, STARPU_EXECUTE_ON_NODE, 1, 0);
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  51. cache = starpu_mpi_cached_receive(data);
  52. if (rank == 1)
  53. {
  54. if (in_cache)
  55. {
  56. STARPU_ASSERT_MSG(cache == 1, "Data should be in cache\n");
  57. }
  58. else
  59. {
  60. STARPU_ASSERT_MSG(cache == 0, "Data should NOT be in cache\n");
  61. }
  62. }
  63. }
  64. int main(int argc, char **argv)
  65. {
  66. int rank;
  67. int ret;
  68. unsigned val = 42;
  69. starpu_data_handle_t data;
  70. ret = starpu_mpi_init_conf(&argc, &argv, 1, MPI_COMM_WORLD, NULL);
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  72. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  73. if (starpu_mpi_cache_is_enabled() == 0)
  74. goto skip;
  75. if (rank == 0)
  76. starpu_variable_data_register(&data, STARPU_MAIN_RAM, (uintptr_t)&val, sizeof(unsigned));
  77. else
  78. starpu_variable_data_register(&data, -1, (uintptr_t)NULL, sizeof(unsigned));
  79. starpu_mpi_data_register(data, 42, 0);
  80. FPRINTF_MPI(stderr, "Registering data %p with tag %d and node %d\n", data, 42, 0);
  81. // We use the same data with different access modes and we check if it is
  82. // available or not in the cache
  83. test(&mycodelet_r, STARPU_R, data, rank, 1);
  84. test(&mycodelet_rw, STARPU_RW, data, rank, 0);
  85. test(&mycodelet_r, STARPU_R, data, rank, 1);
  86. test(&mycodelet_r, STARPU_R, data, rank, 1);
  87. test(&mycodelet_w, STARPU_W, data, rank, 0);
  88. FPRINTF(stderr, "Waiting ...\n");
  89. starpu_task_wait_for_all();
  90. starpu_data_unregister(data);
  91. skip:
  92. starpu_mpi_shutdown();
  93. return starpu_mpi_cache_is_enabled() == 0 ? STARPU_TEST_SKIPPED : 0;
  94. }