mpi_cholesky_distributed.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. }
  27. int main(int argc, char **argv)
  28. {
  29. /* create a simple definite positive symetric matrix example
  30. *
  31. * Hilbert matrix : h(i,j) = 1/(i+j+1)
  32. * */
  33. float ***bmat;
  34. int rank, nodes;
  35. parse_args(argc, argv);
  36. struct starpu_conf conf;
  37. starpu_conf_init(&conf);
  38. conf.sched_policy_name = "heft";
  39. conf.calibrate = 1;
  40. int ret = starpu_init(&conf);
  41. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  42. starpu_mpi_initialize_extended(&rank, &nodes);
  43. starpu_helper_cublas_init();
  44. unsigned i,j,x,y;
  45. bmat = malloc(nblocks * sizeof(float *));
  46. for(x=0 ; x<nblocks ; x++)
  47. {
  48. bmat[x] = malloc(nblocks * sizeof(float *));
  49. for(y=0 ; y<nblocks ; y++)
  50. {
  51. int mpi_rank = my_distrib(x, y, nodes);
  52. if (mpi_rank == rank)
  53. {
  54. starpu_malloc((void **)&bmat[x][y], BLOCKSIZE*BLOCKSIZE*sizeof(float));
  55. for (i = 0; i < BLOCKSIZE; i++)
  56. {
  57. for (j = 0; j < BLOCKSIZE; j++)
  58. {
  59. 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);
  60. //mat[j +i*size] = ((i == j)?1.0f*size:0.0f);
  61. }
  62. }
  63. }
  64. }
  65. }
  66. dw_cholesky(bmat, size, size/nblocks, nblocks, rank, nodes);
  67. starpu_mpi_shutdown();
  68. for(x=0 ; x<nblocks ; x++)
  69. {
  70. for(y=0 ; y<nblocks ; y++)
  71. {
  72. int mpi_rank = my_distrib(x, y, nodes);
  73. if (mpi_rank == rank)
  74. {
  75. starpu_free((void *)bmat[x][y]);
  76. }
  77. }
  78. free(bmat[x]);
  79. }
  80. free(bmat);
  81. starpu_helper_cublas_shutdown();
  82. starpu_shutdown();
  83. return 0;
  84. }