insert_task_cache.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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 <starpu_mpi.h>
  17. #include <math.h>
  18. void func_cpu(void *descr[], __attribute__ ((unused)) void *_args)
  19. {
  20. unsigned *x = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[0]);
  21. unsigned *y = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[1]);
  22. fprintf(stdout, "VALUES: %d %d\n", *x, *y);
  23. *x = (*x + *y) / 2;
  24. }
  25. starpu_codelet mycodelet = {
  26. .where = STARPU_CPU,
  27. .cpu_func = func_cpu,
  28. .nbuffers = 2
  29. };
  30. #define X 4
  31. #define Y 5
  32. /* Returns the MPI node number where data indexes index is */
  33. int my_distrib(int x, int y, int nb_nodes) {
  34. return x % nb_nodes;
  35. }
  36. int main(int argc, char **argv)
  37. {
  38. int rank, size, x, y;
  39. int value=0;
  40. unsigned matrix[X][Y];
  41. starpu_data_handle data_handles[X][Y];
  42. starpu_init(NULL);
  43. starpu_mpi_initialize_extended(&rank, &size);
  44. for(x = 0; x < X; x++) {
  45. for (y = 0; y < Y; y++) {
  46. matrix[x][y] = (rank+1)*10 + value;
  47. value++;
  48. }
  49. }
  50. #if 0
  51. for(x = 0; x < X; x++) {
  52. fprintf(stdout, "[%d] ", rank);
  53. for (y = 0; y < Y; y++) {
  54. fprintf(stdout, "%3d ", matrix[x][y]);
  55. }
  56. fprintf(stdout, "\n");
  57. }
  58. #endif
  59. for(x = 0; x < X; x++) {
  60. for (y = 0; y < Y; y++) {
  61. int mpi_rank = my_distrib(x, y, size);
  62. if (mpi_rank == rank) {
  63. //fprintf(stderr, "[%d] Owning data[%d][%d]\n", rank, x, y);
  64. starpu_variable_data_register(&data_handles[x][y], 0, (uintptr_t)&(matrix[x][y]), sizeof(unsigned));
  65. }
  66. else if (rank == mpi_rank+1 || rank == mpi_rank-1) {
  67. /* I don't own that index, but will need it for my computations */
  68. //fprintf(stderr, "[%d] Neighbour of data[%d][%d]\n", rank, x, y);
  69. starpu_variable_data_register(&data_handles[x][y], -1, (uintptr_t)NULL, sizeof(unsigned));
  70. }
  71. else {
  72. /* I know it's useless to allocate anything for this */
  73. data_handles[x][y] = NULL;
  74. }
  75. if (data_handles[x][y])
  76. starpu_data_set_rank(data_handles[x][y], mpi_rank);
  77. }
  78. }
  79. starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[1][1], STARPU_R, data_handles[0][1], 0);
  80. starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[3][1], STARPU_R, data_handles[0][1], 0);
  81. starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[0][1], STARPU_R, data_handles[0][0], 0);
  82. starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[3][1], STARPU_R, data_handles[0][1], 0);
  83. fprintf(stderr, "Waiting ...\n");
  84. starpu_task_wait_for_all();
  85. for(x = 0; x < X; x++) {
  86. for (y = 0; y < Y; y++) {
  87. if (data_handles[x][y])
  88. starpu_data_unregister(data_handles[x][y]);
  89. }
  90. }
  91. starpu_mpi_shutdown();
  92. starpu_shutdown();
  93. #if 0
  94. for(x = 0; x < X; x++) {
  95. fprintf(stdout, "[%d] ", rank);
  96. for (y = 0; y < Y; y++) {
  97. fprintf(stdout, "%3d ", matrix[x][y]);
  98. }
  99. fprintf(stdout, "\n");
  100. }
  101. #endif
  102. return 0;
  103. }