cache_disable.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-2017 CNRS
  4. * Copyright (C) 2015,2017 Université de Bordeaux
  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 <math.h>
  19. #include "helper.h"
  20. #include <starpu_mpi_cache.h>
  21. void func_cpu(void *descr[], void *_args)
  22. {
  23. (void)descr;
  24. (void)_args;
  25. }
  26. struct starpu_codelet mycodelet_r =
  27. {
  28. .cpu_funcs = {func_cpu},
  29. .nbuffers = 1,
  30. .modes = {STARPU_R},
  31. .model = &starpu_perfmodel_nop,
  32. };
  33. int main(int argc, char **argv)
  34. {
  35. int rank, n;
  36. int ret;
  37. unsigned *val;
  38. starpu_data_handle_t data;
  39. int in_cache;
  40. int cache;
  41. ret = starpu_init(NULL);
  42. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  43. ret = starpu_mpi_init(&argc, &argv, 1);
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  45. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  46. cache = starpu_mpi_cache_is_enabled();
  47. if (cache == 0)
  48. goto skip;
  49. val = malloc(sizeof(*val));
  50. *val = 12;
  51. if (rank == 0)
  52. starpu_variable_data_register(&data, STARPU_MAIN_RAM, (uintptr_t)val, sizeof(unsigned));
  53. else
  54. starpu_variable_data_register(&data, -1, (uintptr_t)NULL, sizeof(unsigned));
  55. starpu_mpi_data_register(data, 42, 0);
  56. FPRINTF_MPI(stderr, "Registering data %p with tag %d and node %d\n", data, 42, 0);
  57. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r, STARPU_R, data, STARPU_EXECUTE_ON_NODE, 1, 0);
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  59. in_cache = _starpu_mpi_cache_received_data_get(data);
  60. if (rank == 1)
  61. {
  62. STARPU_ASSERT_MSG(in_cache == 1, "Data should be in cache\n");
  63. }
  64. // We clean the cache
  65. starpu_mpi_cache_set(0);
  66. // We check the data is no longer in the cache
  67. in_cache = _starpu_mpi_cache_received_data_get(data);
  68. if (rank == 1)
  69. {
  70. STARPU_ASSERT_MSG(in_cache == 0, "Data should NOT be in cache\n");
  71. }
  72. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r, STARPU_R, data, STARPU_EXECUTE_ON_NODE, 1, 0);
  73. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  74. in_cache = _starpu_mpi_cache_received_data_get(data);
  75. if (rank == 1)
  76. {
  77. STARPU_ASSERT_MSG(in_cache == 0, "Data should NOT be in cache\n");
  78. }
  79. FPRINTF(stderr, "Waiting ...\n");
  80. starpu_task_wait_for_all();
  81. starpu_data_unregister(data);
  82. free(val);
  83. skip:
  84. starpu_mpi_shutdown();
  85. starpu_shutdown();
  86. return cache == 0 ? STARPU_TEST_SKIPPED : 0;
  87. }