IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
macros_dh.h
00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 */
00042 
00043 #ifndef MACROS_DH
00044 #define MACROS_DH
00045 
00046 #ifndef FMAX
00047 #define FMAX(a,b)  ((FABS(a)) > (FABS(b)) ? (FABS(a)) : (FABS(b)))
00048 #endif
00049 
00050 #ifndef MAX
00051 #define MAX(a,b)   ((a) > (b) ? (a) : (b))
00052 #endif
00053 
00054 #ifndef MIN
00055 #define MIN(a,b) ((a)<(b)?(a):(b))
00056 #endif
00057 
00058 #ifndef ABS
00059 #define ABS(x) (((x)<0)?(-(x)):(x))
00060 #endif
00061 
00062 #ifndef FABS
00063 #define FABS(a)    ((a) < 0 ? -(a) : a)
00064 #endif
00065 
00066 /* used in Mat_SEQ_PrintTriples, so matlab won't discard zeros (yuck!) */
00067 #define _MATLAB_ZERO_  1e-100
00068 
00069 
00070 /*---------------------------------------------------------------------- 
00071  * macros for error handling everyplace except in main.
00072  *---------------------------------------------------------------------- */
00073 
00074 /* for future expansion: should check that "ptr" points to
00075    a valid memory address, if not null.
00076 */
00077 #define ASSERT_DH(ptr) \
00078     { \
00079       if (ptr == NULL) { \
00080         sprintf(msgBuf_dh, "%s is NULL", ptr); \
00081         SET_V_ERROR(msgBuf_dh); \
00082       } \
00083     }
00084 
00085 
00086 #if 0
00087 #define CHECK_MPI_V_ERROR(errCode)  \
00088       { \
00089         if (errCode) { \
00090           int len; \
00091           MPI_Error_string(errCode, msgBuf_dh, &len); \
00092           setError_dh(msgBuf_dh, __FUNC__, __FILE__, __LINE__); \
00093           return; \
00094         } \
00095       }
00096 
00097 #define CHECK_MPI_ERROR(errCode)  \
00098       { \
00099         if (errCode) { \
00100           int len; \
00101           MPI_Error_string(errCode, msgBuf_dh, &len); \
00102           setError_dh(msgBuf_dh, __FUNC__, __FILE__, __LINE__); \
00103           return(errCode); \
00104         } \
00105       }
00106 #endif
00107 
00108 #define CHECK_MPI_V_ERROR(errCode)  \
00109       { \
00110         if (errCode) { \
00111           setError_dh("MPI error!", __FUNC__, __FILE__, __LINE__); \
00112           printErrorMsg(stderr); \
00113           MPI_Abort(comm_dh, -1); \
00114         } \
00115       }
00116 
00117 #define CHECK_MPI_ERROR(errCode)  \
00118       { \
00119         if (errCode) { \
00120           setError_dh("MPI error!", __FUNC__, __FILE__, __LINE__); \
00121           printErrorMsg(stderr); \
00122           MPI_Abort(comm_dh, -1); \
00123         } \
00124       }
00125 
00126 #define SET_V_ERROR(msg)  \
00127       { setError_dh(msg, __FUNC__, __FILE__, __LINE__); \
00128         printErrorMsg(stderr); \
00129         MPI_Abort(comm_dh, -1); \
00130       }
00131 
00132 #define SET_ERROR(retval, msg)  \
00133       { setError_dh(msg, __FUNC__, __FILE__, __LINE__); \
00134         printErrorMsg(stderr); \
00135         MPI_Abort(comm_dh, -1); \
00136       }
00137 
00138 #define CHECK_V_ERROR   \
00139           if (errFlag_dh) { \
00140             setError_dh("",  __FUNC__, __FILE__, __LINE__); \
00141             printErrorMsg(stderr); \
00142             MPI_Abort(comm_dh, -1); \
00143           }
00144 
00145 #define CHECK_ERROR(retval)  \
00146           if (errFlag_dh) { \
00147             setError_dh("",  __FUNC__, __FILE__, __LINE__); \
00148             printErrorMsg(stderr); \
00149             MPI_Abort(comm_dh, -1); \
00150           }
00151 
00152 /*---------------------------------------------------------------------- 
00153  * informational macros
00154  *---------------------------------------------------------------------- */
00155 
00156 #define SET_INFO(msg)  setInfo_dh(msg, __FUNC__, __FILE__, __LINE__);
00157 
00158 /*---------------------------------------------------------------------- 
00159  * macros for tracking the function call stack
00160  *---------------------------------------------------------------------- */
00161 #ifdef OPTIMIZED_DH
00162 
00163 #define START_FUNC_DH   \
00164           dh_StartFunc(__FUNC__, __FILE__, __LINE__, 1);  \
00165           {
00166 
00167 #define END_FUNC_DH     \
00168           } \
00169           dh_EndFunc(__FUNC__, 1);
00170 
00171 #define END_FUNC_VAL(a) \
00172          dh_EndFunc(__FUNC__, 1); \
00173          return a ; \
00174          }
00175 
00176 #define START_FUNC_DH_2 
00177 #define END_FUNC_DH_2 
00178 #define END_FUNC_VAL_2(a) return a ;
00179 #else
00180 
00181 #define START_FUNC_DH  \
00182           dh_StartFunc(__FUNC__, __FILE__, __LINE__, 1); \
00183           if (logFuncsToStderr || logFuncsToFile)\
00184             Error_dhStartFunc(__FUNC__, __FILE__, __LINE__); \
00185           {
00186 
00187 #define END_FUNC_DH   \
00188           dh_EndFunc(__FUNC__, 1); \
00189           if (logFuncsToStderr || logFuncsToFile) \
00190             Error_dhEndFunc(__FUNC__); \
00191           return; \
00192           } \
00193 
00194 #define START_FUNC_DH_2  \
00195           dh_StartFunc(__FUNC__, __FILE__, __LINE__, 2); \
00196           if (logFuncsToStderr || logFuncsToFile)\
00197             Error_dhStartFunc(__FUNC__, __FILE__, __LINE__); \
00198           {
00199 
00200 #define END_FUNC_DH_2   \
00201           dh_EndFunc(__FUNC__, 2); \
00202           if (logFuncsToStderr || logFuncsToFile) \
00203             Error_dhEndFunc(__FUNC__); \
00204           return; \
00205           } \
00206 
00207 
00208 #define END_FUNC_VAL(retval) \
00209           dh_EndFunc(__FUNC__, 1); \
00210           if (logFuncsToStderr || logFuncsToFile) \
00211             Error_dhEndFunc(__FUNC__); \
00212           return(retval); \
00213           } \
00214 
00215 #define END_FUNC_VAL_2(retval) \
00216           dh_EndFunc(__FUNC__, 2); \
00217           if (logFuncsToStderr || logFuncsToFile) \
00218             Error_dhEndFunc(__FUNC__); \
00219           return(retval); \
00220           } \
00221 
00222 
00223 #endif
00224 
00225 #endif /* #ifndef MACROS_DH */
 All Classes Files Functions Variables Enumerations Friends