mpi_decomposition_matrix.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013,2015-2017 CNRS
  4. * Copyright (C) 2009-2012,2014,2015,2020 Université de Bordeaux
  5. * Copyright (C) 2010 Mehdi Juhoor
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include "mpi_cholesky.h"
  19. /* Returns the MPI node number where data indexes index is */
  20. int my_distrib(int y, int x, int nb_nodes)
  21. {
  22. (void)nb_nodes;
  23. //return (x+y) % nb_nodes;
  24. return (x%dblockx)+(y%dblocky)*dblockx;
  25. }
  26. void matrix_display(float ***bmat, int rank)
  27. {
  28. if (display)
  29. {
  30. unsigned y;
  31. printf("[%d] Input :\n", rank);
  32. for(y=0 ; y<nblocks ; y++)
  33. {
  34. unsigned x;
  35. for(x=0 ; x<nblocks ; x++)
  36. {
  37. unsigned j;
  38. printf("Block %u,%u :\n", x, y);
  39. for (j = 0; j < BLOCKSIZE; j++)
  40. {
  41. unsigned i;
  42. for (i = 0; i < BLOCKSIZE; i++)
  43. {
  44. if (i <= j)
  45. {
  46. printf("%2.2f\t", bmat[y][x][j +i*BLOCKSIZE]);
  47. }
  48. else
  49. {
  50. printf(".\t");
  51. }
  52. }
  53. printf("\n");
  54. }
  55. }
  56. }
  57. }
  58. }
  59. /* Note: bmat is indexed by bmat[m][n][mm+nn*BLOCKSIZE],
  60. * i.e. the content of the tiles is column-major, but the array of tiles is
  61. * row-major to keep the m,n notation everywhere */
  62. void matrix_init(float ****bmat, int rank, int nodes, int alloc_everywhere)
  63. {
  64. unsigned nn,mm,m,n;
  65. *bmat = malloc(nblocks * sizeof(float **));
  66. for(m=0 ; m<nblocks ; m++)
  67. {
  68. (*bmat)[m] = malloc(nblocks * sizeof(float *));
  69. for(n=0 ; n<nblocks ; n++)
  70. {
  71. int mpi_rank = my_distrib(m, n, nodes);
  72. if (alloc_everywhere || (mpi_rank == rank))
  73. {
  74. starpu_malloc((void **)&(*bmat)[m][n], BLOCKSIZE*BLOCKSIZE*sizeof(float));
  75. for (nn = 0; nn < BLOCKSIZE; nn++)
  76. {
  77. for (mm = 0; mm < BLOCKSIZE; mm++)
  78. {
  79. #ifndef STARPU_SIMGRID
  80. (*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);
  81. //mat[mm +nn*size] = ((nn == mm)?1.0f*size:0.0f);
  82. #endif
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. void matrix_free(float ****bmat, int rank, int nodes, int alloc_everywhere)
  90. {
  91. unsigned m, n;
  92. for(m=0 ; m<nblocks ; m++)
  93. {
  94. for(n=0 ; n<nblocks ; n++)
  95. {
  96. int mpi_rank = my_distrib(m, n, nodes);
  97. if (alloc_everywhere || (mpi_rank == rank))
  98. {
  99. starpu_free((void *)(*bmat)[m][n]);
  100. }
  101. }
  102. free((*bmat)[m]);
  103. }
  104. free(*bmat);
  105. }