Sophie

Sophie

distrib > Mandriva > 10.2 > x86_64 > by-pkgid > 6d7a8a22c52111519bc5fd829d630cd1 > files > 11

mpich-1.2.5.2-5mdk.src.rpm

/*
 * Author:  Matt Massie (massie@cs.berkeley.edu)
 * 
 * Originally Copied from:
 * http://now.CS.Berkeley.EDU/Fastcomm/MPI/howto/hello-world/hello-world.c
 * by Frederick Wong (fredwong@cs.berkeley.edu)
 */
#include <stdio.h>
#include "mpi.h"
#include <unistd.h>

int
main(int argc, char **argv) {

  int rank;
  char msg[20];
  char host[255];
  
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  gethostname(host,254);
  
  if (rank==0) {
    strcpy(msg,"Hello World!");
    printf("%s: Sending %s\n\n",host,msg);
    MPI_Bcast(msg, 13, MPI_CHAR, rank, MPI_COMM_WORLD);
  } else {
    MPI_Bcast(msg, 13, MPI_CHAR, 0, MPI_COMM_WORLD);
    printf("  |- %-30s %s\n", host,msg);
  }

  MPI_Finalize();
}