//
// "hello world" program, plus command-line arguments
//

#include <iostream>
#include <cstdlib>		// has exit(), etc.
#include <mpi++.h>		// MPI header file

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

  // initialize for MPI (should come before any other calls to
  //     MPI routines)
  if (MPI_Init(&argc, &argv) != MPI_SUCCESS) {
    cerr << "MPI initialization error\n"; exit(EXIT_FAILURE);
  }

  // get number of processes
  int nprocs;
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

  // get this process's number (ranges from 0 to nprocs - 1)
  int myid;
  MPI_Comm_rank(MPI_COMM_WORLD, &myid);

  // print a greeting
  cout << "hello from process " << myid << " of " << nprocs << endl;

  // show command-line arguments, if any
  for (int i = 0; i < argc; ++i) 
    cout << "in process " << myid << ", argument " << i 
	 << " is " << argv[i] << endl;

  // clean up for MPI 
  MPI_Finalize();

  return EXIT_SUCCESS;
}