Merge lp:~fluidity-core/fluidity/fluidity-petsc-legacy into lp:fluidity

Proposed by Stephan Kramer
Status: Needs review
Proposed branch: lp:~fluidity-core/fluidity/fluidity-petsc-legacy
Merge into: lp:fluidity
Diff against target: 390 lines (+69/-105)
7 files modified
femtools/Multigrid.F90 (+6/-38)
femtools/Petsc_Tools.F90 (+2/-11)
femtools/Solvers.F90 (+2/-20)
femtools/Sparse_Tools.F90 (+1/-6)
femtools/Sparse_Tools_Petsc.F90 (+1/-13)
include/petsc_legacy.h (+54/-0)
tools/petsc_readnsolve.F90 (+3/-17)
To merge this branch: bzr merge lp:~fluidity-core/fluidity/fluidity-petsc-legacy
Reviewer Review Type Date Requested Status
Michael Lange Pending
Review via email: mp+221192@code.launchpad.net

Description of the change

This cleans up the legacy support for previous PETSc versions a bit, moving most of the #ifdef logic into a single header file. Also adds fixes to make Fluidity build with petsc-dev master

To post a comment you must log in.
4317. By Rhodri Davies

Merge in trunk.

Revision history for this message
Stephan Kramer (s-kramer) wrote :

Unmerged revisions

4317. By Rhodri Davies

Merge in trunk.

4316. By Rhodri Davies

Merge in trunk.

4315. By Stephan Kramer

API change in petsc-dev: flag argument to KSP/PCSetOperators has been dropped.

Passes all short tests (with petsc 'master') after Jed's fixing of MatCreateTranspose.

4314. By Stephan Kramer

Use PetscBool instead of PetscTruth.

4313. By Stephan Kramer

Put all petsc-legacy redefinitions in one header file.

