root/ompi/mpi/c/get_library_version.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Get_library_version

   1 /*
   2  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2009 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2014-2018 Cisco Systems, Inc.  All rights reserved
  13  * Copyright (c) 2015      Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * Copyright (c) 2015      Intel, Inc. All rights reserved
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 #include "ompi_config.h"
  23 #include <stdio.h>
  24 
  25 #include "ompi/mpi/c/bindings.h"
  26 #include "ompi/runtime/params.h"
  27 #include "ompi/communicator/communicator.h"
  28 #include "ompi/errhandler/errhandler.h"
  29 
  30 #if OMPI_BUILD_MPI_PROFILING
  31 #if OPAL_HAVE_WEAK_SYMBOLS
  32 #pragma weak MPI_Get_library_version = PMPI_Get_library_version
  33 #endif
  34 #define MPI_Get_library_version PMPI_Get_library_version
  35 #endif
  36 
  37 static const char FUNC_NAME[] = "MPI_Get_library_version";
  38 
  39 
  40 int MPI_Get_library_version(char *version, int *resultlen)
  41 {
  42     int len_left;
  43     char *ptr, tmp[MPI_MAX_LIBRARY_VERSION_STRING];
  44 
  45     OPAL_CR_NOOP_PROGRESS();
  46 
  47     if (MPI_PARAM_CHECK) {
  48         /* Per MPI-3, this function can be invoked before
  49            MPI_INIT, so we don't invoke the normal
  50            MPI_ERR_INIT_FINALIZE() macro here */
  51 
  52         if (NULL == version || NULL == resultlen) {
  53             /* Note that we have to check and see if we have
  54                previously called MPI_INIT or not.  If so, use the
  55                normal OMPI_ERRHANDLER_INVOKE, because the user may
  56                have changed the default errhandler on MPI_COMM_WORLD.
  57                If we have not invoked MPI_INIT, then just abort
  58                (i.e., use a NULL communicator, which will end up at the
  59                default errhandler, which is abort). */
  60 
  61             int32_t state = ompi_mpi_state;
  62             if (state >= OMPI_MPI_STATE_INIT_COMPLETED &&
  63                 state < OMPI_MPI_STATE_FINALIZE_PAST_COMM_SELF_DESTRUCT) {
  64                 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
  65                                               FUNC_NAME);
  66             } else {
  67                 /* We have no MPI object here so call ompi_errhandle_invoke
  68                  * directly */
  69                 return ompi_errhandler_invoke(NULL, NULL, -1,
  70                                               ompi_errcode_get_mpi_code(MPI_ERR_ARG),
  71                                               FUNC_NAME);
  72             }
  73         }
  74     }
  75 
  76     /* First write to a tmp variable so that we can write to *all* the
  77        chars (MPI-3 says that we can only write resultlen chars to the
  78        output string) */
  79     ptr = tmp;
  80     len_left = sizeof(tmp);
  81     memset(tmp, 0, MPI_MAX_LIBRARY_VERSION_STRING);
  82 
  83     snprintf(tmp, MPI_MAX_LIBRARY_VERSION_STRING, "Open MPI v%d.%d.%d",
  84              OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION, OMPI_RELEASE_VERSION);
  85     ptr += strlen(tmp);
  86     len_left -= strlen(tmp);
  87 
  88     if (strlen(OMPI_GREEK_VERSION) > 0) {
  89         snprintf(ptr, len_left, "%s", OMPI_GREEK_VERSION);
  90         ptr = tmp + strlen(tmp);
  91         len_left = MPI_MAX_LIBRARY_VERSION_STRING - strlen(tmp);
  92     }
  93 
  94     /* Package name */
  95     if (strlen(OPAL_PACKAGE_STRING) > 0) {
  96         snprintf(ptr, len_left, ", package: %s", OPAL_PACKAGE_STRING);
  97         ptr = tmp + strlen(tmp);
  98         len_left = MPI_MAX_LIBRARY_VERSION_STRING - strlen(tmp);
  99     }
 100 
 101     /* Ident string */
 102     if (strlen(OMPI_IDENT_STRING) > 0) {
 103         snprintf(ptr, len_left, ", ident: %s", OMPI_IDENT_STRING);
 104         ptr = tmp + strlen(tmp);
 105         len_left = MPI_MAX_LIBRARY_VERSION_STRING - strlen(tmp);
 106     }
 107 
 108     /* Repository revision */
 109     if (strlen(OMPI_REPO_REV) > 0) {
 110         snprintf(ptr, len_left, ", repo rev: %s", OMPI_REPO_REV);
 111         ptr = tmp + strlen(tmp);
 112         len_left = MPI_MAX_LIBRARY_VERSION_STRING - strlen(tmp);
 113     }
 114 
 115     /* Release date */
 116     if (strlen(OMPI_RELEASE_DATE) > 0) {
 117         snprintf(ptr, len_left, ", %s", OMPI_RELEASE_DATE);
 118         ptr = tmp + strlen(tmp);
 119         len_left = MPI_MAX_LIBRARY_VERSION_STRING - strlen(tmp);
 120     }
 121 
 122     memcpy(version, tmp, strlen(tmp) + 1);
 123     *resultlen = strlen(tmp) + 1;
 124 
 125     return MPI_SUCCESS;
 126 }

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