mpi_cholesky_distributed.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
  5. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  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 <starpu_mpi.h>
  19. #include "mpi_cholesky.h"
  20. #include "mpi_cholesky_models.h"
  21. #include "mpi_cholesky_codelets.h"
  22. /* Returns the MPI node number where data indexes index is */
  23. int my_distrib(int x, int y, int nb_nodes)
  24. {
  25. //return (x+y) % nb_nodes;
  26. return (x%dblockx)+(y%dblocky)*dblockx;
  27. }
  28. int main(int argc, char **argv)
  29. {
  30. /* create a simple definite positive symetric matrix example
  31. *
  32. * Hilbert matrix : h(i,j) = 1/(i+j+1)
  33. * */
  34. float ***bmat;
  35. int rank, nodes, ret;
  36. parse_args(argc, argv);
  37. ret = starpu_init(NULL);
  38. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  39. starpu_mpi_initialize_extended(&rank, &nodes);
  40. starpu_helper_cublas_init();
  41. if (dblockx == -1 || dblocky == -1)
  42. {
  43. int factor;
  44. dblockx = nodes;
  45. dblocky = 1;
  46. for(factor=sqrt(nodes) ; factor>1 ; factor--)
  47. {
  48. if (nodes % factor == 0)
  49. {
  50. dblockx = nodes/factor;
  51. dblocky = factor;
  52. break;
  53. }
  54. }
  55. }
  56. unsigned i,j,x,y;
  57. bmat = malloc(nblocks * sizeof(float *));
  58. for(x=0 ; x<nblocks ; x++)
  59. {
  60. bmat[x] = malloc(nblocks * sizeof(float *));
  61. for(y=0 ; y<nblocks ; y++)
  62. {
  63. int mpi_rank = my_distrib(x, y, nodes);
  64. if (mpi_rank == rank)
  65. {
  66. starpu_malloc((void **)&bmat[x][y], BLOCKSIZE*BLOCKSIZE*sizeof(float));
  67. for (i = 0; i < BLOCKSIZE; i++)
  68. {
  69. for (j = 0; j < BLOCKSIZE; j++)
  70. {
  71. 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);
  72. //mat[j +i*size] = ((i == j)?1.0f*size:0.0f);
  73. }
  74. }
  75. }
  76. }
  77. }
  78. double timing, flops;
  79. dw_cholesky(bmat, size, size/nblocks, nblocks, rank, nodes, &timing, &flops);
  80. starpu_mpi_shutdown();
  81. if (rank == 0)
  82. {
  83. fprintf(stdout, "Computation time (in ms): %2.2f\n", timing/1000);
  84. fprintf(stdout, "Synthetic GFlops : %2.2f\n", (flops/timing/1000.0f));
  85. }
  86. for(x=0 ; x<nblocks ; x++)
  87. {
  88. for(y=0 ; y<nblocks ; y++)
  89. {
  90. int mpi_rank = my_distrib(x, y, nodes);
  91. if (mpi_rank == rank)
  92. {
  93. starpu_free((void *)bmat[x][y]);
  94. }
  95. }
  96. free(bmat[x]);
  97. }
  98. free(bmat);
  99. starpu_helper_cublas_shutdown();
  100. starpu_shutdown();
  101. return 0;
  102. }