insert_task_seq.c 3.2 KB

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