#include "easypap.h" #include #include // si nécessaire pour afficher une matrice static void print(unsigned *M, int n1, int n2); // multiplication séquentielle de deux matrices static void multiplication_elementaire(int n, unsigned* A, unsigned* B, unsigned* C); // initialisation d'une matrice static void init_mat(unsigned *M, int n1, int n2); static unsigned *A; static unsigned *B; static unsigned *C; int cannon_do_tile_default (int x, int y, int width, int height) { for (int i = y; i < y + height; i++) for (int j = x; j < x + width; j++) cur_img (i, j) = rgba(C[i*DIM+j]%255,0,0,255); return 0; } void cannon_init (void) { PRINT_DEBUG ('u', "Image size is %dx%d\n", DIM, DIM); PRINT_DEBUG ('u', "Block size is %dx%d\n", TILE_W, TILE_H); PRINT_DEBUG ('u', "Press to pause/unpause, to quit.\n"); A = (unsigned *)malloc(DIM*DIM*sizeof(unsigned )); B = (unsigned *)malloc(DIM*DIM*sizeof(unsigned )); C = (unsigned *)calloc(DIM*DIM,sizeof(unsigned )); srand(time(NULL)); } unsigned cannon_compute_seq (unsigned nb_iter) { for (unsigned it = 1; it <= nb_iter; it++) { init_mat(A,DIM,DIM); init_mat(B,DIM,DIM); multiplication_elementaire(DIM,A,B,C); /* printf("A : \n"); print(A,DIM,DIM); printf("B : \n"); print(B,DIM,DIM); printf("C : \n"); print(C,DIM,DIM);*/ do_tile(0,0,DIM,DIM,0); } return 0; } /////////////////////////////////////////////// // Ajout pour la partie MPI static int mpi_rank = -1; static int mpi_size = -1; // Pour la topologie static MPI_Comm Comm_grille; // Nouveau communicateur static int nbprocs_dim[2] = {0,0};// définition de la topologie static int period[2] = {1,1}; // elle sera périodique dans les deux axes static int mes_coords[2]; // Pour les coordonnées dans la topologie // Pour les matrices en local static unsigned *A_local; static unsigned *B_local; static unsigned *C_local; // Pour la taille static int n_local; ////////////////////////: // Version du do_tile pour le kernel mpi // Chaque processus va convertir son C_local en pixels et // mettre à jour le morceau correspondant dans cur_img int cannon_do_tile_mpi (int x, int y, int width, int height) { for (int i = y; i < y + height; i++) for (int j = x; j < x + width; j++) cur_img (i, j) = rgba(C_local[(i-y)*n_local+(j-x)]%255,0,0,255); return 0; } void cannon_init_mpi(void) { easypap_check_mpi(); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); // A compléter ici // Pour définir la topologie cartésienne. // Et définir ses coordonnées dans cette topologie // ... // fin A_local = (unsigned *)malloc(n_local*n_local*sizeof(unsigned )); B_local = (unsigned *)malloc(n_local*n_local*sizeof(unsigned )); C_local = (unsigned *)calloc(n_local*n_local,sizeof(unsigned )); srand(100*time(NULL)); } unsigned cannon_compute_mpi(unsigned nb_iter) { for (unsigned it = 1; it<= nb_iter; it++) { init_mat(A_local,n_local,n_local); init_mat(B_local,n_local,n_local); for (int i=0; i