macros_dh.h

00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2009) 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 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 */
00029 
00030 #ifndef MACROS_DH
00031 #define MACROS_DH
00032 
00033 #ifndef FMAX
00034 #define FMAX(a,b)  ((FABS(a)) > (FABS(b)) ? (FABS(a)) : (FABS(b)))
00035 #endif
00036 
00037 #ifndef MAX
00038 #define MAX(a,b)   ((a) > (b) ? (a) : (b))
00039 #endif
00040 
00041 #ifndef MIN
00042 #define MIN(a,b) ((a)<(b)?(a):(b))
00043 #endif
00044 
00045 #ifndef ABS
00046 #define ABS(x) (((x)<0)?(-(x)):(x))
00047 #endif
00048 
00049 #ifndef FABS
00050 #define FABS(a)    ((a) < 0 ? -(a) : a)
00051 #endif
00052 
00053 /* used in Mat_SEQ_PrintTriples, so matlab won't discard zeros (yuck!) */
00054 #define _MATLAB_ZERO_  1e-100
00055 
00056 
00057 /*---------------------------------------------------------------------- 
00058  * macros for error handling everyplace except in main.
00059  *---------------------------------------------------------------------- */
00060 
00061 /* for future expansion: should check that "ptr" points to
00062    a valid memory address, if not null.
00063 */
00064 #define ASSERT_DH(ptr) \
00065     { \
00066       if (ptr == NULL) { \
00067         sprintf(msgBuf_dh, "%s is NULL", ptr); \
00068         SET_V_ERROR(msgBuf_dh); \
00069       } \
00070     }
00071 
00072 
00073 #if 0
00074 #define CHECK_MPI_V_ERROR(errCode)  \
00075       { \
00076         if (errCode) { \
00077           int len; \
00078           MPI_Error_string(errCode, msgBuf_dh, &len); \
00079           setError_dh(msgBuf_dh, __FUNC__, __FILE__, __LINE__); \
00080           return; \
00081         } \
00082       }
00083 
00084 #define CHECK_MPI_ERROR(errCode)  \
00085       { \
00086         if (errCode) { \
00087           int len; \
00088           MPI_Error_string(errCode, msgBuf_dh, &len); \
00089           setError_dh(msgBuf_dh, __FUNC__, __FILE__, __LINE__); \
00090           return(errCode); \
00091         } \
00092       }
00093 #endif
00094 
00095 #define CHECK_MPI_V_ERROR(errCode)  \
00096       { \
00097         if (errCode) { \
00098           setError_dh("MPI error!", __FUNC__, __FILE__, __LINE__); \
00099           printErrorMsg(stderr); \
00100           MPI_Abort(comm_dh, -1); \
00101         } \
00102       }
00103 
00104 #define CHECK_MPI_ERROR(errCode)  \
00105       { \
00106         if (errCode) { \
00107           setError_dh("MPI error!", __FUNC__, __FILE__, __LINE__); \
00108           printErrorMsg(stderr); \
00109           MPI_Abort(comm_dh, -1); \
00110         } \
00111       }
00112 
00113 #define SET_V_ERROR(msg)  \
00114       { setError_dh(msg, __FUNC__, __FILE__, __LINE__); \
00115         printErrorMsg(stderr); \
00116         MPI_Abort(comm_dh, -1); \
00117       }
00118 
00119 #define SET_ERROR(retval, msg)  \
00120       { setError_dh(msg, __FUNC__, __FILE__, __LINE__); \
00121         printErrorMsg(stderr); \
00122         MPI_Abort(comm_dh, -1); \
00123       }
00124 
00125 #define CHECK_V_ERROR   \
00126           if (errFlag_dh) { \
00127             setError_dh("",  __FUNC__, __FILE__, __LINE__); \
00128             printErrorMsg(stderr); \
00129             MPI_Abort(comm_dh, -1); \
00130           }
00131 
00132 #define CHECK_ERROR(retval)  \
00133           if (errFlag_dh) { \
00134             setError_dh("",  __FUNC__, __FILE__, __LINE__); \
00135             printErrorMsg(stderr); \
00136             MPI_Abort(comm_dh, -1); \
00137           }
00138 
00139 /*---------------------------------------------------------------------- 
00140  * informational macros
00141  *---------------------------------------------------------------------- */
00142 
00143 #define SET_INFO(msg)  setInfo_dh(msg, __FUNC__, __FILE__, __LINE__);
00144 
00145 /*---------------------------------------------------------------------- 
00146  * macros for tracking the function call stack
00147  *---------------------------------------------------------------------- */
00148 #ifdef OPTIMIZED_DH
00149 
00150 #define START_FUNC_DH   \
00151           dh_StartFunc(__FUNC__, __FILE__, __LINE__, 1);  \
00152           {
00153 
00154 #define END_FUNC_DH     \
00155           } \
00156           dh_EndFunc(__FUNC__, 1);
00157 
00158 #define END_FUNC_VAL(a) \
00159          dh_EndFunc(__FUNC__, 1); \
00160          return a ; \
00161          }
00162 
00163 #define START_FUNC_DH_2 
00164 #define END_FUNC_DH_2 
00165 #define END_FUNC_VAL_2(a) return a ;
00166 #else
00167 
00168 #define START_FUNC_DH  \
00169           dh_StartFunc(__FUNC__, __FILE__, __LINE__, 1); \
00170           if (logFuncsToStderr || logFuncsToFile)\
00171             Error_dhStartFunc(__FUNC__, __FILE__, __LINE__); \
00172           {
00173 
00174 #define END_FUNC_DH   \
00175           dh_EndFunc(__FUNC__, 1); \
00176           if (logFuncsToStderr || logFuncsToFile) \
00177             Error_dhEndFunc(__FUNC__); \
00178           return; \
00179           } \
00180 
00181 #define START_FUNC_DH_2  \
00182           dh_StartFunc(__FUNC__, __FILE__, __LINE__, 2); \
00183           if (logFuncsToStderr || logFuncsToFile)\
00184             Error_dhStartFunc(__FUNC__, __FILE__, __LINE__); \
00185           {
00186 
00187 #define END_FUNC_DH_2   \
00188           dh_EndFunc(__FUNC__, 2); \
00189           if (logFuncsToStderr || logFuncsToFile) \
00190             Error_dhEndFunc(__FUNC__); \
00191           return; \
00192           } \
00193 
00194 
00195 #define END_FUNC_VAL(retval) \
00196           dh_EndFunc(__FUNC__, 1); \
00197           if (logFuncsToStderr || logFuncsToFile) \
00198             Error_dhEndFunc(__FUNC__); \
00199           return(retval); \
00200           } \
00201 
00202 #define END_FUNC_VAL_2(retval) \
00203           dh_EndFunc(__FUNC__, 2); \
00204           if (logFuncsToStderr || logFuncsToFile) \
00205             Error_dhEndFunc(__FUNC__); \
00206           return(retval); \
00207           } \
00208 
00209 
00210 #endif
00211 
00212 #endif /* #ifndef MACROS_DH */

Generated on Wed May 12 21:30:18 2010 for IFPACK by  doxygen 1.4.7