root/orte/test/mpi/hello_nodename.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* -*- C -*-
   2  *
   3  * $HEADER$
   4  *
   5  * The most basic of MPI applications
   6  */
   7 
   8 #define _GNU_SOURCE
   9 
  10 #include "orte_config.h"
  11 
  12 #include <stdio.h>
  13 #include <unistd.h>
  14 #include <stdlib.h>
  15 
  16 #include "mpi.h"
  17 
  18 int main(int argc, char* argv[])
  19 {
  20     int rank, size;
  21     char hostname[OPAL_MAXHOSTNAMELEN];
  22     void *appnum;
  23     void *univ_size;
  24     char *appstr, *unistr;
  25     int flag;
  26     char *envar;
  27 
  28     envar = getenv("OMPI_UNIVERSE_SIZE");
  29 
  30     MPI_Init(&argc, &argv);
  31     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  32     MPI_Comm_size(MPI_COMM_WORLD, &size);
  33     MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_APPNUM, &appnum, &flag);
  34     if (NULL == appnum) {
  35         opal_asprintf(&appstr, "UNDEFINED");
  36     } else {
  37         opal_asprintf(&appstr, "%d", *(int*)appnum);
  38     }
  39     MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &univ_size, &flag);
  40     if (NULL == univ_size) {
  41         opal_asprintf(&unistr, "UNDEFINED");
  42     } else {
  43         opal_asprintf(&unistr, "%d", *(int*)univ_size);
  44     }
  45 
  46     gethostname(hostname, sizeof(hostname));
  47     printf("Hello, World, I am %d of %d on host %s from app number %s universe size %s universe envar %s\n",
  48            rank, size, hostname, appstr, unistr, (NULL == envar) ? "NULL" : envar);
  49 
  50     MPI_Finalize();
  51     return 0;
  52 }

/* [<][>][^][v][top][bottom][index][help] */