IFPACK  Development
 All Classes Namespaces Files Functions Variables Enumerations Friends Pages
macros_dh.h
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef MACROS_DH
44 #define MACROS_DH
45 
46 #if defined(Ifpack_SHOW_DEPRECATED_WARNINGS)
47 #ifdef __GNUC__
48 #warning "The Ifpack package is deprecated"
49 #endif
50 #endif
51 
52 #ifndef FMAX
53 #define FMAX(a,b) ((FABS(a)) > (FABS(b)) ? (FABS(a)) : (FABS(b)))
54 #endif
55 
56 #ifndef MAX
57 #define MAX(a,b) ((a) > (b) ? (a) : (b))
58 #endif
59 
60 #ifndef MIN
61 #define MIN(a,b) ((a)<(b)?(a):(b))
62 #endif
63 
64 #ifndef ABS
65 #define ABS(x) (((x)<0)?(-(x)):(x))
66 #endif
67 
68 #ifndef FABS
69 #define FABS(a) ((a) < 0 ? -(a) : a)
70 #endif
71 
72 /* used in Mat_SEQ_PrintTriples, so matlab won't discard zeros (yuck!) */
73 #define _MATLAB_ZERO_ 1e-100
74 
75 
76 /*----------------------------------------------------------------------
77  * macros for error handling everyplace except in main.
78  *---------------------------------------------------------------------- */
79 
80 /* for future expansion: should check that "ptr" points to
81  a valid memory address, if not null.
82 */
83 #define ASSERT_DH(ptr) \
84  { \
85  if (ptr == NULL) { \
86  sprintf(msgBuf_dh, "%s is NULL", ptr); \
87  SET_V_ERROR(msgBuf_dh); \
88  } \
89  }
90 
91 
92 #if 0
93 #define CHECK_MPI_V_ERROR(errCode) \
94  { \
95  if (errCode) { \
96  int len; \
97  MPI_Error_string(errCode, msgBuf_dh, &len); \
98  setError_dh(msgBuf_dh, __FUNC__, __FILE__, __LINE__); \
99  return; \
100  } \
101  }
102 
103 #define CHECK_MPI_ERROR(errCode) \
104  { \
105  if (errCode) { \
106  int len; \
107  MPI_Error_string(errCode, msgBuf_dh, &len); \
108  setError_dh(msgBuf_dh, __FUNC__, __FILE__, __LINE__); \
109  return(errCode); \
110  } \
111  }
112 #endif
113 
114 #define CHECK_MPI_V_ERROR(errCode) \
115  { \
116  if (errCode) { \
117  setError_dh("MPI error!", __FUNC__, __FILE__, __LINE__); \
118  printErrorMsg(stderr); \
119  MPI_Abort(comm_dh, -1); \
120  } \
121  }
122 
123 #define CHECK_MPI_ERROR(errCode) \
124  { \
125  if (errCode) { \
126  setError_dh("MPI error!", __FUNC__, __FILE__, __LINE__); \
127  printErrorMsg(stderr); \
128  MPI_Abort(comm_dh, -1); \
129  } \
130  }
131 
132 #define SET_V_ERROR(msg) \
133  { setError_dh(msg, __FUNC__, __FILE__, __LINE__); \
134  printErrorMsg(stderr); \
135  MPI_Abort(comm_dh, -1); \
136  }
137 
138 #define SET_ERROR(retval, msg) \
139  { setError_dh(msg, __FUNC__, __FILE__, __LINE__); \
140  printErrorMsg(stderr); \
141  MPI_Abort(comm_dh, -1); \
142  }
143 
144 #define CHECK_V_ERROR \
145  if (errFlag_dh) { \
146  setError_dh("", __FUNC__, __FILE__, __LINE__); \
147  printErrorMsg(stderr); \
148  MPI_Abort(comm_dh, -1); \
149  }
150 
151 #define CHECK_ERROR(retval) \
152  if (errFlag_dh) { \
153  setError_dh("", __FUNC__, __FILE__, __LINE__); \
154  printErrorMsg(stderr); \
155  MPI_Abort(comm_dh, -1); \
156  }
157 
158 /*----------------------------------------------------------------------
159  * informational macros
160  *---------------------------------------------------------------------- */
161 
162 #define SET_INFO(msg) setInfo_dh(msg, __FUNC__, __FILE__, __LINE__);
163 
164 /*----------------------------------------------------------------------
165  * macros for tracking the function call stack
166  *---------------------------------------------------------------------- */
167 #ifdef OPTIMIZED_DH
168 
169 #define START_FUNC_DH \
170  dh_StartFunc(__FUNC__, __FILE__, __LINE__, 1); \
171  {
172 
173 #define END_FUNC_DH \
174  } \
175  dh_EndFunc(__FUNC__, 1);
176 
177 #define END_FUNC_VAL(a) \
178  dh_EndFunc(__FUNC__, 1); \
179  return a ; \
180  }
181 
182 #define START_FUNC_DH_2
183 #define END_FUNC_DH_2
184 #define END_FUNC_VAL_2(a) return a ;
185 #else
186 
187 #define START_FUNC_DH \
188  dh_StartFunc(__FUNC__, __FILE__, __LINE__, 1); \
189  if (logFuncsToStderr || logFuncsToFile)\
190  Error_dhStartFunc(__FUNC__, __FILE__, __LINE__); \
191  {
192 
193 #define END_FUNC_DH \
194  dh_EndFunc(__FUNC__, 1); \
195  if (logFuncsToStderr || logFuncsToFile) \
196  Error_dhEndFunc(__FUNC__); \
197  return; \
198  } \
199 
200 #define START_FUNC_DH_2 \
201  dh_StartFunc(__FUNC__, __FILE__, __LINE__, 2); \
202  if (logFuncsToStderr || logFuncsToFile)\
203  Error_dhStartFunc(__FUNC__, __FILE__, __LINE__); \
204  {
205 
206 #define END_FUNC_DH_2 \
207  dh_EndFunc(__FUNC__, 2); \
208  if (logFuncsToStderr || logFuncsToFile) \
209  Error_dhEndFunc(__FUNC__); \
210  return; \
211  } \
212 
213 
214 #define END_FUNC_VAL(retval) \
215  dh_EndFunc(__FUNC__, 1); \
216  if (logFuncsToStderr || logFuncsToFile) \
217  Error_dhEndFunc(__FUNC__); \
218  return(retval); \
219  } \
220 
221 #define END_FUNC_VAL_2(retval) \
222  dh_EndFunc(__FUNC__, 2); \
223  if (logFuncsToStderr || logFuncsToFile) \
224  Error_dhEndFunc(__FUNC__); \
225  return(retval); \
226  } \
227 
228 
229 #endif
230 
231 #endif /* #ifndef MACROS_DH */