/usr/share/doc/libsundials-serial-dev/examples/kinsol/fcmix_parallel/fkinDiagon_kry_p.f is in libsundials-serial-dev 2.5.0-3ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | program fkinDiagon_kry_p
c ----------------------------------------------------------------
c $Revision: 1.2 $
c $Date: 2009/09/30 23:42:12 $
c ----------------------------------------------------------------
c Programmer(s): Allan G. Taylor, Alan C. Hindmarsh and
c Radu Serban @ LLNL
c ----------------------------------------------------------------
c Simple diagonal test with Fortran interface, using
c user-supplied preconditioner setup and solve routines (supplied
c in Fortran, below).
c
c This example does a basic test of the solver by solving the
c system:
c f(u) = 0 for
c f(u) = u(i)^2 - i^2
c
c No scaling is done.
c An approximate diagonal preconditioner is used.
c
c Execution command: mpirun -np 4 fkinDiagon_kry_p
c ----------------------------------------------------------------
c
implicit none
include "mpif.h"
integer ier, size, globalstrat, rank, mype, npes
integer maxl, maxlrst
integer*4 localsize
parameter(localsize=32)
integer*4 neq, nlocal, msbpre, baseadd, i, ii
integer*4 iout(15)
double precision rout(2)
double precision pp, fnormtol, scsteptol
double precision uu(localsize), scale(localsize)
double precision constr(localsize)
common /pcom/ pp(localsize), mype, npes, baseadd, nlocal
nlocal = localsize
neq = 4 * nlocal
globalstrat = 0
fnormtol = 1.0d-5
scsteptol = 1.0d-4
maxl = 10
maxlrst = 2
msbpre = 5
c The user MUST call mpi_init, Fortran binding, for the fkinsol package
c to work. The communicator, MPI_COMM_WORLD, is the only one common
c between the Fortran and C bindings. So in the following, the communicator
c MPI_COMM_WORLD is used in calls to mpi_comm_size and mpi_comm_rank
c to determine the total number of processors and the rank (0 ... size-1)
c number of this process.
call mpi_init(ier)
if (ier .ne. 0) then
write(6,1210) ier
1210 format('MPI_ERROR: MPI_INIT returned IER = ', i2)
stop
endif
call fnvinitp(mpi_comm_world, 3, nlocal, neq, ier)
if (ier .ne. 0) then
write(6,1220) ier
1220 format('SUNDIALS_ERROR: FNVINITP returned IER = ', i2)
call mpi_finalize(ier)
stop
endif
call mpi_comm_size(mpi_comm_world, size, ier)
if (ier .ne. 0) then
write(6,1222) ier
1222 format('MPI_ERROR: MPI_COMM_SIZE returned IER = ', i2)
call mpi_abort(mpi_comm_world, 1, ier)
stop
endif
if (size .ne. 4) then
write(6,1230)
1230 format('MPI_ERROR: must use 4 processes')
call mpi_finalize(ier)
stop
endif
npes = size
call mpi_comm_rank(mpi_comm_world, rank, ier)
if (ier .ne. 0) then
write(6,1224) ier
1224 format('MPI_ERROR: MPI_COMM_RANK returned IER = ', i2)
call mpi_abort(mpi_comm_world, 1, ier)
stop
endif
mype = rank
baseadd = mype * nlocal
do 20 ii = 1, nlocal
i = ii + baseadd
uu(ii) = 2.0d0 * i
scale(ii) = 1.0d0
constr(ii) = 0.0d0
20 continue
call fkinmalloc(iout, rout, ier)
if (ier .ne. 0) then
write(6,1231)ier
1231 format('SUNDIALS_ERROR: FKINMALLOC returned IER = ', i2)
call mpi_abort(mpi_comm_world, 1, ier)
stop
endif
call fkinsetiin('MAX_SETUPS', msbpre, ier)
call fkinsetrin('FNORM_TOL', fnormtol, ier)
call fkinsetrin('SSTEP_TOL', scsteptol, ier)
call fkinsetvin('CONSTR_VEC', constr, ier)
call fkinspgmr(maxl, maxlrst, ier)
call fkinspilssetprec(1, ier)
if (mype .eq. 0) write(6,1240)
1240 format('Example program fkinDiagon_kry_p:'//
1 ' This FKINSOL example',
2 ' solves a 128 eqn diagonal algebraic system.'/
3 ' Its purpose is to demonstrate the use of the Fortran',
4 ' interface'/' in a parallel environment.')
call fkinsol(uu, globalstrat, scale, scale, ier)
if (ier .lt. 0) then
write(6,1242) ier, iout(9)
1242 format('SUNDIALS_ERROR: FKINSOL returned IER = ', i2, /,
1 ' Linear Solver returned IER = ', i2)
call mpi_abort(mpi_comm_world, 1, ier)
stop
endif
if (mype .eq. 0) write(6,1245) ier
1245 format(/' FKINSOL return code is ', i4)
if (mype .eq. 0) write(6,1246)
1246 format(/' The resultant values of uu (process 0) are:'/)
do 30 i = 1, nlocal, 4
if(mype .eq. 0) write(6,1256) i + baseadd, uu(i), uu(i+1),
1 uu(i+2), uu(i+3)
1256 format(i4, 4(1x, f10.6))
30 continue
if (mype .eq. 0) write(6,1267) iout(3), iout(14), iout(4),
1 iout(12), iout(13), iout(15)
1267 format(/'Final statistics:'//
1 ' nni = ', i3, ', nli = ', i3, /,
2 ' nfe = ', i3, ', npe = ', i3, /,
3 ' nps = ', i3, ', ncfl = ', i3)
call fkinfree
c An explicit call to mpi_finalize (Fortran binding) is required by
c the constructs used in fkinsol.
call mpi_finalize(ier)
stop
end
c * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
c The function defining the system f(u) = 0 must be defined by a Fortran
c function with the following name and form.
subroutine fkfun(uu, fval, ier)
implicit none
integer mype, npes, ier
integer*4 baseadd, nlocal, i, localsize
parameter(localsize=32)
double precision pp
double precision fval(*), uu(*)
common /pcom/ pp(localsize), mype, npes, baseadd, nlocal
do 10 i = 1, nlocal
10 fval(i) = uu(i) * uu(i) - (i + baseadd) * (i + baseadd)
return
end
c * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
c The routine kpreco is the preconditioner setup routine. It must have
c that specific name be used in order that the c code can find and link
c to it. The argument list must also be as illustrated below:
subroutine fkpset(udata, uscale, fdata, fscale,
1 vtemp1, vtemp2, ier)
implicit none
integer ier, mype, npes
integer*4 localsize
parameter(localsize=32)
integer*4 baseadd, nlocal, i
double precision pp
double precision udata(*), uscale(*), fdata(*), fscale(*)
double precision vtemp1(*), vtemp2(*)
common /pcom/ pp(localsize), mype, npes, baseadd, nlocal
do 10 i = 1, nlocal
10 pp(i) = 0.5d0 / (udata(i)+ 5.0d0)
ier = 0
return
end
c * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
c The routine kpsol is the preconditioner solve routine. It must have
c that specific name be used in order that the c code can find and link
c to it. The argument list must also be as illustrated below:
subroutine fkpsol(udata, uscale, fdata, fscale,
1 vv, ftem, ier)
implicit none
integer ier, mype, npes
integer*4 baseadd, nlocal, i
integer*4 localsize
parameter(localsize=32)
double precision udata(*), uscale(*), fdata(*), fscale(*)
double precision vv(*), ftem(*)
double precision pp
common /pcom/ pp(localsize), mype, npes, baseadd, nlocal
do 10 i = 1, nlocal
10 vv(i) = vv(i) * pp(i)
ier = 0
return
end
|