mpi_cholesky.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010 Mehdi Juhoor <mjuhoor@gmail.com>
  5. * Copyright (C) 2010, 2011, 2012, 2013 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_params.h"
  20. #include "mpi_cholesky_models.h"
  21. #include "mpi_cholesky_codelets.h"
  22. int main(int argc, char **argv)
  23. {
  24. /* create a simple definite positive symetric matrix example
  25. *
  26. * Hilbert matrix : h(i,j) = 1/(i+j+1)
  27. * */
  28. float ***bmat;
  29. int rank, nodes, ret;
  30. parse_args(argc, argv);
  31. ret = starpu_init(NULL);
  32. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  33. ret = starpu_mpi_init(&argc, &argv, 1);
  34. STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
  35. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  36. MPI_Comm_size(MPI_COMM_WORLD, &nodes);
  37. starpu_helper_cublas_init();
  38. if (dblockx == -1 || dblocky == -1)
  39. {
  40. int factor;
  41. dblockx = nodes;
  42. dblocky = 1;
  43. for(factor=sqrt(nodes) ; factor>1 ; factor--)
  44. {
  45. if (nodes % factor == 0)
  46. {
  47. dblockx = nodes/factor;
  48. dblocky = factor;
  49. break;
  50. }
  51. }
  52. }
  53. unsigned i,j,x,y;
  54. bmat = malloc(nblocks * sizeof(float *));
  55. for(x=0 ; x<nblocks ; x++)
  56. {
  57. bmat[x] = malloc(nblocks * sizeof(float *));
  58. for(y=0 ; y<nblocks ; y++)
  59. {
  60. starpu_malloc((void **)&bmat[x][y], BLOCKSIZE*BLOCKSIZE*sizeof(float));
  61. for (i = 0; i < BLOCKSIZE; i++)
  62. {
  63. for (j = 0; j < BLOCKSIZE; j++)
  64. {
  65. 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);
  66. //mat[j +i*size] = ((i == j)?1.0f*size:0.0f);
  67. }
  68. }
  69. }
  70. }
  71. if (display)
  72. {
  73. printf("[%d] Input :\n", rank);
  74. for(y=0 ; y<nblocks ; y++)
  75. {
  76. for(x=0 ; x<nblocks ; x++)
  77. {
  78. printf("Block %u,%u :\n", x, y);
  79. for (j = 0; j < BLOCKSIZE; j++)
  80. {
  81. for (i = 0; i < BLOCKSIZE; i++)
  82. {
  83. if (i <= j)
  84. {
  85. printf("%2.2f\t", bmat[y][x][j +i*BLOCKSIZE]);
  86. }
  87. else
  88. {
  89. printf(".\t");
  90. }
  91. }
  92. printf("\n");
  93. }
  94. }
  95. }
  96. }
  97. double timing, flops;
  98. dw_cholesky(bmat, size, size/nblocks, nblocks, rank, nodes, &timing, &flops);
  99. starpu_mpi_shutdown();
  100. if (display)
  101. {
  102. printf("[%d] Results :\n", rank);
  103. for(y=0 ; y<nblocks ; y++)
  104. {
  105. for(x=0 ; x<nblocks ; x++)
  106. {
  107. printf("Block %u,%u :\n", x, y);
  108. for (j = 0; j < BLOCKSIZE; j++)
  109. {
  110. for (i = 0; i < BLOCKSIZE; i++)
  111. {
  112. if (i <= j)
  113. {
  114. printf("%2.2f\t", bmat[y][x][j +i*BLOCKSIZE]);
  115. }
  116. else
  117. {
  118. printf(".\t");
  119. }
  120. }
  121. printf("\n");
  122. }
  123. }
  124. }
  125. }
  126. int correctness;
  127. dw_cholesky_check_computation(bmat, size, rank, nodes, &correctness, &flops);
  128. for(x=0 ; x<nblocks ; x++)
  129. {
  130. for(y=0 ; y<nblocks ; y++)
  131. {
  132. starpu_free((void *)bmat[x][y]);
  133. }
  134. free(bmat[x]);
  135. }
  136. free(bmat);
  137. starpu_helper_cublas_shutdown();
  138. starpu_shutdown();
  139. assert(correctness);
  140. if (rank == 0)
  141. {
  142. fprintf(stdout, "Computation time (in ms): %2.2f\n", timing/1000);
  143. fprintf(stdout, "Synthetic GFlops : %2.2f\n", (flops/timing/1000.0f));
  144. }
  145. return 0;
  146. }