broadcast5.c

/*****************************************************************/
/*                                                               */
/* Utilisation du broadcast offert par la librairie MPI...       */
/*                                                               */
/*****************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <mpi.h>
#include <sys/time.h>

#define BUFLEN 65536

long ms_time() 
{
  struct timeval tv;

  gettimeofday(&tv, NULL);
  return(tv.tv_sec*1000 + tv.tv_usec/1000);
}

void long_computation() 
{
   long now=ms_time();
   while(ms_time()<now+4000) 
     {
     }
}

int main(int argc, char **argv) 
{
  int nb_proc;
  int my_id;
  int next;
  int buffer[BUFLEN];

  long start,end;

  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD,&nb_proc);
  MPI_Comm_rank(MPI_COMM_WORLD,&my_id);

  if (my_id == nb_proc-1)
    next = 0;
  else
    next = my_id+1;

  if (my_id == 0) start = ms_time();

  if (my_id == 0) 
    {
      int i;
      for(i=0; i<BUFLEN; i++) buffer[i]=i;
    } 

  MPI_Bcast(buffer, BUFLEN, MPI_INT, 0, MPI_COMM_WORLD);
  long_computation();

  MPI_Finalize();
  if (my_id == 0) end = ms_time();
  if (my_id == 0) printf("Ça m'a prit %ld ms\n",(end-start));

  return (0);
}

Generated by GNU enscript 1.6.3.