
The opal_gethostname() function provides a more robust mechanism to retrieve the hostname than gethostname(), which can return results that are not null-terminated, and which can vary in its behavior from system to system. opal_gethostname() just returns the value in opal_process_info.nodename; this is populated in opal_init_gethostname() inside opal_init.c. -Changed all gethostname calls in opal subtree to opal_gethostname -Changed all gethostname calls in orte subtree to opal_gethostname -Changed all gethostname calls in ompi subdir to opal_gethostname -Changed all gethostname calls in oshmem subdir to opal_gethostname -Changed opal_if.c in test subdir to use opal_gethostname -Changed opal_init.c to include opal_init_gethostname. This function returns an int and directly sets opal_process_info.nodename per jsquyres' modifications. Relates to open-mpi#6801 Signed-off-by: Charles Shereda <cpshereda@lanl.gov>
55 строки
1.2 KiB
C
55 строки
1.2 KiB
C
/* -*- C -*-
|
|
*
|
|
* $HEADER$
|
|
*
|
|
* The most basic of MPI applications
|
|
*/
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include "orte_config.h"
|
|
|
|
#include "opal/runtime/opal.h"
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "mpi.h"
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
int rank, size;
|
|
const char *hostname;
|
|
void *appnum;
|
|
void *univ_size;
|
|
char *appstr, *unistr;
|
|
int flag;
|
|
char *envar;
|
|
|
|
envar = getenv("OMPI_UNIVERSE_SIZE");
|
|
|
|
MPI_Init(&argc, &argv);
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_APPNUM, &appnum, &flag);
|
|
if (NULL == appnum) {
|
|
opal_asprintf(&appstr, "UNDEFINED");
|
|
} else {
|
|
opal_asprintf(&appstr, "%d", *(int*)appnum);
|
|
}
|
|
MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &univ_size, &flag);
|
|
if (NULL == univ_size) {
|
|
opal_asprintf(&unistr, "UNDEFINED");
|
|
} else {
|
|
opal_asprintf(&unistr, "%d", *(int*)univ_size);
|
|
}
|
|
|
|
hostname = opal_gethostname();
|
|
printf("Hello, World, I am %d of %d on host %s from app number %s universe size %s universe envar %s\n",
|
|
rank, size, hostname, appstr, unistr, (NULL == envar) ? "NULL" : envar);
|
|
|
|
MPI_Finalize();
|
|
return 0;
|
|
}
|