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-2005 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) 2006-2008 Cisco Systems, Inc. All rights reserved.
13 * Copyright (c) 2015 Research Organization for Information Science
14 * and Technology (RIST). All rights reserved.
15 * $COPYRIGHT$
16 *
17 * Additional copyrights may follow
18 *
19 * $HEADER$
20 */
21 #include "ompi_config.h"
22 #include <stdio.h>
23 #ifdef HAVE_UNISTD_H
24 #include <unistd.h>
25 #endif
26 #include <string.h>
27
28 #include "ompi/mpi/c/bindings.h"
29 #include "ompi/runtime/params.h"
30 #include "ompi/communicator/communicator.h"
31 #include "ompi/errhandler/errhandler.h"
32
33 #if OMPI_BUILD_MPI_PROFILING
34 #if OPAL_HAVE_WEAK_SYMBOLS
35 #pragma weak MPI_Get_processor_name = PMPI_Get_processor_name
36 #endif
37 #define MPI_Get_processor_name PMPI_Get_processor_name
38 #endif
39
40 static const char FUNC_NAME[] = "MPI_Get_processor_name";
41
42
43 int MPI_Get_processor_name(char *name, int *resultlen)
44 {
45 OPAL_CR_NOOP_PROGRESS();
46
47 if ( MPI_PARAM_CHECK) {
48 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
49 if ( NULL == name ) {
50 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
51 FUNC_NAME);
52 }
53 if ( NULL == resultlen ) {
54 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
55 FUNC_NAME);
56 }
57 }
58
59 /* A simple implementation of this function using gethostname.
60
61 Note that MPI-2.1 requires:
62 - terminating the string with a \0
63 - name[*resultlen] == '\0'
64 - and therefore (*resultlen) cannot be > (MPI_MAX_PROCESSOR_NAME-1)
65
66 Guard against gethostname() returning a *really long* hostname
67 and not null-terminating the string. The Fortran API version
68 will pad to the right if necessary. */
69 gethostname(name, (MPI_MAX_PROCESSOR_NAME - 1));
70 name[MPI_MAX_PROCESSOR_NAME - 1] = '\0';
71 *resultlen = (int) strlen(name);
72
73 return MPI_SUCCESS;
74 }