diff --git a/exercices/solutions/ex3_rotation.c b/exercices/solutions/ex3_rotation.c index db8838b..fe86d8a 100644 --- a/exercices/solutions/ex3_rotation.c +++ b/exercices/solutions/ex3_rotation.c @@ -1,5 +1,5 @@ #include -#include +#include "mpi.h" #include #define n 64 @@ -7,7 +7,7 @@ int main(int argc, char *argv[]) { int i,ierr,proc,nproc,prec,suiv,iter; -MPI_Status etat[MPI_STATUS_SIZE]; +MPI_Status etat; int *A; ierr = MPI_Init(&argc,&argv); @@ -15,21 +15,21 @@ ierr = MPI_Init(&argc,&argv); ierr = MPI_Comm_size(MPI_COMM_WORLD, &nproc); ierr = MPI_Comm_rank(MPI_COMM_WORLD, &proc); -if (proc==0 && (n%nproc /= 0 || n%2 != 0)) { +if (proc==0 && (n%nproc != 0 || n%2 != 0)) { printf("Nombre de processus incompatible avec la taille\n"); ierr = MPI_Abort(MPI_COMM_WORLD,1); } -A = (int *) malloc((n/proc+1) * sizeof(int)); +A = (int *) malloc((n/nproc+1) * sizeof(int)); for (i=1; i<= n/nproc; i++) - a[i]=proc; + A[i]=proc; printf("proc %i iter=0 A = ", proc); for (i = 1; i <= n/nproc; i++) printf("%i ", A[i]); printf("\n"); -for (i=1; i<=n; i++) +for (iter=1; iter<=n; iter++) { if (proc == 0) prec=nproc-1; @@ -41,20 +41,19 @@ for (i=1; i<=n; i++) suiv=proc+1; if (proc%2 == 0) { - ierr = MPI_Send(A[n/nproc],1,MPI_INTEGER,suiv,iter,MPI_COMM_WORLD); - ierr = MPI_Recv(A[0],1,MPI_INTEGER,prec,iter,MPI_COMM_WORLD,etat); + ierr = MPI_Send(&(A[n/nproc]),1,MPI_INT,suiv,iter,MPI_COMM_WORLD); + ierr = MPI_Recv(A,1,MPI_INT,prec,iter,MPI_COMM_WORLD,&etat); } else { - ierr = MPI_Recv(A[0],1,MPI_INTEGER,prec,iter,MPI_COMM_WORLD,etat); - ierr = MPI_Send(A[n/nproc],1,MPI_INTEGER,suiv,iter,MPI_COMM_WORLD); + ierr = MPI_Recv(A,1,MPI_INT,prec,iter,MPI_COMM_WORLD,&etat); + ierr = MPI_Send(&(A[n/nproc]),1,MPI_INT,suiv,iter,MPI_COMM_WORLD); } for (i=n/nproc; i>=1; i--) A[i]=A[i-1]; - print '(A,i2,A,i3,A,64i5)', 'proc=',proc,' iter=',iter,' A=',A(1:n/nproc) -printf("proc %i iter=%i A = ", proc,iter); -for (i = 1; i <= n/nproc; i++) - printf("%i ", A[i]); -printf("\n"); + printf("proc %i iter=%i A = ", proc,iter); + for (i = 1; i <= n/nproc; i++) + printf("%i ", A[i]); + printf("\n"); } free(A); ierr = MPI_Finalize();