cache_disable.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015 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. struct starpu_codelet mycodelet_r =
  24. {
  25. .cpu_funcs = {func_cpu},
  26. .nbuffers = 1,
  27. .modes = {STARPU_R}
  28. };
  29. int main(int argc, char **argv)
  30. {
  31. int rank, n;
  32. int ret;
  33. unsigned val;
  34. starpu_data_handle_t data;
  35. void *ptr;
  36. int cache;
  37. ret = starpu_init(NULL);
  38. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  39. ret = starpu_mpi_init(&argc, &argv, 1);
  40. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  41. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  42. cache = starpu_mpi_cache_is_enabled();
  43. if (cache == 0) goto skip;
  44. if (rank == 0)
  45. starpu_variable_data_register(&data, STARPU_MAIN_RAM, (uintptr_t)&val, sizeof(unsigned));
  46. else
  47. starpu_variable_data_register(&data, -1, (uintptr_t)NULL, sizeof(unsigned));
  48. starpu_mpi_data_register(data, 42, 0);
  49. FPRINTF_MPI(stderr, "Registering data %p with tag %d and node %d\n", data, 42, 0);
  50. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r, STARPU_R, data, STARPU_EXECUTE_ON_NODE, 1, 0);
  51. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  52. ptr = _starpu_mpi_cache_received_data_get(data, 0);
  53. if (rank == 1)
  54. {
  55. STARPU_ASSERT_MSG(ptr != NULL, "Data should be in cache\n");
  56. }
  57. // We clean the cache
  58. starpu_mpi_cache_set(0);
  59. // We check the data is no longer in the cache
  60. ptr = _starpu_mpi_cache_received_data_get(data, 0);
  61. if (rank == 1)
  62. {
  63. STARPU_ASSERT_MSG(ptr == NULL, "Data should NOT be in cache\n");
  64. }
  65. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet_r, STARPU_R, data, STARPU_EXECUTE_ON_NODE, 1, 0);
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  67. ptr = _starpu_mpi_cache_received_data_get(data, 0);
  68. if (rank == 1)
  69. {
  70. STARPU_ASSERT_MSG(ptr == NULL, "Data should NOT be in cache\n");
  71. }
  72. FPRINTF(stderr, "Waiting ...\n");
  73. starpu_task_wait_for_all();
  74. starpu_data_unregister(data);
  75. skip:
  76. starpu_mpi_shutdown();
  77. starpu_shutdown();
  78. return cache == 0 ? STARPU_TEST_SKIPPED : 0;
  79. }