Personal tools
You are here: Home CSE Student Resources HPC Resources samples Parallel Hello World

Parallel Hello World

example Hello world for parallel computing.

This is an example parallel program for testing the clusters.

Simple parallel hello world. requires an even number of nodes/cores

/* C Example */
#include <stdio.h>
#include <mpi.h>


int main (argc, argv)
     int argc;
     char *argv[];
{
  int rank, size;
  char hostname[256];

  MPI_Init (&argc, &argv);	/* starts MPI */
  MPI_Comm_rank (MPI_COMM_WORLD, &rank);	/* get current process id */
  MPI_Comm_size (MPI_COMM_WORLD, &size);	/* get number of processes */
  gethostname(hostname,255);
  printf( "Hello world from process %d of %d on host %s\n", rank, size, hostname );
  MPI_Finalize();
  return 0;
}
Document Actions