1 /* Copyright 2004,2007,2008,2011 ENSEIRB, INRIA & CNRS
2 **
3 ** This file is part of the Scotch software package for static mapping,
4 ** graph partitioning and sparse matrix ordering.
5 **
6 ** This software is governed by the CeCILL-C license under French law
7 ** and abiding by the rules of distribution of free software. You can
8 ** use, modify and/or redistribute the software under the terms of the
9 ** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
10 ** URL: "http://www.cecill.info".
11 **
12 ** As a counterpart to the access to the source code and rights to copy,
13 ** modify and redistribute granted by the license, users are provided
14 ** only with a limited warranty and the software's author, the holder of
15 ** the economic rights, and the successive licensors have only limited
16 ** liability.
17 **
18 ** In this respect, the user's attention is drawn to the risks associated
19 ** with loading, using, modifying and/or developing or reproducing the
20 ** software by the user in light of its specific status of free software,
21 ** that may mean that it is complicated to manipulate, and that also
22 ** therefore means that it is reserved for developers and experienced
23 ** professionals having in-depth computer knowledge. Users are therefore
24 ** encouraged to load and test the software's suitability as regards
25 ** their requirements in conditions enabling the security of their
26 ** systems and/or data to be ensured and, more generally, to use and
27 ** operate it in the same conditions as regards security.
28 **
29 ** The fact that you are presently reading this means that you have had
30 ** knowledge of the CeCILL-C license and that you accept its terms.
31 */
32 /************************************************************/
33 /**                                                        **/
34 /**   NAME       : library_error.c                         **/
35 /**                                                        **/
36 /**   AUTHOR     : Francois PELLEGRINI                     **/
37 /**                                                        **/
38 /**   FUNCTION   : This module provides error handling     **/
39 /**                routines to process errors generated by **/
40 /**                the routines of the libSCOTCH library.  **/
41 /**                                                        **/
42 /**   DATES      : # Version 3.3  : from : 02 oct 1998     **/
43 /**                                 to     02 oct 1998     **/
44 /**                # Version 3.4  : from : 01 nov 2001     **/
45 /**                                 to     01 nov 2001     **/
46 /**                # Version 5.0  : from : 06 mar 2008     **/
47 /**                                 to     24 may 2008     **/
48 /**                # Version 5.1  : from : 27 sep 2008     **/
49 /**                                 to     17 jul 2011     **/
50 /**                                                        **/
51 /************************************************************/
52 
53 /*
54 **  The defines and includes.
55 */
56 
57 #define LIBRARY_ERROR
58 
59 #include "module.h"
60 #include "common.h"
61 #include "scotch.h"
62 
63 /********************************/
64 /*                              */
65 /* The error handling routines. */
66 /*                              */
67 /********************************/
68 
69 static char                 _SCOTCHerrorProgName[32] = "";
70 
71 /* This routine sets the program name for
72 ** error reporting.
73 ** It returns:
74 ** - VOID  : in all cases.
75 */
76 
77 void
SCOTCH_errorProg(const char * const progstr)78 SCOTCH_errorProg (
79 const char * const          progstr)              /*+ Program name +*/
80 {
81   int                 charnbr;
82   const char *        nsrcptr;
83   char *              ndstptr;
84 
85   nsrcptr = progstr;
86   ndstptr = _SCOTCHerrorProgName;
87   charnbr = strlen (progstr);
88   if (charnbr > 31) {
89     _SCOTCHerrorProgName[0] =
90     _SCOTCHerrorProgName[1] =
91     _SCOTCHerrorProgName[2] = '.';
92     ndstptr += 3;
93     nsrcptr += charnbr - 28;
94     charnbr  = 28;
95   }
96   strncpy (ndstptr, nsrcptr, charnbr);
97   _SCOTCHerrorProgName[31] = '\0';
98 }
99 
100 /* This routine prints an error message with
101 ** a variable number of arguments, as printf ()
102 ** does, and exits.
103 ** It returns:
104 ** - void  : in all cases.
105 */
106 
107 void
SCOTCH_errorPrint(const char * const errstr,...)108 SCOTCH_errorPrint (
109 const char * const          errstr,               /*+ printf-like variable argument list */
110 ...)
111 {
112   va_list             errlist;                    /* The argument list of the call */
113 #ifdef SCOTCH_PTSCOTCH
114   int                 proclocnum;
115 #endif /* SCOTCH_PTSCOTCH */
116 
117   fprintf  (stderr, "%s", _SCOTCHerrorProgName);
118 #ifdef SCOTCH_PTSCOTCH
119   if ((MPI_Initialized (&proclocnum) == MPI_SUCCESS) &&
120       (proclocnum != 0)                              &&
121       (MPI_Comm_rank (MPI_COMM_WORLD, &proclocnum) == MPI_SUCCESS))
122     fprintf (stderr, "(%d): ", proclocnum);
123   else
124     fprintf (stderr, ": ");
125 #else /* SCOTCH_PTSCOTCH */
126   if (_SCOTCHerrorProgName[0] != '\0')
127     fprintf  (stderr, ": ");
128 #endif /* SCOTCH_PTSCOTCH */
129   fprintf  (stderr, "ERROR: ");
130   va_start (errlist, errstr);
131   vfprintf (stderr, errstr, errlist);             /* Print arguments */
132   va_end   (errlist);
133   fprintf  (stderr, "\n");
134   fflush   (stderr);                              /* In case it has been set to buffered mode */
135 }
136 
137 /* This routine prints a warning message with
138 ** a variable number of arguments, as printf ()
139 ** does.
140 ** It returns:
141 ** - VOID  : in all cases.
142 */
143 
144 void
SCOTCH_errorPrintW(const char * const errstr,...)145 SCOTCH_errorPrintW (
146 const char * const          errstr,               /*+ printf-like variable argument list */
147 ...)
148 {
149   va_list             errlist;                    /* The argument list of the call */
150 #ifdef SCOTCH_PTSCOTCH
151   int                 proclocnum;
152 #endif /* SCOTCH_PTSCOTCH */
153 
154   fprintf  (stderr, "%s", _SCOTCHerrorProgName);
155 #ifdef SCOTCH_PTSCOTCH
156   if ((MPI_Initialized (&proclocnum) == MPI_SUCCESS) &&
157       (proclocnum != 0)                              &&
158       (MPI_Comm_rank (MPI_COMM_WORLD, &proclocnum) == MPI_SUCCESS))
159     fprintf (stderr, "(%d): ", proclocnum);
160   else
161     fprintf (stderr, ": ");
162 #else /* SCOTCH_PTSCOTCH */
163   if (_SCOTCHerrorProgName[0] != '\0')
164     fprintf  (stderr, ": ");
165 #endif /* SCOTCH_PTSCOTCH */
166   fprintf  (stderr, "WARNING: ");
167   va_start (errlist, errstr);
168   vfprintf (stderr, errstr, errlist);             /* Print arguments */
169   va_end   (errlist);
170   fprintf  (stderr, "\n");
171   fflush   (stderr);                              /* In case it has been set to buffered mode */
172 }
173