#include<cstdlib>#include<ctime>#include<iomanip>#include<iostream>#include<mpi.h>#include<omp.h>usingnamespace std;intmain(int argc,char*argv[]){int id;int ierr;int p;//// Initialize MPI.//
ierr =MPI_Init(&argc,&argv );if( ierr !=0){
cout <<"\n";
cout <<" MPI_Init returned nonzero ierr.\n";exit(1);}//// Get the number of processes.//
ierr =MPI_Comm_size( MPI_COMM_WORLD,&p );//// Get the individual process ID.//
ierr =MPI_Comm_rank( MPI_COMM_WORLD,&id );//// Process 0 prints an introductory message.//#pragmaomp parallel num_threads(2){int tid =omp_get_thread_num();
cout <<"P"<< id <<" T"<< tid <<": 'Hello, world!'\n"<< std::flush;}MPI_Finalize();if( id ==0){
cout <<"\n";
cout <<"P"<< id <<": Normal end of execution.\n";
cout <<"\n";}return0;}
wk@ubuntu:~/cppdir$ mpiCC hello2.cpp -fopenmp
wk@ubuntu:~/cppdir$ mpirun -n 2 ./a.out
P1 T1: 'Hello, world!'
P1 T0: 'Hello, world!'
P0 T0: 'Hello, world!'
P0 T1: 'Hello, world!'
P0: Normal end of execution.