mpi_decomposition_matrix.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2010 Mehdi Juhoor
  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 "mpi_cholesky.h"
  18. /* Returns the MPI node number where data indexes index is */
  19. int my_distrib(int y, int x, int nb_nodes)
  20. {
  21. (void)nb_nodes;
  22. //return (x+y) % nb_nodes;
  23. return (x%dblockx)+(y%dblocky)*dblockx;
  24. }
  25. void matrix_display(float ***bmat, int rank)
  26. {
  27. if (display)
  28. {
  29. unsigned y;
  30. printf("[%d] Input :\n", rank);
  31. for(y=0 ; y<nblocks ; y++)
  32. {
  33. unsigned x;
  34. for(x=0 ; x<nblocks ; x++)
  35. {
  36. unsigned j;
  37. printf("Block %u,%u :\n", x, y);
  38. for (j = 0; j < BLOCKSIZE; j++)
  39. {
  40. unsigned i;
  41. for (i = 0; i < BLOCKSIZE; i++)
  42. {
  43. if (i <= j)
  44. {
  45. printf("%2.2f\t", bmat[y][x][j +i*BLOCKSIZE]);
  46. }
  47. else
  48. {
  49. printf(".\t");
  50. }
  51. }
  52. printf("\n");
  53. }
  54. }
  55. }
  56. }
  57. }
  58. /* Note: bmat is indexed by bmat[m][n][mm+nn*BLOCKSIZE],
  59. * i.e. the content of the tiles is column-major, but the array of tiles is
  60. * row-major to keep the m,n notation everywhere */
  61. void matrix_init(float ****bmat, int rank, int nodes, int alloc_everywhere)
  62. {
  63. unsigned nn,mm,m,n;
  64. *bmat = malloc(nblocks * sizeof(float **));
  65. for(m=0 ; m<nblocks ; m++)
  66. {
  67. (*bmat)[m] = malloc(nblocks * sizeof(float *));
  68. for(n=0 ; n<nblocks ; n++)
  69. {
  70. int mpi_rank = my_distrib(m, n, nodes);
  71. if (alloc_everywhere || (mpi_rank == rank))
  72. {
  73. starpu_malloc((void **)&(*bmat)[m][n], BLOCKSIZE*BLOCKSIZE*sizeof(float));
  74. for (nn = 0; nn < BLOCKSIZE; nn++)
  75. {
  76. for (mm = 0; mm < BLOCKSIZE; mm++)
  77. {
  78. #ifndef STARPU_SIMGRID
  79. (*bmat)[m][n][mm +nn*BLOCKSIZE] = (1.0f/(1.0f+(nn+(m*BLOCKSIZE)+mm+(n*BLOCKSIZE)))) + ((nn+(m*BLOCKSIZE) == mm+(n*BLOCKSIZE))?1.0f*size:0.0f);
  80. //mat[mm +nn*size] = ((nn == mm)?1.0f*size:0.0f);
  81. #endif
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. void matrix_free(float ****bmat, int rank, int nodes, int alloc_everywhere)
  89. {
  90. unsigned m, n;
  91. for(m=0 ; m<nblocks ; m++)
  92. {
  93. for(n=0 ; n<nblocks ; n++)
  94. {
  95. int mpi_rank = my_distrib(m, n, nodes);
  96. if (alloc_everywhere || (mpi_rank == rank))
  97. {
  98. starpu_free((void *)(*bmat)[m][n]);
  99. }
  100. }
  101. free((*bmat)[m]);
  102. }
  103. free(*bmat);
  104. }