cache_disable.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. int main(int argc, char **argv)
  32. {
  33. int rank;
  34. int ret;
  35. unsigned *val;
  36. starpu_data_handle_t data;
  37. int in_cache;
  38. int cache;
  39. ret = starpu_mpi_init_conf(&argc, &argv, 1, MPI_COMM_WORLD, NULL);
  40. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  41. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  42. cache = starpu_mpi_cache_is_enabled();
  43. if (cache == 0)
  44. goto skip;
  45. val = malloc(sizeof(*val));
  46. *val = 12;
  47. if (rank == 0)
  48. starpu_variable_data_register(&data, STARPU_MAIN_RAM, (uintptr_t)val, sizeof(unsigned));
  49. else
  50. starpu_variable_data_register(&data, -1, (uintptr_t)NULL, sizeof(unsigned));
  51. starpu_mpi_data_register(data, 42, 0);
  52. FPRINTF_MPI(stderr, "Registering data %p with tag %d and node %d\n", data, 42, 0);
  53. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r, STARPU_R, data, STARPU_EXECUTE_ON_NODE, 1, 0);
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  55. in_cache = starpu_mpi_cached_receive(data);
  56. if (rank == 1)
  57. {
  58. STARPU_ASSERT_MSG(in_cache == 1, "Data should be in cache\n");
  59. }
  60. // We clean the cache
  61. starpu_mpi_cache_set(0);
  62. // We check the data is no longer in the cache
  63. in_cache = starpu_mpi_cached_receive(data);
  64. if (rank == 1)
  65. {
  66. STARPU_ASSERT_MSG(in_cache == 0, "Data should NOT be in cache\n");
  67. }
  68. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r, STARPU_R, data, STARPU_EXECUTE_ON_NODE, 1, 0);
  69. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  70. in_cache = starpu_mpi_cached_receive(data);
  71. if (rank == 1)
  72. {
  73. STARPU_ASSERT_MSG(in_cache == 0, "Data should NOT be in cache\n");
  74. }
  75. FPRINTF(stderr, "Waiting ...\n");
  76. starpu_task_wait_for_all();
  77. starpu_data_unregister(data);
  78. free(val);
  79. skip:
  80. starpu_mpi_shutdown();
  81. return cache == 0 ? STARPU_TEST_SKIPPED : 0;
  82. }