init.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "Matrix.xmptype.h"
  2. #include <mpi.h>
  3. #include <stdio.h>
  4. #include <unistd.h> // for usleep
  5. #include <xmp.h>
  6. #pragma xmp nodes p(2, 2)
  7. #pragma xmp template t(0 : 3, 0 : 3)
  8. #pragma xmp distribute t(block, block) onto p
  9. XMP_Matrix A[4][4];
  10. #pragma xmp align A[i][j] with t(j, i)
  11. #pragma xmp shadow A[4][4]
  12. XMP_Matrix B[4][4];
  13. #pragma xmp align B[i][j] with t(j, i)
  14. #pragma xmp shadow B[4][4]
  15. XMP_Matrix C[4][4];
  16. #pragma xmp align C[i][j] with t(j, i)
  17. int main(int argc, char **argv) {
  18. xmp_init_mpi(&argc, &argv);
  19. int rank;
  20. MPI_Barrier(MPI_COMM_WORLD);
  21. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  22. int i, j, n;
  23. n = 4;
  24. fprintf(stderr, "rank = %d ; ", rank);
  25. char *processor_name = malloc(256 * sizeof(char));
  26. int name_len;
  27. #pragma xmp loop(i, j) on t(j, i)
  28. for (i = 0; i < n; i++) {
  29. for (j = 0; j < n; j++) {
  30. fprintf(stderr, "\n(%d, %d, %d) ", rank, i, j);
  31. MPI_Get_processor_name(processor_name, &name_len);
  32. // Afficher le résultat
  33. fprintf(stderr, "\nProcesseur %d - Nom : %s \n", rank, processor_name);
  34. C[i][j] = 0;
  35. A[i][j] = 1;
  36. B[i][j] = i * n + j + 1;
  37. fprintf(stderr, "B[%d,%d]=%f rank=%d, n=%d\n", i, j, B[i][j], rank, n);
  38. }
  39. }
  40. // Libérer la mémoire allouée
  41. free(processor_name);
  42. #pragma xmp reflect(A)
  43. #pragma xmp reflect(B)
  44. MPI_Barrier(MPI_COMM_WORLD);
  45. usleep(100);
  46. if (rank == 0) {
  47. fprintf(stdout, "\nValeur de B[i,j] \n");
  48. for (i = 0; i < n; i++) {
  49. for (j = 0; j < n; j++) {
  50. fprintf(stdout, "B[%d,%d]=%f rank=%d, n=%d\n", i, j, B[i][j], rank, n);
  51. }
  52. }
  53. fprintf(stdout, "\nValeur de A[i,j] \n");
  54. for (i = 0; i < n; i++) {
  55. for (j = 0; j < n; j++) {
  56. fprintf(stdout, "A[%d,%d]=%f rank=%d, n=%d\n", i, j, A[i][j], rank, n);
  57. }
  58. }
  59. }
  60. xmp_finalize_mpi();
  61. return 0;
  62. }