You develop a parallel application that will be deployed on a Windows HPC Server 2008 cluster.You write the following code segment. (Line numbers are included for reference only.)
01 int rank;
02 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
03 // declaration of variable hostName
04 // code to execute
06 std::cout << "hostname of rank " << rank;
07 std::cout << ": " << hostName << "n";
You need to ensure that a variable named hostName contains the name of the cluster node that the code runs on.
Which code segment should you add at line 05?
A.
char *hostName = getenv("MPI_HOSTNAME");
B.
char hostName[MPI_MAX_PROCESSOR_NAME]; int resultlen; MPI_Get_processor_name(&resultlen, hostName);
C.
char hostName[MPI_MAX_NAME_STRING]; int resultlen; MPI_Comm_get_name(MPI_COMM_WORLD, hostName, &resultlen);
D.
char hostName[256]; int resultlen = sizeof(hostName); if (rank == 0) { gethostname(hostName, resultlen); }