cache.c 3.3 KB

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