Broadcast.c
                
      
      
      
        
          
          
              
                 Broadcast.c
              
              
                  —
                  C source code,
                  1 kB (1319 bytes)
                Broadcast.c
              
              
                  —
                  C source code,
                  1 kB (1319 bytes)
              
          
          
          
        
      
    
    
            
Contenido del Archivo
#include <stdio.h>
#include <string.h>
#include "mpi.h"
main(int argc, char* argv[])
{
    int         my_rank;       // Rank del proceso
    int         p;             // Numero de procesos
    int         source;        // Rank del que envia
    int         dest;          // Rank del que recibe
    int         tag = 0;       // Tag del mensaje
    char        message[100];  // Mensaje
    MPI_Status  status;
    double   start,stop;
    /* Inicio */
    MPI_Init(&argc, &argv);
    /* Averiguando el Rank del proceso */
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
    /* Averiguando el numero de procesos que participan */
    MPI_Comm_size(MPI_COMM_WORLD, &p);
    /* Hasta que todos los procesos no lleguen hasta aqui ninguno continua */
    MPI_Barrier(MPI_COMM_WORLD);
    start = MPI_Wtime();
    sprintf(message, "Soy el proceso %d y estoy enviando un mensaje broadcast!",my_rank);
    MPI_Bcast(message, strlen(message)+1, MPI_CHAR, 0, MPI_COMM_WORLD);
    if (my_rank != 0)
	printf("%s Y yo soy el proceso %d y lo estoy recibiendo.\n",message,my_rank);
    MPI_Barrier(MPI_COMM_WORLD);  // Espero a que todos los procesos terminen para calcular el tiempo de finalizacion.
    stop = MPI_Wtime();
    if (my_rank == 0)
       printf("Tiempo empleado: %g\n",stop-start);
    MPI_Finalize();
}
             





