Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include "mpi.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define SIZE 1000
  6.  
  7. int main(int argc, char *argv[]){
  8.     double startwtime, endwtime;
  9.     int namelen, numprocs, myid, size ;
  10.     char processor_name[MPI_MAX_PROCESSOR_NAME], buff[SIZE], msg[SIZE];
  11.  
  12.     MPI_Init(&argc,&argv);
  13.     startwtime = MPI_Wtime();
  14.     MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
  15.     MPI_Comm_rank(MPI_COMM_WORLD,&myid);
  16.     MPI_Get_processor_name(processor_name,&namelen);
  17.     fprintf(stderr,"\nProcessus %d sur la machine %s parmi %d processus.\n",myid,processor_name, numprocs);
  18.  
  19.     if (numprocs != 3)
  20.         fprintf(stderr,"Il me faut 3 processus !\n") ;
  21.  
  22.     strcpy(msg,"Message Broadcast");
  23.     size=sizeof(char)*strlen(msg);
  24.     if (myid==0)
  25.         fprintf(stderr,"%d envoie <%s>\n",myid , msg) ;
  26.     /* c'est le processus 0 qui est l'envoyeur */
  27.  
  28.     MPI_Bcast((void*) msg, size, MPI_CHAR,0, MPI_COMM_WORLD) ;
  29.     fprintf(stderr,"%d recoit [%s]\n",myid,msg) ;
  30.     endwtime = MPI_Wtime();
  31.     printf("Temps ecoule sur %d = %f\n", myid, endwtime-startwtime);
  32.     MPI_Finalize();
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement