mpi_cholesky_codelets.c 4.6 KB

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