Maybe it can‘t be run ,but it just provides a thinking way and mpi api overview.
#include "mpi.h"
#include <stdio.h>
#include <unistd.h>
#define nodeNameLength 20
int main(int argc, char *argv[])
{
int rank,nproc;
MPI_Init( &argc, &argv );
MPI_Comm_size( MPI_COMM_WORLD, &nproc);
MPI_Comm_rank( MPI_COMM_WORLD, &rank);
char currentNodeName[nodeNameLength];
if(-1==gethostname(currentNodeName,sizeof(currentNodeName)))
{