insert_task_seq.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-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. #if !defined(STARPU_HAVE_SETENV)
  20. #warning setenv is not defined. Skipping test
  21. int main(int argc, char **argv)
  22. {
  23. return STARPU_TEST_SKIPPED;
  24. }
  25. #else
  26. void func_cpu(void *descr[], void *_args)
  27. {
  28. (void) descr;
  29. (void) _args;
  30. }
  31. struct starpu_codelet mycodelet =
  32. {
  33. .cpu_funcs = {func_cpu},
  34. .nbuffers = 2,
  35. .modes = {STARPU_RW, STARPU_R},
  36. .model = &starpu_perfmodel_nop,
  37. };
  38. struct starpu_codelet mycodelet2 =
  39. {
  40. .cpu_funcs = {func_cpu},
  41. .nbuffers = 1,
  42. .modes = {STARPU_RW},
  43. .model = &starpu_perfmodel_nop,
  44. };
  45. #define X 4
  46. /* Returns the MPI node number where data is */
  47. int my_distrib(int x, int nb_nodes)
  48. {
  49. return x % nb_nodes;
  50. }
  51. void dotest(int rank, int size, char *enabled)
  52. {
  53. int x, i;
  54. int ret;
  55. unsigned values[X];
  56. starpu_data_handle_t data_handles[X];
  57. setenv("STARPU_MPI_CACHE", enabled, 1);
  58. FPRINTF(stderr, "Testing with cache '%s'\n", enabled);
  59. ret = starpu_mpi_init_conf(NULL, NULL, 0, MPI_COMM_WORLD, NULL);
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init_conf");
  61. for(x = 0; x < X; x++)
  62. {
  63. values[x] = (rank+1)*10;
  64. }
  65. for(x = 0; x < X; x++)
  66. {
  67. int mpi_rank = my_distrib(x, size);
  68. if (mpi_rank == rank)
  69. {
  70. starpu_variable_data_register(&data_handles[x], STARPU_MAIN_RAM, (uintptr_t)&(values[x]), sizeof(unsigned));
  71. }
  72. else
  73. {
  74. /* I don't own this index, but will need it for my computations */
  75. starpu_variable_data_register(&data_handles[x], -1, (uintptr_t)NULL, sizeof(unsigned));
  76. }
  77. if (data_handles[x])
  78. {
  79. starpu_mpi_data_register(data_handles[x], x, mpi_rank);
  80. }
  81. }
  82. for(i = 0 ; i<size ; i++)
  83. {
  84. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[i], STARPU_R, data_handles[0], 0);
  85. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  86. }
  87. for(i = 0 ; i<size ; i++)
  88. {
  89. // Calling starpu_mpi_get_data_on_all_nodes_detached() is necessary to make sure all nodes have a valid copy of the data
  90. starpu_mpi_get_data_on_all_nodes_detached(MPI_COMM_WORLD, data_handles[i]);
  91. starpu_task_insert(&mycodelet2, STARPU_RW, data_handles[i], 0);
  92. }
  93. starpu_task_wait_for_all();
  94. for(x = 0; x < X; x++)
  95. {
  96. STARPU_ASSERT(data_handles[x]);
  97. starpu_data_unregister(data_handles[x]);
  98. }
  99. starpu_mpi_shutdown();
  100. }
  101. int main(int argc, char **argv)
  102. {
  103. int rank, size;
  104. MPI_INIT_THREAD_real(&argc, &argv, MPI_THREAD_SERIALIZED);
  105. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  106. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  107. dotest(rank, size, "0");
  108. dotest(rank, size, "1");
  109. MPI_Finalize();
  110. return 0;
  111. }
  112. #endif