lazy_unregister.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2020 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.h>
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. #include "../helper.h"
  20. /*
  21. * Test that starpu_data_unregister_submit waits for both tasks to finish
  22. */
  23. void dummy_func(void ** buffers, void * args)
  24. {
  25. (void) buffers;
  26. (void) args;
  27. }
  28. static struct starpu_codelet dummy_cl =
  29. {
  30. .modes = { STARPU_RW },
  31. .cpu_funcs = { dummy_func },
  32. .cpu_funcs_name = { "dummy_func" },
  33. .nbuffers = 1
  34. };
  35. int main(void)
  36. {
  37. int ret;
  38. int buffer[1024];
  39. starpu_data_handle_t handle;
  40. struct starpu_task *t1,*t2;
  41. ret = starpu_init(NULL);
  42. if (ret == -ENODEV)
  43. return STARPU_TEST_SKIPPED;
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  45. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)buffer, 1024*sizeof(int));
  46. t1 = starpu_task_create();
  47. t2 = starpu_task_create();
  48. t2->cl = &dummy_cl;
  49. t2->detach = 0;
  50. t2->handles[0] = handle;
  51. starpu_task_declare_deps_array(t2, 1, &t1);
  52. ret = starpu_task_submit(t2);
  53. if (ret == -ENODEV)
  54. return STARPU_TEST_SKIPPED;
  55. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  56. starpu_data_unregister_submit(handle);
  57. /* Note: we have no way to know when this will happen. We have to wait
  58. * for starpu_shutdown before being able to free the registered buffer */
  59. ret = starpu_task_submit(t1);
  60. if (ret == -ENODEV)
  61. return STARPU_TEST_SKIPPED;
  62. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  63. ret = starpu_task_wait(t2);
  64. if (ret == -ENODEV)
  65. return STARPU_TEST_SKIPPED;
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait");
  67. while (starpu_data_lookup(buffer) != NULL)
  68. usleep(100000);
  69. starpu_shutdown();
  70. return EXIT_SUCCESS;
  71. }