Skip to content

Commit

Permalink
Corriger les erreurs causées par la traduction du Fortran.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Béland committed Feb 23, 2016
1 parent afa361c commit 7fff237
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions exercices/solutions/ex3_rotation.c
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
#include <stdio.h>
#include <mpi.h>
#include "mpi.h"
#include <stdlib.h>
#define n 64

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);

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;
Expand All @@ -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();
Expand Down

0 comments on commit 7fff237

Please sign in to comment.