#include "Matrix.xmptype.h" #include #include #include // for usleep #include #pragma xmp nodes p(2, 2) #pragma xmp template t(0 : 3, 0 : 3) #pragma xmp distribute t(block, block) onto p XMP_Matrix A[4][4]; #pragma xmp align A[i][j] with t(j, i) #pragma xmp shadow A[4][4] XMP_Matrix B[4][4]; #pragma xmp align B[i][j] with t(j, i) #pragma xmp shadow B[4][4] XMP_Matrix C[4][4]; #pragma xmp align C[i][j] with t(j, i) int main(int argc, char **argv) { xmp_init_mpi(&argc, &argv); int rank; MPI_Barrier(MPI_COMM_WORLD); MPI_Comm_rank(MPI_COMM_WORLD, &rank); int i, j, n; n = 4; fprintf(stderr, "rank = %d ; ", rank); char *processor_name = malloc(256 * sizeof(char)); int name_len; #pragma xmp loop(i, j) on t(j, i) for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { fprintf(stderr, "\n(%d, %d, %d) ", rank, i, j); MPI_Get_processor_name(processor_name, &name_len); // Afficher le résultat fprintf(stderr, "\nProcesseur %d - Nom : %s \n", rank, processor_name); C[i][j] = 0; A[i][j] = 1; B[i][j] = i * n + j + 1; fprintf(stderr, "B[%d,%d]=%f rank=%d, n=%d\n", i, j, B[i][j], rank, n); } } // Libérer la mémoire allouée free(processor_name); #pragma xmp reflect(A) #pragma xmp reflect(B) MPI_Barrier(MPI_COMM_WORLD); usleep(100); if (rank == 0) { fprintf(stdout, "\nValeur de B[i,j] \n"); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { fprintf(stdout, "B[%d,%d]=%f rank=%d, n=%d\n", i, j, B[i][j], rank, n); } } fprintf(stdout, "\nValeur de A[i,j] \n"); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { fprintf(stdout, "A[%d,%d]=%f rank=%d, n=%d\n", i, j, A[i][j], rank, n); } } } xmp_finalize_mpi(); return 0; }