mpi_cholesky_codelets.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  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 "mpi_cholesky_params.h"
  19. #include "mpi_cholesky_models.h"
  20. #include "mpi_cholesky_codelets.h"
  21. #include "mpi_cholesky_kernels.h"
  22. /*
  23. * Create the codelets
  24. */
  25. static struct starpu_codelet cl11 =
  26. {
  27. .where = STARPU_CPU|STARPU_CUDA,
  28. .cpu_funcs = {chol_cpu_codelet_update_u11, NULL},
  29. #ifdef STARPU_USE_CUDA
  30. .cuda_funcs = {chol_cublas_codelet_update_u11, NULL},
  31. #endif
  32. .nbuffers = 1,
  33. .modes = {STARPU_RW},
  34. .model = &chol_model_11
  35. };
  36. static struct starpu_codelet cl21 =
  37. {
  38. .where = STARPU_CPU|STARPU_CUDA,
  39. .cpu_funcs = {chol_cpu_codelet_update_u21, NULL},
  40. #ifdef STARPU_USE_CUDA
  41. .cuda_funcs = {chol_cublas_codelet_update_u21, NULL},
  42. #endif
  43. .nbuffers = 2,
  44. .modes = {STARPU_R, STARPU_RW},
  45. .model = &chol_model_21
  46. };
  47. static struct starpu_codelet cl22 =
  48. {
  49. .where = STARPU_CPU|STARPU_CUDA,
  50. .cpu_funcs = {chol_cpu_codelet_update_u22, NULL},
  51. #ifdef STARPU_USE_CUDA
  52. .cuda_funcs = {chol_cublas_codelet_update_u22, NULL},
  53. #endif
  54. .nbuffers = 3,
  55. .modes = {STARPU_R, STARPU_R, STARPU_RW},
  56. .model = &chol_model_22
  57. };
  58. /* Returns the MPI node number where data indexes index is */
  59. int my_distrib(int x, int y, int nb_nodes)
  60. {
  61. //return (x+y) % nb_nodes;
  62. return (x%dblockx)+(y%dblocky)*dblockx;
  63. }
  64. /*
  65. * code to bootstrap the factorization
  66. * and construct the DAG
  67. */
  68. void dw_cholesky(float ***matA, unsigned size, unsigned ld, unsigned nblocks, int rank, int nodes, double *timing, double *flops)
  69. {
  70. struct timeval start;
  71. struct timeval end;
  72. starpu_data_handle_t **data_handles;
  73. int x, y;
  74. /* create all the DAG nodes */
  75. unsigned i,j,k;
  76. data_handles = malloc(nblocks*sizeof(starpu_data_handle_t *));
  77. for(x=0 ; x<nblocks ; x++) data_handles[x] = malloc(nblocks*sizeof(starpu_data_handle_t));
  78. for(x = 0; x < nblocks ; x++)
  79. {
  80. for (y = 0; y < nblocks; y++)
  81. {
  82. int mpi_rank = my_distrib(x, y, nodes);
  83. if (mpi_rank == rank)
  84. {
  85. //fprintf(stderr, "[%d] Owning data[%d][%d]\n", rank, x, y);
  86. starpu_matrix_data_register(&data_handles[x][y], 0, (uintptr_t)matA[x][y],
  87. ld, size/nblocks, size/nblocks, sizeof(float));
  88. }
  89. #warning TODO: make better test to only register what is needed
  90. else
  91. {
  92. /* I don't own that index, but will need it for my computations */
  93. //fprintf(stderr, "[%d] Neighbour of data[%d][%d]\n", rank, x, y);
  94. starpu_matrix_data_register(&data_handles[x][y], -1, (uintptr_t)NULL,
  95. ld, size/nblocks, size/nblocks, sizeof(float));
  96. }
  97. if (data_handles[x][y])
  98. {
  99. starpu_data_set_rank(data_handles[x][y], mpi_rank);
  100. starpu_data_set_tag(data_handles[x][y], (y*nblocks)+x);
  101. }
  102. }
  103. }
  104. starpu_mpi_barrier(MPI_COMM_WORLD);
  105. gettimeofday(&start, NULL);
  106. for (k = 0; k < nblocks; k++)
  107. {
  108. int prio = STARPU_DEFAULT_PRIO;
  109. if (!noprio) prio = STARPU_MAX_PRIO;
  110. starpu_mpi_insert_task(MPI_COMM_WORLD, &cl11,
  111. STARPU_PRIORITY, prio,
  112. STARPU_RW, data_handles[k][k],
  113. 0);
  114. for (j = k+1; j<nblocks; j++)
  115. {
  116. prio = STARPU_DEFAULT_PRIO;
  117. if (!noprio&& (j == k+1)) prio = STARPU_MAX_PRIO;
  118. starpu_mpi_insert_task(MPI_COMM_WORLD, &cl21,
  119. STARPU_PRIORITY, prio,
  120. STARPU_R, data_handles[k][k],
  121. STARPU_RW, data_handles[k][j],
  122. 0);
  123. for (i = k+1; i<nblocks; i++)
  124. {
  125. if (i <= j)
  126. {
  127. prio = STARPU_DEFAULT_PRIO;
  128. if (!noprio && (i == k + 1) && (j == k +1) ) prio = STARPU_MAX_PRIO;
  129. starpu_mpi_insert_task(MPI_COMM_WORLD, &cl22,
  130. STARPU_PRIORITY, prio,
  131. STARPU_R, data_handles[k][i],
  132. STARPU_R, data_handles[k][j],
  133. STARPU_RW, data_handles[i][j],
  134. 0);
  135. }
  136. }
  137. }
  138. }
  139. starpu_task_wait_for_all();
  140. for(x = 0; x < nblocks ; x++)
  141. {
  142. for (y = 0; y < nblocks; y++)
  143. {
  144. if (data_handles[x][y])
  145. starpu_data_unregister(data_handles[x][y]);
  146. }
  147. free(data_handles[x]);
  148. }
  149. free(data_handles);
  150. starpu_mpi_barrier(MPI_COMM_WORLD);
  151. gettimeofday(&end, NULL);
  152. if (rank == 0)
  153. {
  154. double timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  155. fprintf(stdout, "Computation time (in ms): %2.2f\n", timing/1000);
  156. double flop = (1.0f*size*size*size)/3.0f;
  157. fprintf(stdout, "Synthetic GFlops : %2.2f\n", (flop/timing/1000.0f));
  158. }
  159. }