mpi_decomposition_matrix.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2012, 2015 Université de Bordeaux
  4. * Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
  5. * Copyright (C) 2010, 2011, 2012, 2013, 2015 CNRS
  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 x, int y, int nb_nodes)
  21. {
  22. //return (x+y) % nb_nodes;
  23. return (x%dblockx)+(y%dblocky)*dblockx;
  24. }
  25. void matrix_display(float ***bmat, int rank)
  26. {
  27. unsigned i,j,x,y;
  28. if (display)
  29. {
  30. printf("[%d] Input :\n", rank);
  31. for(y=0 ; y<nblocks ; y++)
  32. {
  33. for(x=0 ; x<nblocks ; x++)
  34. {
  35. printf("Block %u,%u :\n", x, y);
  36. for (j = 0; j < BLOCKSIZE; j++)
  37. {
  38. for (i = 0; i < BLOCKSIZE; i++)
  39. {
  40. if (i <= j)
  41. {
  42. printf("%2.2f\t", bmat[y][x][j +i*BLOCKSIZE]);
  43. }
  44. else
  45. {
  46. printf(".\t");
  47. }
  48. }
  49. printf("\n");
  50. }
  51. }
  52. }
  53. }
  54. }
  55. void matrix_init(float ****bmat, int rank, int nodes, int alloc_everywhere)
  56. {
  57. unsigned i,j,x,y;
  58. *bmat = malloc(nblocks * sizeof(float **));
  59. for(x=0 ; x<nblocks ; x++)
  60. {
  61. (*bmat)[x] = malloc(nblocks * sizeof(float *));
  62. for(y=0 ; y<nblocks ; y++)
  63. {
  64. int mpi_rank = my_distrib(x, y, nodes);
  65. if (alloc_everywhere || (mpi_rank == rank))
  66. {
  67. starpu_malloc((void **)&(*bmat)[x][y], BLOCKSIZE*BLOCKSIZE*sizeof(float));
  68. for (i = 0; i < BLOCKSIZE; i++)
  69. {
  70. for (j = 0; j < BLOCKSIZE; j++)
  71. {
  72. (*bmat)[x][y][j +i*BLOCKSIZE] = (1.0f/(1.0f+(i+(x*BLOCKSIZE)+j+(y*BLOCKSIZE)))) + ((i+(x*BLOCKSIZE) == j+(y*BLOCKSIZE))?1.0f*size:0.0f);
  73. //mat[j +i*size] = ((i == j)?1.0f*size:0.0f);
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
  80. void matrix_free(float ****bmat, int rank, int nodes, int alloc_everywhere)
  81. {
  82. unsigned x, y;
  83. for(x=0 ; x<nblocks ; x++)
  84. {
  85. for(y=0 ; y<nblocks ; y++)
  86. {
  87. int mpi_rank = my_distrib(x, y, nodes);
  88. if (alloc_everywhere || (mpi_rank == rank))
  89. {
  90. starpu_free((void *)(*bmat)[x][y]);
  91. }
  92. }
  93. free((*bmat)[x]);
  94. }
  95. free(*bmat);
  96. }