#include <cstdlib>
#include <iostream>
#include <mpi.h>
#include <string>

#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 256
#endif

using namespace std;

int main()
{
	MPI::Init();

	int rank = MPI::COMM_WORLD.Get_rank();
	int size = MPI::COMM_WORLD.Get_size();

	char host[HOST_NAME_MAX];
	int status = gethostname(host, HOST_NAME_MAX);
	string hostname;

	if (status == -1)
		hostname = "<unknown>";
	else
		hostname = host;

	cout << "Hello from rank " << rank << " of " << size << "! (I'm on host " << hostname << ".)" << endl;

	MPI::Finalize();
}

#include <mpi.h>
#include <iostream>

using namespace std;

int main()
{
	MPI::Init();

	int rank = MPI::COMM_WORLD.Get_rank();
	int size = MPI::COMM_WORLD.Get_size();

	cout << "Hello from rank " << rank << " of " << size << "!" << endl;

	MPI::Finalize();
}

--- 
+++ 
@@ -1,5 +1,11 @@
+#include <cstdlib>
+#include <iostream>
 #include <mpi.h>
-#include <iostream>
+#include <string>
+
+#ifndef HOST_NAME_MAX
+#define HOST_NAME_MAX 256
+#endif
 
 using namespace std;
 
@@ -10,7 +16,16 @@
 	int rank = MPI::COMM_WORLD.Get_rank();
 	int size = MPI::COMM_WORLD.Get_size();
 
-	cout << "Hello from rank " << rank << " of " << size << "!" << endl;
+	char host[HOST_NAME_MAX];
+	int status = gethostname(host, HOST_NAME_MAX);
+	string hostname;
+
+	if (status == -1)
+		hostname = "<unknown>";
+	else
+		hostname = host;
+
+	cout << "Hello from rank " << rank << " of " << size << "! (I'm on host " << hostname << ".)" << endl;
 
 	MPI::Finalize();
 }
Print hostname where hellompi runs
