cache_disable.c 2.7 KB

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