C code for parallel programming in MPICH2, run and make executable file


In ubuntu command line, run this command

nano hello.c

/* C Code */
#include <stdio.h> //standard input/out
#include <mpi.h>  //mpich2 c library

 
int main (int argc, char *argv[])
{
  int myRank, size;
 
  MPI_Init (&argc, &argv);      /* Initialize MPI */
  MPI_Comm_rank (MPI_COMM_WORLD, &myRank);        /* get current process id */
  MPI_Comm_size (MPI_COMM_WORLD, &size);        /* get number of processes in communicator */

  printf( "Hello world from process %d of %d\n", myRank, size );

  MPI_Finalize();
}

Now to save file:

ctrl+O

To exit file:

ctrl+X

Compile hello.c file:

$ mpicc hello.c -o hello

Run exe file on 5 processes:

$ mpirun -np 5 ./hello

Output: it will be random


Hello world from process 0 of 5
Hello world from process 1 of 5
Hello world from process 4 of 5
Hello world from process 2 of 5
Hello world from process 3 of 5
Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with: ,
Posted in mpich2, Parallel Programming

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: