#include #include #include // strcpy MPI_CHAR const int tag = 10; int main(int argc, char **argv) { int pid, nprocs; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &pid); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); int a = pid; //echange simple point à point if(pid==0) MPI_Send(&a,1,MPI_INT,1,tag,MPI_COMM_WORLD); if(pid==1) MPI_Recv(&a,1,MPI_INT,0,tag,MPI_COMM_WORLD,MPI_STATUS_IGNORE); printf("Je suis processus %d a= %d", pid,a); // Je suis processus 1 a= 0 // Je suis processus 1 a= 0 // np 4 char msg[]; if(pid==0) { strcpy(msg,"hello from 0"); } MPI_Bcast(&msg,sizeof(msg),MPI_CHAR,0,MPI_COMM_WORLD); printf("Je suis processus %d le message = %s", pid,msg); Je suis processus 0 le message = hello from 0 Je suis processus 2 le message = hello from 0 Je suis processus 1 le message = hello from 0 Je suis processus 3 le message = hello from 0 int Tab[10],i; char msg[20]; if (pid == 0) strcpy(msg,"bonjour"); MPI_Bcast(&msg, sizeof(msg), MPI_CHAR, 0 , MPI_COMM_WORLD); printf ("processus %d msg = %s\n", pid,msg); PO,P1,P2,P3 int a=23; if(pid==0) // root { a=367; MPI_Send(&a,1,MPI_INT,1,12,MPI_COMM_WORLD); MPI_Send(&a,1,MPI_INT,2,12,MPI_COMM_WORLD); MPI_Send(&a,1,MPI_INT,3,12,MPI_COMM_WORLD); MPI_Send(&a,1,MPI_INT,0,12,MPI_COMM_WORLD); MPI_Recv(&a,1,MPI_INT,0,12,MPI_COMM_WORLD,MPI_STATUS_IGNORE); } else{ // int c; MPI_Recv(&a,1,MPI_INT,1,12,MPI_COMM_WORLD,MPI_STATUS_IGNORE); MPI_Recv(&a,1,MPI_INT,2,12,MPI_COMM_WORLD,MPI_STATUS_IGNORE); MPI_Recv(&a,1,MPI_INT,3,12,MPI_COMM_WORLD,MPI_STATUS_IGNORE); } int a=23; if(pid==2) // root { a=367; } MPI_Bcast(&a, 1, MPI_INT, 2 , MPI_COMM_WORLD); printf("le processus %d a la valeur a=%d",pid,a); //MPI_Send(&a, 1, MPI_INT, 1, tag, MPI_COMM_WORLD); //if (pid == 1) // MPI_Recv(&a, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); // 1. MPI_Bcast(msg, 1, MPI_INT, 0 , MPI_COMM_WORLD); //printf("%s je suis %d\n",msg, pid); //Q2 if(pid==0) { for (i=0;i<10;i++) Tab[i] = i; } MPI_Bcast(Tab,10, MPI_INT,0, MPI_COMM_WORLD); for (i=0;i<10;i++) printf("Processus %d ---> tab[%d]=%d\n", pid, i,Tab[i]); MPI_Finalize(); return 0; }