petsc_macro.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 #ifndef LIBMESH_PETSC_MACRO_H
19 #define LIBMESH_PETSC_MACRO_H
20 
21 // Local includes
22 #include "libmesh/libmesh_config.h"
23 
24 #ifdef LIBMESH_HAVE_PETSC
25 
26 // A convenient macro for comparing PETSc versions. Returns 1 if the
27 // current PETSc version is < major.minor.subminor and zero otherwise.
28 //
29 // This macro does not require petscversion.h to be included for it to work correctly.
30 // It instead relies on the PETSc version numbers detected during configure. Note that if
31 // LIBMESH_HAVE_PETSC is not defined, none of the LIBMESH_DETECTED_PETSC_VERSION_* variables will
32 // be defined either.
33 #define PETSC_VERSION_LESS_THAN(major,minor,subminor) \
34  ((LIBMESH_DETECTED_PETSC_VERSION_MAJOR < (major) || \
35  (LIBMESH_DETECTED_PETSC_VERSION_MAJOR == (major) && (LIBMESH_DETECTED_PETSC_VERSION_MINOR < (minor) || \
36  (LIBMESH_DETECTED_PETSC_VERSION_MINOR == (minor) && \
37  LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR < (subminor))))) ? 1 : 0)
38 
39 // The PETSC_VERSION_RELEASE constant was introduced just prior to 2.3.0 (ca. Apr 22 2005),
40 // so fall back to using PETSC_VERSION_LESS_THAN in case it doesn't exist.
41 #ifdef LIBMESH_DETECTED_PETSC_VERSION_RELEASE
42 
43 #define PETSC_RELEASE_LESS_THAN(major,minor,subminor) \
44  (PETSC_VERSION_LESS_THAN(major,minor,subminor) && LIBMESH_DETECTED_PETSC_VERSION_RELEASE)
45 
46 #else
47 
48 #define PETSC_RELEASE_LESS_THAN(major,minor,subminor) \
49  (PETSC_VERSION_LESS_THAN(major,minor,subminor))
50 
51 #endif
52 
53 // In case the configure test some day fails, we can fall back on including petscversion.h.
54 // In order to support PETSc 2.3.1, however, we need to use a few hacks that allow us to
55 // include petscversion.h without including petsc.h first. These are explained below...
56 //
57 // // We have to jump through some hoops here: in Petsc 2.3.1 you cannot
58 // // include petscversion.h without including petsc.h beforehand. This
59 // // was because petscversion.h relied on the existence of
60 // // PETSC_EXTERN_CXX_BEGIN/END in 2.3.1. The problem is, we don't know
61 // // how to include petsc.h (wrapped or not wrapped in extern "C") until
62 // // we know the version!
63 //
64 // // First figure out if we need to define PETSC_EXTERN_CXX_BEGIN/END to
65 // // make petscversion.h happy
66 // #ifndef PETSC_EXTERN_CXX_BEGIN
67 // # define PETSC_EXTERN_CXX_BEGIN
68 // # define PETSC_EXTERN_CXX_END
69 // # define LIBMESH_PETSC_EXTERN_C_WORKAROUND
70 // #endif
71 //
72 // // Now actually include it
73 // #include <petscversion.h>
74 //
75 // // And finally, get rid of our bogus-definitions. <petsc.h> will set these itself.
76 // #ifdef LIBMESH_PETSC_EXTERN_C_WORKAROUND
77 // # undef PETSC_EXTERN_CXX_BEGIN
78 // # undef PETSC_EXTERN_CXX_END
79 // #endif
80 
81 // Make up for missing extern "C" in old PETSc versions
82 #if !defined(LIBMESH_USE_COMPLEX_NUMBERS) && PETSC_VERSION_LESS_THAN(2,3,0)
83 # define EXTERN_C_FOR_PETSC_BEGIN extern "C" {
84 # define EXTERN_C_FOR_PETSC_END }
85 #else
86 # define EXTERN_C_FOR_PETSC_BEGIN
87 # define EXTERN_C_FOR_PETSC_END
88 #endif
89 
90 
91 // Petsc include files
92 EXTERN_C_FOR_PETSC_BEGIN
93 #include <petsc.h>
94 EXTERN_C_FOR_PETSC_END
95 
96 #if PETSC_RELEASE_LESS_THAN(3,1,1)
97 typedef PetscTruth PetscBool;
98 #endif
99 
100 #if PETSC_RELEASE_LESS_THAN(3,1,1)
101 # define LibMeshVecDestroy(x) VecDestroy(*(x))
102 # define LibMeshVecScatterDestroy(x) VecScatterDestroy(*(x))
103 # define LibMeshMatDestroy(x) MatDestroy(*(x))
104 # define LibMeshISDestroy(x) ISDestroy(*(x))
105 # define LibMeshKSPDestroy(x) KSPDestroy(*(x))
106 # define LibMeshSNESDestroy(x) SNESDestroy(*(x))
107 # define LibMeshPetscViewerDestroy(x) PetscViewerDestroy(*(x))
108 # define LibMeshPCDestroy(x) PCDestroy(*(x))
109 #else
110 # define LibMeshVecDestroy(x) VecDestroy(x)
111 # define LibMeshVecScatterDestroy(x) VecScatterDestroy(x)
112 # define LibMeshMatDestroy(x) MatDestroy(x)
113 # define LibMeshISDestroy(x) ISDestroy(x)
114 # define LibMeshKSPDestroy(x) KSPDestroy(x)
115 # define LibMeshSNESDestroy(x) SNESDestroy(x)
116 # define LibMeshPetscViewerDestroy(x) PetscViewerDestroy(x)
117 # define LibMeshPCDestroy(x) PCDestroy(x)
118 #endif
119 
120 #if PETSC_VERSION_LESS_THAN(2,2,1)
121 // This version of PETSc always makes a copy. Current occurrences of PETSC_USE_POINTER are safe with the definition below.
123 # define ISCreateLibMesh(comm,n,idx,mode,is) \
124  ((mode) == PETSC_OWN_POINTER \
125  ? (ISCreateGeneral((comm),(n),(idx),(is)) || PetscFree(idx) || (*(idx) = PETSC_NULL)) \
126  : (ISCreateGeneral((comm),(n),(idx),(is))))
127 #elif PETSC_RELEASE_LESS_THAN(3,1,1)
129 # define ISCreateLibMesh(comm,n,idx,mode,is) \
130  ((mode) == PETSC_USE_POINTER \
131  ? ISCreateGeneralWithArray((comm),(n),(idx),(is)) \
132  : ((mode) == PETSC_OWN_POINTER \
133  ? ISCreateGeneralNC((comm),(n),(idx),(is)) \
134  : ISCreateGeneral((comm),(n),(idx),(is))))
135 #else
136 # define ISCreateLibMesh(comm,n,idx,mode,is) ISCreateGeneral((comm),(n),(idx),(mode),(is))
137 #endif
138 
139 #define LIBMESH_CHKERRABORT(ierr) CHKERRABORT(this->comm().get(), ierr);
140 
141 #else // LIBMESH_HAVE_PETSC
142 
143 #define PETSC_VERSION_LESS_THAN(major,minor,subminor) 1
144 #define PETSC_RELEASE_LESS_THAN(major,minor,subminor) 1
145 
146 #endif // LIBMESH_HAVE_PETSC
147 
148 #endif // LIBMESH_PETSC_MACRO_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo