insert_task_dyn_handles.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013, 2014 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 <config.h>
  17. #include <starpu_mpi.h>
  18. #include <starpu_config.h>
  19. #include "helper.h"
  20. void func_cpu(void *descr[], void *_args)
  21. {
  22. int num = starpu_task_get_current()->nbuffers;
  23. int i;
  24. for (i = 0; i < num; i++)
  25. {
  26. int *x = (int *)STARPU_VARIABLE_GET_PTR(descr[i]);
  27. *x = *x + 1;
  28. }
  29. }
  30. struct starpu_codelet codelet =
  31. {
  32. .cpu_funcs = {func_cpu},
  33. .cpu_funcs_name = {"func_cpu"},
  34. .nbuffers = STARPU_VARIABLE_NBUFFERS,
  35. };
  36. int main(int argc, char **argv)
  37. {
  38. int *x;
  39. int i, ret, loop;
  40. int rank;
  41. #ifdef STARPU_QUICK_CHECK
  42. int nloops = 4;
  43. #else
  44. int nloops = 16;
  45. #endif
  46. starpu_data_handle_t *data_handles;
  47. struct starpu_data_descr *descrs;
  48. MPI_Init(&argc, &argv);
  49. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  50. ret = starpu_init(NULL);
  51. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  52. ret = starpu_mpi_init(NULL, NULL, 0);
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  54. x = calloc(1, (STARPU_NMAXBUFS+15) * sizeof(int));
  55. data_handles = malloc((STARPU_NMAXBUFS+15) * sizeof(starpu_data_handle_t));
  56. descrs = malloc((STARPU_NMAXBUFS+15) * sizeof(struct starpu_data_descr));
  57. for(i=0 ; i<STARPU_NMAXBUFS+15 ; i++)
  58. {
  59. starpu_variable_data_register(&data_handles[i], STARPU_MAIN_RAM, (uintptr_t)&x[i], sizeof(x[i]));
  60. starpu_mpi_data_register(data_handles[i], i, 0);
  61. descrs[i].handle = data_handles[i];
  62. descrs[i].mode = STARPU_RW;
  63. }
  64. for (loop = 0; loop < nloops; loop++)
  65. {
  66. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &codelet,
  67. STARPU_DATA_MODE_ARRAY, descrs, STARPU_NMAXBUFS-1,
  68. 0);
  69. if (ret == -ENODEV) goto enodev;
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  71. ret = starpu_mpi_task_insert(MPI_COMM_WORLD, &codelet,
  72. STARPU_DATA_MODE_ARRAY, descrs, STARPU_NMAXBUFS+15,
  73. 0);
  74. if (ret == -ENODEV) goto enodev;
  75. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_task_insert");
  76. }
  77. enodev:
  78. for(i=0 ; i<STARPU_NMAXBUFS+15 ; i++)
  79. {
  80. starpu_data_unregister(data_handles[i]);
  81. }
  82. free(data_handles);
  83. free(descrs);
  84. if (ret == -ENODEV)
  85. {
  86. fprintf(stderr, "WARNING: No one can execute this task\n");
  87. /* yes, we do not perform the computation but we did detect that no one
  88. * could perform the kernel, so this is not an error from StarPU */
  89. free(x);
  90. ret = STARPU_TEST_SKIPPED;
  91. }
  92. else if (rank == 0)
  93. {
  94. for(i=0 ; i<STARPU_NMAXBUFS-1 ; i++)
  95. {
  96. if (x[i] != nloops * 2)
  97. {
  98. FPRINTF_MPI("[end loop] value[%d] = %d != Expected value %d\n", i, x[i], nloops*2);
  99. ret = 1;
  100. }
  101. }
  102. for(i=STARPU_NMAXBUFS-1 ; i<STARPU_NMAXBUFS+15 ; i++)
  103. {
  104. if (x[i] != nloops)
  105. {
  106. FPRINTF_MPI("[end loop] value[%d] = %d != Expected value %d\n", i, x[i], nloops);
  107. ret = 1;
  108. }
  109. }
  110. if (ret == 0)
  111. {
  112. FPRINTF_MPI("[end of loop] all values are correct\n");
  113. }
  114. free(x);
  115. }
  116. else
  117. {
  118. FPRINTF_MPI("[end of loop] no computation on this node\n");
  119. ret = 0;
  120. }
  121. starpu_mpi_shutdown();
  122. starpu_shutdown();
  123. MPI_Finalize();
  124. return ret;
  125. }