policy_selection2.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015, 2016 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 "helper.h"
  18. void func_cpu(void *descr[], void *_args)
  19. {
  20. (void)_args;
  21. int *data0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. int *data1 = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  23. int *data2 = (int *)STARPU_VARIABLE_GET_PTR(descr[2]);
  24. *data1 += *data0;
  25. *data2 += *data0;
  26. }
  27. /* Dummy cost function for simgrid */
  28. static double cost_function(struct starpu_task *task STARPU_ATTRIBUTE_UNUSED, unsigned nimpl STARPU_ATTRIBUTE_UNUSED)
  29. {
  30. return 0.000001;
  31. }
  32. static struct starpu_perfmodel dumb_model =
  33. {
  34. .type = STARPU_COMMON,
  35. .cost_function = cost_function
  36. };
  37. struct starpu_codelet mycodelet =
  38. {
  39. .cpu_funcs = {func_cpu},
  40. .nbuffers = 3,
  41. .modes = {STARPU_R, STARPU_W, STARPU_W},
  42. .model = &dumb_model
  43. };
  44. int main(int argc, char **argv)
  45. {
  46. int ret;
  47. int i;
  48. int rank, size;
  49. struct starpu_task *task;
  50. int data[3];
  51. starpu_data_handle_t handles[3];
  52. MPI_Init(&argc, &argv);
  53. starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
  54. starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
  55. ret = starpu_init(NULL);
  56. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  57. ret = starpu_mpi_init(NULL, NULL, 0);
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  59. if ((size < 3) || (starpu_cpu_worker_get_count() == 0))
  60. {
  61. if (rank == 0)
  62. {
  63. if (size < 3)
  64. FPRINTF(stderr, "We need at least 3 processes.\n");
  65. else
  66. FPRINTF(stderr, "We need at least 1 CPU worker.\n");
  67. }
  68. starpu_mpi_shutdown();
  69. starpu_shutdown();
  70. MPI_Finalize();
  71. return STARPU_TEST_SKIPPED;
  72. }
  73. data[0] = 12;
  74. starpu_variable_data_register(&handles[0], STARPU_MAIN_RAM, (uintptr_t)&data[0], sizeof(int));
  75. starpu_mpi_data_register(handles[0], 10, 0);
  76. data[1] = 12;
  77. starpu_variable_data_register(&handles[1], STARPU_MAIN_RAM, (uintptr_t)&data[1], sizeof(int));
  78. starpu_mpi_data_register(handles[1], 20, 1);
  79. data[2] = 12;
  80. starpu_variable_data_register(&handles[2], STARPU_MAIN_RAM, (uintptr_t)&data[2], sizeof(int));
  81. starpu_mpi_data_register(handles[2], 30, 2);
  82. starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  83. STARPU_R, handles[2], STARPU_W, handles[0], STARPU_W, handles[1],
  84. 0);
  85. for(i=0 ; i<2 ; i++) starpu_data_acquire(handles[i], STARPU_R);
  86. FPRINTF_MPI(stderr, "data[%d,%d,%d] = %d,%d,%d\n", 0, 1, 2, data[0], data[1], data[2]);
  87. for(i=0 ; i<2 ; i++) starpu_data_release(handles[i]);
  88. if (rank == 2)
  89. {
  90. STARPU_ASSERT_MSG(data[0] == 2*data[2] && data[1] == 2*data[2], "Computation incorrect. data[%d] (%d) != 2*data[%d] (%d) && data[%d] (%d) != 2*data[%d] (%d)\n",
  91. 0, data[0], 2, data[2], 1, data[1], 2, data[2]);
  92. }
  93. for(i=0 ; i<2 ; i++) starpu_data_acquire(handles[i], STARPU_W);
  94. for(i=0 ; i<2 ; i++) data[i] = 12;
  95. for(i=0 ; i<2 ; i++) starpu_data_release(handles[i]);
  96. // Let StarPU choose the node
  97. starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet,
  98. STARPU_R, handles[2], STARPU_W, handles[0], STARPU_W, handles[1],
  99. STARPU_EXECUTE_ON_NODE, 1,
  100. 0);
  101. for(i=0 ; i<2 ; i++) starpu_data_acquire(handles[i], STARPU_R);
  102. FPRINTF_MPI(stderr, "data[%d,%d,%d] = %d,%d,%d\n", 0, 1, 2, data[0], data[1], data[2]);
  103. for(i=0 ; i<2 ; i++) starpu_data_release(handles[i]);
  104. if (rank == 1)
  105. {
  106. STARPU_ASSERT_MSG(data[0] == 2*data[2] && data[1] == 2*data[2], "Computation incorrect. data[%d] (%d) != 2*data[%d] (%d) && data[%d] (%d) != 2*data[%d] (%d)\n",
  107. 0, data[0], 2, data[2], 1, data[1], 2, data[2]);
  108. }
  109. for(i=0 ; i<3 ; i++) starpu_data_unregister(handles[i]);
  110. starpu_mpi_shutdown();
  111. starpu_shutdown();
  112. MPI_Finalize();
  113. return 0;
  114. }