File: errstring.c

package info (click to toggle)
lam 7.1.4-8
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 56,404 kB
  • sloc: ansic: 156,541; sh: 9,991; cpp: 7,699; makefile: 5,621; perl: 488; fortran: 260; asm: 83
file content (176 lines) | stat: -rw-r--r-- 4,974 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * Copyright (c) 2001-2003 The Trustees of Indiana University.  
 *                         All rights reserved.
 * Copyright (c) 1998-2001 University of Notre Dame. 
 *                         All rights reserved.
 * Copyright (c) 1994-1998 The Ohio State University.  
 *                         All rights reserved.
 * 
 * This file is part of the LAM/MPI software package.  For license
 * information, see the LICENSE file in the top level directory of the
 * LAM/MPI source distribution.
 * 
 * $HEADER$
 *
 * $Id: errstring.c,v 6.10 2003/05/31 22:28:50 jsquyres Exp $
 *
 *	Function:	- return the MPI error message
 *	Accepts:	- error code
 *			- message buffer (out)
 *			- buffer length (out)
 *	Returns:	- MPI_SUCCESS
 */

#include <stdio.h>
#include <string.h>

#include "lam.h"

#include <blktype.h>
#include <mpi.h>
#include <mpisys.h>
#include <terror.h>
#include <typical.h>
#include <etc_misc.h>


/*
 * error messages
 */
static CONST char	*mpierrmsg[] = {
	"unused error code",			/* unused */
	"invalid buffer pointer",		/* MPI_ERR_BUFFER */
	"invalid count argument",		/* MPI_ERR_COUNT */
	"invalid datatype argument",		/* MPI_ERR_TYPE */
	"invalid tag argument",			/* MPI_ERR_TAG */
	"invalid communicator",			/* MPI_ERR_COMM */
	"invalid rank",				/* MPI_ERR_RANK */
	"invalid request handle",		/* MPI_ERR_REQUEST */
	"invalid root",				/* MPI_ERR_ROOT */
	"invalid group",			/* MPI_ERR_GROUP */
	"invalid operation",			/* MPI_ERR_OP */
	"invalid topology",			/* MPI_ERR_TOPOLOGY */
	"invalid dimension argument",		/* MPI_ERR_DIMS */
	"invalid argument",			/* MPI_ERR_ARG */
	"unknown error",			/* MPI_ERR_UNKNOWN */
	"message truncated",			/* MPI_ERR_TRUNCATE */
	"unclassified",				/* MPI_ERR_OTHER */
	"internal MPI error",			/* MPI_ERR_INTERN */
	"error code is in status",		/* MPI_ERR_IN_STATUS */
	"pending request",			/* MPI_ERR_PENDING */
	"out of system resources",		/* MPI_ERR_SYSRESOURCE */
	"process in local group is dead",	/* MPI_ERR_LOCALDEAD */
	"process in remote group is dead",	/* MPI_ERR_REMOTEDEAD */
	"info value truncated",			/* MPI_ERR_VALUE */
	"mismatched run-time flags",		/* MPI_ERR_FLAGS */
	"publishing service",			/* MPI_ERR_SERVICE */
	"publishing service",			/* MPI_ERR_NAME */
	"error spawning process",		/* MPI_ERR_SPAWN */
	"invalid key value",			/* MPI_ERR_KEYVAL */
	"no such info key",			/* MPI_ERR_INFO_NOKEY */
	"invalid window",			/* MPI_ERR_WIN */
	"invalid epoch",			/* MPI_ERR_EPOCH */
	"operation not supported on type",	/* MPI_ERR_TYPENOTSUP */
	"invalid info key",			/* MPI_ERR_INFO_KEY */
	"invalid info value",			/* MPI_ERR_INFO_VALUE */
	"could not allocate memory",		/* MPI_ERR_NOMEM */
	"invalid base argument",		/* MPI_ERR_BASE */
	"last error code (huh?)",		/* MPI_ERR_LASTCODE */
	};

/*@
   MPI_Error_string - Return a string for a given error code

Input Parameters:
. errcode - Error code returned by an MPI routine or an MPI error
class

Output Parameter:
+ msg - Text that corresponds to the errorcode 
- plen - Length of string 

Notes:  

Error codes are the values return by MPI routines (in C) or in the
'ierr' argument (in Fortran).  These can be converted into error
classes with the routine 'MPI_Error_class'.

These messages are provided in English (En_US - English/United
States).  If there is an interest in providing messages in different
languages, please submit requests to the LAM mailing list (see
'http://www.lam-mpi.org/contact.php').

.N fortran

.N ACK
@*/
int MPI_Error_string(int errcode, char *msg, 
		     int *plen)
{
	int		class;			/* error class */
	int		funct;			/* error function */
	int		error;			/* UNIX errno */
	int		err;			/* function error code */
	unint		len;			/* error message length */
	char		*p;			/* favourite pointer */
	char		buf[MPI_MAX_ERROR_STRING]; /* error message buffer */

	lam_initerr();
	lam_setfunc(BLKMPIERRSTRING);
/*
 * Check the arguments.
 */
	if ((msg == 0) || (plen == 0)) {
		return(lam_errfunc(MPI_COMM_WORLD,
			BLKMPIERRSTRING, lam_mkerr(MPI_ERR_ARG, EINVAL)));
	}
/*
 * Create the error message string.
 */
	err = MPI_SUCCESS;

	if (errcode == 0) {
		sprintf(buf, "MPI: no errors");
	}

	else {
		lam_bkerr(errcode, &class, &funct, &error);
		strcpy(buf, "");

		if (funct == 0) {
			funct = lam_getfunc();
		}

		if ((p = blktype(funct))) {
			strcat(buf, p);
			strcat(buf, ": ");
		}

		if ((class > 0) && (class < MPI_ERR_LASTCODE)) {
			strcat(buf, mpierrmsg[class]);
		} else {
			strcat(buf, "unknown error class");
			err = lam_mkerr(MPI_ERR_ARG, EINVAL);
		}

		if (error > 0) {
			strcat(buf, ": ");
			LAMSetLastError(error);
			len = strlen(buf);
			lam_errorstr(buf + len, MPI_MAX_ERROR_STRING - len);
		}
	}
/*
 * Fill the user's message buffer.
 */
	lam_strncpy(msg, buf, MPI_MAX_ERROR_STRING - 1);
	msg[MPI_MAX_ERROR_STRING - 1] = '\0';
	*plen = strlen(msg);

	if (err != MPI_SUCCESS) {
		return(lam_errfunc(MPI_COMM_WORLD, BLKMPIERRSTRING, err));
	}

	lam_resetfunc(BLKMPIERRSTRING);
	return(MPI_SUCCESS);
}