From 6f498c0964f0d236b97a560edcf9fc7df0aa3738 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Tue, 16 Oct 2007 16:17:48 +0000 Subject: [PATCH] Since we no longer set the APP_NUM attribute in the case of a singleton, protect the code so we don't crash in that case. This commit was SVN r16461. --- orte/test/mpi/hello_nodename.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/orte/test/mpi/hello_nodename.c b/orte/test/mpi/hello_nodename.c index 8e3e7771f8..2f5abfb83c 100644 --- a/orte/test/mpi/hello_nodename.c +++ b/orte/test/mpi/hello_nodename.c @@ -14,17 +14,28 @@ int main(int argc, char* argv[]) char hostname[512]; void *appnum; void *univ_size; + char *appstr, *unistr; int flag; 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) { + asprintf(&appstr, "UNDEFINED"); + } else { + asprintf(&appstr, "%d", *(int*)appnum); + } MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &univ_size, &flag); - + if (NULL == univ_size) { + asprintf(&unistr, "UNDEFINED"); + } else { + asprintf(&unistr, "%d", *(int*)univ_size); + } + gethostname(hostname, 512); - printf("Hello, World, I am %d of %d on host %s from app number %d universe size %d\n", - rank, size, hostname, *(int*)appnum, *(int*)univ_size); + printf("Hello, World, I am %d of %d on host %s from app number %s universe size %s\n", + rank, size, hostname, appstr, unistr); MPI_Finalize(); return 0;