This cleans up some repeated #if PETSC_VERSION stuff in the modules that use fortran.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'femtools/Multigrid.F90'
2--- femtools/Multigrid.F90 2013-01-29 13:20:53 +0000
3+++ femtools/Multigrid.F90 2014-05-29 00:03:29 +0000
4@@ -9,25 +9,11 @@
5 use spud
6 use futils
7 use parallel_tools
8-#include "petscversion.h"
9 #ifdef HAVE_PETSC_MODULES
10 use petsc
11 #endif
12 implicit none
13-#ifdef HAVE_PETSC_MODULES
14-#include "finclude/petscdef.h"
15-#else
16-#include "finclude/petsc.h"
17-#endif
18-#if PETSC_VERSION_MINOR>=2
19-#define KSP_NORM_NO KSP_NORM_NONE
20-#endif
21-#if PETSC_VERSION_MINOR>=3
22-#define MatCreateSeqAIJ myMatCreateSeqAIJ
23-#define MatCreateMPIAIJ myMatCreateMPIAIJ
24-#define MatCreateSeqBAIJ myMatCreateSeqBAIJ
25-#define MatCreateMPIBAIJ myMatCreateMPIBAIJ
26-#endif
27+#include "petsc_legacy.h"
28
29 !! Some parameters that change the behaviour of
30 !! the smoothed aggregation method. All of
31@@ -165,8 +151,7 @@
32 call SetupSmoothedAggregation(internal_smoother_pc, &
33 Internal_Smoother_Mat, ierr, no_top_smoothing=lno_top_smoothing)
34
35- call PCSetOperators(internal_smoother_pc,Internal_Smoother_Mat, &
36- Internal_Smoother_Mat,DIFFERENT_NONZERO_PATTERN,ierr)
37+ call PCSetOperators(internal_smoother_pc,Internal_Smoother_Mat, Internal_Smoother_Mat,DIFFERENT_NONZERO_PATTERN,ierr)
38
39 !set up pc to output
40 myPETSC_NULL_OBJECT=PETSC_NULL_OBJECT
41@@ -599,8 +584,7 @@
42 call SetupSORSmoother(ksp_smoother, matrices(nolevels), &
43 SOR_LOCAL_SYMMETRIC_SWEEP, 20)
44 else
45- call KSPSetOperators(ksp_smoother, matrices(nolevels), matrices(nolevels), &
46- SAME_PRECONDITIONER, ierr)
47+ call KSPSetOperators(ksp_smoother, matrices(nolevels), matrices(nolevels), SAME_PRECONDITIONER, ierr)
48 call KSPSetType(ksp_smoother, KSPPREONLY, ierr)
49 call PCSetType(prec_smoother, PCLU, ierr)
50 call KSPSetTolerances(ksp_smoother, 1.0e-100_PetscReal_kind, 1e-8_PetscReal_kind, 1e10_PetscReal_kind, 300, ierr)
51@@ -633,7 +617,7 @@
52 call KSPSetTolerances(ksp, PETSC_DEFAULT_DOUBLE_PRECISION, &
53 PETSC_DEFAULT_DOUBLE_PRECISION, PETSC_DEFAULT_DOUBLE_PRECISION, &
54 1, ierr)
55- call KSPSetNormType(ksp, KSP_NORM_NO, ierr)
56+ call KSPSetNormType(ksp, KSP_NORM_NONE, ierr)
57
58 call KSPGetPC(ksp, pc, ierr)
59 call PCSetType(pc, PCSOR, ierr)
60@@ -656,7 +640,7 @@
61 PETSC_DEFAULT_DOUBLE_PRECISION, PETSC_DEFAULT_DOUBLE_PRECISION, &
62 0, ierr)
63 call KSPRichardsonSetScale(ksp,real(0.0, kind = PetscReal_kind),ierr)
64- call KSPSetNormType(ksp, KSP_NORM_NO, ierr)
65+ call KSPSetNormType(ksp, KSP_NORM_NONE, ierr)
66
67 call KSPGetPC(ksp, pc, ierr)
68 call PCSetType(pc,PCNONE,ierr)
69@@ -672,21 +656,13 @@
70 PC:: pc
71 PetscErrorCode:: ierr
72
73-#if PETSC_VERSION_MINOR>=3
74 call KSPSetType(ksp, KSPCHEBYSHEV, ierr)
75-#else
76- call KSPSetType(ksp, KSPCHEBYCHEV, ierr)
77-#endif
78 call KSPSetOperators(ksp, matrix, matrix, SAME_PRECONDITIONER, ierr)
79 call KSPSetTolerances(ksp, PETSC_DEFAULT_DOUBLE_PRECISION, &
80 PETSC_DEFAULT_DOUBLE_PRECISION, PETSC_DEFAULT_DOUBLE_PRECISION, &
81 iterations, ierr)
82-#if PETSC_VERSION_MINOR>=3
83 call KSPChebyshevSetEigenvalues(ksp, emax, emin, ierr)
84-#else
85- call KSPChebychevSetEigenvalues(ksp, emax, emin, ierr)
86-#endif
87- call KSPSetNormType(ksp, KSP_NORM_NO, ierr)
88+ call KSPSetNormType(ksp, KSP_NORM_NONE, ierr)
89
90 call KSPGetPC(ksp, pc, ierr)
91 call PCSetType(pc, PCNONE, ierr)
92@@ -699,11 +675,7 @@
93 integer, intent(out):: maxlevels, coarsesize
94 integer, intent(out):: nosmd, nosmu, clustersize
95
96-#if PETSC_VERSION_MINOR>=2
97 PetscBool flag
98-#else
99- PetscTruth flag
100-#endif
101 PetscErrorCode ierr
102
103 call PetscOptionsGetReal('', '-mymg_epsilon', epsilon, flag, ierr)
104@@ -800,11 +772,7 @@
105
106 !
107 call VecCopy(diag, sqrt_diag, ierr)
108-#if PETSC_VERSION_MINOR>=2
109 call VecSqrtAbs(sqrt_diag, ierr)
110-#else
111- call VecSqrt(sqrt_diag, ierr)
112-#endif
113 !
114 call VecDuplicate(sqrt_diag, inv_sqrt_diag, ierr)
115 call VecCopy(sqrt_diag, inv_sqrt_diag, ierr)
116
117=== modified file 'femtools/Petsc_Tools.F90'
118--- femtools/Petsc_Tools.F90 2014-01-10 17:50:49 +0000
119+++ femtools/Petsc_Tools.F90 2014-05-29 00:03:29 +0000
120@@ -26,7 +26,6 @@
121 ! USA
122 #include "fdebug.h"
123 module Petsc_Tools
124-#include "petscversion.h"
125 use FLDebug
126 use Sparse_Tools
127 use parallel_tools
128@@ -42,12 +41,8 @@
129 use petsc
130 #endif
131 implicit none
132-#include "petscversion.h"
133-#ifdef HAVE_PETSC_MODULES
134-#include "finclude/petscdef.h"
135-#else
136-#include "finclude/petsc.h"
137-#endif
138+
139+#include "petsc_legacy.h"
140
141 PetscReal, parameter, private :: dummy_petsc_real = 0.0
142 integer, parameter, public :: PetscReal_kind = kind(dummy_petsc_real)
143@@ -122,10 +117,6 @@
144 logical, public, save :: petsc_test_error_handler_called = .false.
145 public petsc_test_error_handler
146 #if PETSC_VERSION_MINOR>=3
147-#define MatCreateSeqAIJ myMatCreateSeqAIJ
148-#define MatCreateMPIAIJ myMatCreateMPIAIJ
149-#define MatCreateSeqBAIJ myMatCreateSeqBAIJ
150-#define MatCreateMPIBAIJ myMatCreateMPIBAIJ
151 public MatCreateSeqAIJ, MatCreateMPIAIJ, MatCreateSeqBAIJ, MatCreateMPIBAIJ
152 #endif
153 contains
154
155=== modified file 'femtools/Solvers.F90'
156--- femtools/Solvers.F90 2013-11-12 04:47:40 +0000
157+++ femtools/Solvers.F90 2014-05-29 00:03:29 +0000
158@@ -25,7 +25,6 @@
159 ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
160 ! USA
161 #include "fdebug.h"
162-#include "petscversion.h"
163 module solvers
164 use FLDebug
165 use elements
166@@ -49,12 +48,7 @@
167 implicit none
168 ! Module to provide explicit interfaces to matrix solvers.
169
170-#include "petscversion.h"
171-#ifdef HAVE_PETSC_MODULES
172-#include "finclude/petscdef.h"
173-#else
174-#include "finclude/petsc.h"
175-#endif
176+#include "petsc_legacy.h"
177
178 ! stuff used in the PETSc monitor (see petsc_solve_callback_setup() below)
179 integer :: petsc_monitor_iteration = 0
180@@ -1612,7 +1606,7 @@
181 end if
182
183 #if PETSC_VERSION_MINOR<3
184- FLExit("multigrid_near_null_space only available in petsc 3.3")
185+ FLExit("multigrid_near_null_space only available in petsc version>=3.3")
186 #else
187 if (.not. present(petsc_numbering)) then
188 FLAbort("Need petsc_numbering for multigrid near null space")
189@@ -1938,10 +1932,6 @@
190 case ("additive")
191 call pcfieldsplitsettype(pc, PC_COMPOSITE_ADDITIVE, ierr)
192 case ("symmetric_multiplicative")
193-! workaround silly bug in petsc 3.1
194-#ifndef PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE
195-#define PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE PC_COMPOSITE_SYM_MULTIPLICATIVE
196-#endif
197 call pcfieldsplitsettype(pc, PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE, ierr)
198 case default
199 FLAbort("Unknown fieldsplit_type")
200@@ -1964,11 +1954,7 @@
201 PCType:: pctype
202 PetscReal:: rtol, atol, dtol
203 PetscInt:: maxits
204-#if PETSC_VERSION_MINOR>=2
205 PetscBool:: flag
206-#else
207- PetscTruth:: flag
208-#endif
209 PetscErrorCode:: ierr
210
211 ewrite(2, *) 'Using solver options from cache:'
212@@ -2358,11 +2344,7 @@
213 Vec, allocatable, dimension(:) :: null_space_array, rot_null_space_array
214 PetscReal :: norm
215 PetscErrorCode :: ierr
216-#if PETSC_VERSION_MINOR>=2
217 PetscBool :: isnull
218-#else
219- PetscTruth :: isnull
220-#endif
221
222 integer :: i, nnulls, nnodes, comp, dim, universal_nodes
223 logical, dimension(3) :: rot_mask
224
225=== modified file 'femtools/Sparse_Tools.F90'
226--- femtools/Sparse_Tools.F90 2012-12-10 11:07:54 +0000
227+++ femtools/Sparse_Tools.F90 2014-05-29 00:03:29 +0000
228@@ -25,7 +25,6 @@
229 ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
230 ! USA
231 #include "fdebug.h"
232-#include "petscversion.h"
233 module sparse_tools
234 !!< This module implements abstract data types for sparse matrices and
235 !!< operations on them.
236@@ -44,11 +43,7 @@
237
238 implicit none
239
240-#ifdef HAVE_PETSC_MODULES
241-#include "finclude/petsckspdef.h"
242-#else
243-#include "finclude/petsc.h"
244-#endif
245+#include "petsc_legacy.h"
246
247 private
248
249
250=== modified file 'femtools/Sparse_Tools_Petsc.F90'
251--- femtools/Sparse_Tools_Petsc.F90 2013-11-06 11:48:34 +0000
252+++ femtools/Sparse_Tools_Petsc.F90 2014-05-29 00:03:29 +0000
253@@ -29,7 +29,6 @@
254 !!< This module is an extension to the sparse_tools module that
255 !!< implements a csr matrix type 'petsc_csr_matrix' that directly
256 !!< stores the matrix in petsc format.
257-#include "petscversion.h"
258 use FLDebug
259 use Sparse_Tools
260 use Reference_Counting
261@@ -43,18 +42,7 @@
262 use petsc
263 #endif
264 implicit none
265-#ifdef HAVE_PETSC_MODULES
266-#include "finclude/petscdef.h"
267-#else
268-#include "finclude/petsc.h"
269-#endif
270-#if PETSC_VERSION_MINOR>=3
271-#define MatCreateSeqAIJ myMatCreateSeqAIJ
272-#define MatCreateMPIAIJ myMatCreateMPIAIJ
273-#define MatCreateSeqBAIJ myMatCreateSeqBAIJ
274-#define MatCreateMPIBAIJ myMatCreateMPIBAIJ
275-#endif
276-
277+#include "petsc_legacy.h"
278 private
279
280 type petsc_csr_matrix
281
282=== added file 'include/petsc_legacy.h'
283--- include/petsc_legacy.h 1970-01-01 00:00:00 +0000
284+++ include/petsc_legacy.h 2014-05-29 00:03:29 +0000
285@@ -0,0 +1,54 @@
286+! This header file should be included in fortran modules that use petsc
287+! directly after the implicit none. It provides legacy support for building
288+! Fluidity with petsc versions older than the latest released petsc. Where names
289+! have changed this #defines the new name as its older equivalent, so that new
290+! names can be used in the code everywhere. Where interfaces have changed we
291+! still need #ifdef PETSC_VERSION>... in the main code
292+#include "petscversion.h"
293+#ifdef HAVE_PETSC_MODULES
294+#include "finclude/petscdef.h"
295+#else
296+#include "finclude/petsc.h"
297+#endif
298+! this is the one exception where we keep the old names for now (until
299+! we get rid of petsc 3.1 and 3.2 support). MatCreate{Seq|MPI}[B]AIJ()
300+! no longer exists in petsc>=3.3. Instead we need to call MatCreateAIJ()
301+! followed by MatSetUp() (now required). We provide wrapper routines
302+! in the petsc_tools module.
303+#if PETSC_VERSION_MINOR>=3
304+#define MatCreateSeqAIJ myMatCreateSeqAIJ
305+#define MatCreateMPIAIJ myMatCreateMPIAIJ
306+#define MatCreateSeqBAIJ myMatCreateSeqBAIJ
307+#define MatCreateMPIBAIJ myMatCreateMPIBAIJ
308+#endif
309+
310+#if PETSC_VERSION_MINOR<2
311+#define KSP_NORM_NONE KSP_NORM_NO
312+#endif
313+#if PETSC_VERSION_MINOR<3
314+#define KSPCHEBYSHEV KSPCHEBYCHEV
315+#define KSPChebyshevSetEigenvalues KSPChebychevSetEigenvalues
316+#endif
317+#if PETSC_VERSION_MINOR<2
318+#define PetscBool PetscTruth
319+#endif
320+#if PETSC_VERSION_MINOR<2
321+#define VecSqrtAbs VecSqrt
322+#endif
323+! workaround sily bug in petsc 3.1
324+#ifndef PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE
325+#define PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE PC_COMPOSITE_SYM_MULTIPLICATIVE
326+#endif
327+! Changes in petsc-dev (master)
328+! should be changed to use PETSC_DEFAULT_REAL in code when petsc 3.5 is released
329+! (can't use #ifndef cause PETSC_DEFAULT_REAL is a module variable in petsc-dev)
330+#if PETSC_VERSION_MINOR>=4 && PETSC_VERSION_RELEASE==0
331+#define PETSC_DEFAULT_DOUBLE_PRECISION PETSC_DEFAULT_REAL
332+#endif
333+! flag argument to KSP/PCSetOperators() has been dropped:
334+! we use this macro hack which means that the call cannot be split over multiple lines
335+! also note the (ab)use of fortran's case insensivity to avoid recursion
336+#if PETSC_VERSION_MINOR>=4 && PETSC_VERSION_RELEASE==0
337+#define KSPSetOperators(ksp, amat, pmat, flag, ierr) kspsetoperators(ksp, amat, pmat, ierr)
338+#define PCSetOperators(pc, amat, pmat, flag, ierr) pcsetoperators(pc, amat, pmat, ierr)
339+#endif
340
341=== modified file 'tools/petsc_readnsolve.F90'
342--- tools/petsc_readnsolve.F90 2013-06-12 16:58:00 +0000
343+++ tools/petsc_readnsolve.F90 2014-05-29 00:03:29 +0000
344@@ -1,6 +1,5 @@
345 #include "confdefs.h"
346 #include "fdebug.h"
347-#include "petscversion.h"
348 !! Little program that reads in a matrix equation from a file called
349 !! 'matrixdump' in the current directory containing a matrix, rhs vector and
350 !! initial guess, written in PETSc binary format. It then subsequently solves
351@@ -41,20 +40,7 @@
352 use petsc
353 #endif
354 implicit none
355-#ifdef HAVE_PETSC_MODULES
356-#include "finclude/petscvecdef.h"
357-#include "finclude/petscmatdef.h"
358-#include "finclude/petsckspdef.h"
359-#include "finclude/petscpcdef.h"
360-#include "finclude/petscviewerdef.h"
361-#include "finclude/petscisdef.h"
362-#else
363-#include "finclude/petsc.h"
364-#endif
365-! hack around PetscTruth->PetscBool change in petsc 3.2
366-#if PETSC_VERSION_MINOR>=2
367-#define PetscTruth PetscBool
368-#endif
369+#include "petsc_legacy.h"
370 ! options read from command-line (-prns_... options)
371 character(len=4096) filename, flml
372 character(len=FIELD_NAME_LEN):: field
373@@ -154,7 +140,7 @@
374 PC prec
375 Vec y
376 PetscViewer viewer
377- PetscTruth flag
378+ PetscBool flag
379 PetscErrorCode ierr
380 KSPConvergedReason reason
381 type(petsc_numbering_type) petsc_numbering
382@@ -795,7 +781,7 @@
383 character(len=*), intent(out):: filename, flml, field
384 logical, intent(out):: zero_init_guess, scipy, random_rhs
385
386- PetscTruth flag
387+ PetscBool flag
388 PetscErrorCode ierr
389
390 call PetscOptionsGetString('prns_', '-filename', filename, flag, ierr)