| 1 |
c* /////////////////////////////////////////////////////////////////////////// |
| 2 |
c* @file mblasd.f |
| 3 |
c* @author Michael Holst |
| 4 |
c* @brief Micro version of the BLAS needed for low-level PMG support. |
| 5 |
c* @version $Id: mblasd.f,v 1.2 2010/08/12 05:45:33 fetk Exp $ |
| 6 |
c* @attention |
| 7 |
c* @verbatim |
| 8 |
c* |
| 9 |
c* PMG -- Parallel algebraic MultiGrid |
| 10 |
c* Copyright (C) 1994-- Michael Holst. |
| 11 |
c* |
| 12 |
c* Michael Holst <[email protected]> |
| 13 |
c* University of California, San Diego |
| 14 |
c* Department of Mathematics, 5739 AP&M |
| 15 |
c* 9500 Gilman Drive, Dept. 0112 |
| 16 |
c* La Jolla, CA 92093-0112 USA |
| 17 |
c* http://math.ucsd.edu/~mholst |
| 18 |
c* |
| 19 |
c* This file is part of PMG. |
| 20 |
c* |
| 21 |
c* PMG is free software; you can redistribute it and/or modify |
| 22 |
c* it under the terms of the GNU General Public License as published by |
| 23 |
c* the Free Software Foundation; either version 2 of the License, or |
| 24 |
c* (at your option) any later version. |
| 25 |
c* |
| 26 |
c* PMG is distributed in the hope that it will be useful, |
| 27 |
c* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 |
c* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 |
c* GNU General Public License for more details. |
| 30 |
c* |
| 31 |
c* You should have received a copy of the GNU General Public License |
| 32 |
c* along with PMG; if not, write to the Free Software |
| 33 |
c* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 34 |
c* |
| 35 |
c* Linking PMG statically or dynamically with other modules is making a |
| 36 |
c* combined work based on PMG. Thus, the terms and conditions of the GNU |
| 37 |
c* General Public License cover the whole combination. |
| 38 |
c* |
| 39 |
c* SPECIAL GPL EXCEPTION |
| 40 |
c* In addition, as a special exception, the copyright holders of PMG |
| 41 |
c* give you permission to combine the PMG program with free software |
| 42 |
c* programs and libraries that are released under the GNU LGPL or with |
| 43 |
c* code included in releases of ISIM, PMV, PyMOL, SMOL, VMD, and Vision. |
| 44 |
c* Such combined software may be linked with PMG and redistributed together |
| 45 |
c* in original or modified form as mere aggregation without requirement that |
| 46 |
c* the entire work be under the scope of the GNU General Public License. |
| 47 |
c* This special exception permission is also extended to any software listed |
| 48 |
c* in the SPECIAL GPL EXCEPTION clauses by the FEtk and APBS libraries. |
| 49 |
c* |
| 50 |
c* Note that people who make modified versions of PMG are not obligated |
| 51 |
c* to grant this special exception for their modified versions; it is |
| 52 |
c* their choice whether to do so. The GNU General Public License gives |
| 53 |
c* permission to release a modified version without this exception; this |
| 54 |
c* exception also makes it possible to release a modified version which |
| 55 |
c* carries forward this exception. |
| 56 |
c* |
| 57 |
c* @endverbatim |
| 58 |
c* /////////////////////////////////////////////////////////////////////////// |
| 59 |
|
| 60 |
subroutine daxpy(n,alpha,x,istep,y,jstep) |
| 61 |
c* ********************************************************************* |
| 62 |
c* purpose: |
| 63 |
c* |
| 64 |
c* parallel/vector vector saxpy. |
| 65 |
c* |
| 66 |
c* author: michael holst |
| 67 |
c* ********************************************************************* |
| 68 |
implicit none |
| 69 |
double precision x(*),y(*),alpha |
| 70 |
integer n,istep,jstep,i,ii,nproc,ipara,ivect |
| 71 |
parameter (nproc=1) |
| 72 |
c* |
| 73 |
cmdir 0 0 |
| 74 |
c* |
| 75 |
c* *** find parallel loops (ipara), remainder (ivect) *** |
| 76 |
ipara = n / nproc |
| 77 |
ivect = mod(n,nproc) |
| 78 |
c* |
| 79 |
c* *** do parallel loops *** |
| 80 |
cmdir 2 1 |
| 81 |
do 10 ii = 1, nproc |
| 82 |
cmdir 2 2 |
| 83 |
do 11 i = 1+(ipara*(ii-1)), ipara*ii |
| 84 |
y(i) = y(i) + alpha * x(i) |
| 85 |
11 continue |
| 86 |
10 continue |
| 87 |
c* |
| 88 |
c* *** do vector loops *** |
| 89 |
cmdir 1 1 |
| 90 |
do 20 i = ipara*nproc+1, n |
| 91 |
y(i) = y(i) + alpha * x(i) |
| 92 |
20 continue |
| 93 |
c* |
| 94 |
c* *** return and end *** |
| 95 |
return |
| 96 |
end |
| 97 |
subroutine dcopy(n,x,istep,y,jstep) |
| 98 |
c* ********************************************************************* |
| 99 |
c* purpose: |
| 100 |
c* |
| 101 |
c* parallel/vector vector copy. |
| 102 |
c* |
| 103 |
c* author: michael holst |
| 104 |
c* ********************************************************************* |
| 105 |
implicit none |
| 106 |
double precision x(*),y(*) |
| 107 |
integer n,istep,jstep,i,ii,nproc,ipara,ivect |
| 108 |
parameter (nproc=1) |
| 109 |
c* |
| 110 |
cmdir 0 0 |
| 111 |
c* |
| 112 |
c* *** find parallel loops (ipara), remainder (ivect) *** |
| 113 |
ipara = n / nproc |
| 114 |
ivect = mod(n,nproc) |
| 115 |
c* |
| 116 |
c* *** do parallel loops *** |
| 117 |
cmdir 2 1 |
| 118 |
do 10 ii = 1, nproc |
| 119 |
cmdir 2 2 |
| 120 |
do 11 i = 1+(ipara*(ii-1)), ipara*ii |
| 121 |
y(i) = x(i) |
| 122 |
11 continue |
| 123 |
10 continue |
| 124 |
c* |
| 125 |
c* *** do vector loops *** |
| 126 |
cmdir 1 1 |
| 127 |
do 20 i = ipara*nproc+1, n |
| 128 |
y(i) = x(i) |
| 129 |
20 continue |
| 130 |
c* |
| 131 |
c* *** return and end *** |
| 132 |
return |
| 133 |
end |
| 134 |
function dasum(n,x,istep) |
| 135 |
c* ********************************************************************* |
| 136 |
c* purpose: |
| 137 |
c* |
| 138 |
c* parallel/vector sum of vector components. |
| 139 |
c* |
| 140 |
c* author: michael holst |
| 141 |
c* ********************************************************************* |
| 142 |
implicit none |
| 143 |
double precision x(*) |
| 144 |
double precision dasum,dnrm1 |
| 145 |
integer n,istep |
| 146 |
c* |
| 147 |
cmdir 0 0 |
| 148 |
c* |
| 149 |
c* *** call the max-norm function *** |
| 150 |
dasum = dnrm1(n,x,istep) |
| 151 |
c* |
| 152 |
c* *** return and end *** |
| 153 |
return |
| 154 |
end |
| 155 |
function dnrm1(n,x,istep) |
| 156 |
c* ********************************************************************* |
| 157 |
c* purpose: |
| 158 |
c* |
| 159 |
c* parallel/vector vector norm. |
| 160 |
c* |
| 161 |
c* author: michael holst |
| 162 |
c* ********************************************************************* |
| 163 |
implicit none |
| 164 |
double precision x(*) |
| 165 |
double precision tmp,dnrm1 |
| 166 |
integer n,istep,i,ii,nproc,ipara,ivect |
| 167 |
parameter (nproc=1) |
| 168 |
c* |
| 169 |
cmdir 0 0 |
| 170 |
c* |
| 171 |
c* *** initialize *** |
| 172 |
tmp = 0.0d0 |
| 173 |
c* |
| 174 |
c* *** find parallel loops (ipara), remainder (ivect) *** |
| 175 |
ipara = n / nproc |
| 176 |
ivect = mod(n,nproc) |
| 177 |
c* |
| 178 |
c* *** do parallel loops *** |
| 179 |
cmdir 2 1 |
| 180 |
do 10 ii = 1, nproc |
| 181 |
cmdir 2 2 |
| 182 |
do 11 i = 1+(ipara*(ii-1)), ipara*ii |
| 183 |
tmp = tmp + dabs(x(i)) |
| 184 |
11 continue |
| 185 |
10 continue |
| 186 |
c* |
| 187 |
c* *** do vector loops *** |
| 188 |
cmdir 1 1 |
| 189 |
do 20 i = ipara*nproc+1, n |
| 190 |
tmp = tmp + dabs(x(i)) |
| 191 |
20 continue |
| 192 |
c* |
| 193 |
c* *** finish up *** |
| 194 |
dnrm1 = tmp |
| 195 |
c* |
| 196 |
c* *** return and end *** |
| 197 |
return |
| 198 |
end |
| 199 |
function dnrm2(n,x,istep) |
| 200 |
c* ********************************************************************* |
| 201 |
c* purpose: |
| 202 |
c* |
| 203 |
c* parallel/vector vector norm. |
| 204 |
c* |
| 205 |
c* author: michael holst |
| 206 |
c* ********************************************************************* |
| 207 |
implicit none |
| 208 |
double precision x(*) |
| 209 |
double precision tmp,dnrm2 |
| 210 |
integer n,istep,i,ii,nproc,ipara,ivect |
| 211 |
parameter (nproc=1) |
| 212 |
c* |
| 213 |
cmdir 0 0 |
| 214 |
c* |
| 215 |
c* *** initialize *** |
| 216 |
tmp = 0.0d0 |
| 217 |
c* |
| 218 |
c* *** find parallel loops (ipara), remainder (ivect) *** |
| 219 |
ipara = n / nproc |
| 220 |
ivect = mod(n,nproc) |
| 221 |
c* |
| 222 |
c* *** do parallel loops *** |
| 223 |
cmdir 2 1 |
| 224 |
do 10 ii = 1, nproc |
| 225 |
cmdir 2 2 |
| 226 |
do 11 i = 1+(ipara*(ii-1)), ipara*ii |
| 227 |
tmp = tmp + x(i)*x(i) |
| 228 |
11 continue |
| 229 |
10 continue |
| 230 |
c* |
| 231 |
c* *** do vector loops *** |
| 232 |
cmdir 1 1 |
| 233 |
do 20 i = ipara*nproc+1, n |
| 234 |
tmp = tmp + x(i)*x(i) |
| 235 |
20 continue |
| 236 |
c* |
| 237 |
c* *** finish up *** |
| 238 |
dnrm2 = dsqrt(tmp) |
| 239 |
c* |
| 240 |
c* *** return and end *** |
| 241 |
return |
| 242 |
end |
| 243 |
function dnrm8(n,x,istep) |
| 244 |
c* ********************************************************************* |
| 245 |
c* purpose: |
| 246 |
c* |
| 247 |
c* parallel/vector vector norm. |
| 248 |
c* |
| 249 |
c* author: michael holst |
| 250 |
c* ********************************************************************* |
| 251 |
implicit none |
| 252 |
double precision x(*) |
| 253 |
double precision tmp,dnrm8 |
| 254 |
integer n,istep,i,ii,nproc,ipara,ivect |
| 255 |
parameter (nproc=1) |
| 256 |
c* |
| 257 |
cmdir 0 0 |
| 258 |
c* |
| 259 |
c* *** initialize *** |
| 260 |
tmp = 0.0d0 |
| 261 |
c* |
| 262 |
c* *** find parallel loops (ipara), remainder (ivect) *** |
| 263 |
ipara = n / nproc |
| 264 |
ivect = mod(n,nproc) |
| 265 |
c* |
| 266 |
c* *** do parallel loops *** |
| 267 |
cmdir 2 1 |
| 268 |
do 10 ii = 1, nproc |
| 269 |
cmdir 2 2 |
| 270 |
do 11 i = 1+(ipara*(ii-1)), ipara*ii |
| 271 |
tmp = dmax1( tmp , dabs(x(i)) ) |
| 272 |
11 continue |
| 273 |
10 continue |
| 274 |
c* |
| 275 |
c* *** do vector loops *** |
| 276 |
cmdir 1 1 |
| 277 |
do 20 i = ipara*nproc+1, n |
| 278 |
tmp = dmax1( tmp , dabs(x(i)) ) |
| 279 |
20 continue |
| 280 |
c* |
| 281 |
c* *** finish up *** |
| 282 |
dnrm8 = tmp |
| 283 |
c* |
| 284 |
c* *** return and end *** |
| 285 |
return |
| 286 |
end |
| 287 |
subroutine dscal(n,fac,x,istep) |
| 288 |
c* ********************************************************************* |
| 289 |
c* purpose: |
| 290 |
c* |
| 291 |
c* parallel/vector vector scale. |
| 292 |
c* |
| 293 |
c* author: michael holst |
| 294 |
c* ********************************************************************* |
| 295 |
implicit none |
| 296 |
double precision x(*),fac |
| 297 |
integer n,istep,i,ii,nproc,ipara,ivect |
| 298 |
parameter (nproc=1) |
| 299 |
c* |
| 300 |
cmdir 0 0 |
| 301 |
c* |
| 302 |
c* *** find parallel loops (ipara), remainder (ivect) *** |
| 303 |
ipara = n / nproc |
| 304 |
ivect = mod(n,nproc) |
| 305 |
c* |
| 306 |
c* *** do parallel loops *** |
| 307 |
cmdir 2 1 |
| 308 |
do 10 ii = 1, nproc |
| 309 |
cmdir 2 2 |
| 310 |
do 11 i = 1+(ipara*(ii-1)), ipara*ii |
| 311 |
x(i) = fac*x(i) |
| 312 |
11 continue |
| 313 |
10 continue |
| 314 |
c* |
| 315 |
c* *** do vector loops *** |
| 316 |
cmdir 1 1 |
| 317 |
do 20 i = ipara*nproc+1, n |
| 318 |
x(i) = fac*x(i) |
| 319 |
20 continue |
| 320 |
c* |
| 321 |
c* *** return and end *** |
| 322 |
return |
| 323 |
end |
| 324 |
function ddot(n,x,istep,y,jstep) |
| 325 |
c* ********************************************************************* |
| 326 |
c* purpose: |
| 327 |
c* |
| 328 |
c* parallel/vector dot product. |
| 329 |
c* |
| 330 |
c* author: michael holst |
| 331 |
c* ********************************************************************* |
| 332 |
implicit none |
| 333 |
double precision x(*),y(*),ddot |
| 334 |
integer n,istep,jstep,i,ii,nproc,ipara,ivect |
| 335 |
parameter (nproc=1) |
| 336 |
c* |
| 337 |
cmdir 0 0 |
| 338 |
c* |
| 339 |
c* *** initialize *** |
| 340 |
ddot = 0.0d0 |
| 341 |
c* |
| 342 |
c* *** find parallel loops (ipara), remainder (ivect) *** |
| 343 |
ipara = n / nproc |
| 344 |
ivect = mod(n,nproc) |
| 345 |
c* |
| 346 |
c* *** do parallel loops *** |
| 347 |
cmdir 2 1 |
| 348 |
do 10 ii = 1, nproc |
| 349 |
cmdir 2 2 |
| 350 |
do 11 i = 1+(ipara*(ii-1)), ipara*ii |
| 351 |
ddot = ddot + x(i)*y(i) |
| 352 |
11 continue |
| 353 |
10 continue |
| 354 |
c* |
| 355 |
c* *** do vector loops *** |
| 356 |
cmdir 1 1 |
| 357 |
do 20 i = ipara*nproc+1, n |
| 358 |
ddot = ddot + x(i)*y(i) |
| 359 |
20 continue |
| 360 |
c* |
| 361 |
c* *** return and end *** |
| 362 |
return |
| 363 |
end |
| 364 |
function idamax(n,sx,incx) |
| 365 |
c* ********************************************************************* |
| 366 |
c* purpose: |
| 367 |
c* |
| 368 |
c* parallel/vector icamax. |
| 369 |
c* |
| 370 |
c* author: michael holst |
| 371 |
c* ********************************************************************* |
| 372 |
implicit none |
| 373 |
integer idamax,n,ns,incx,ii,i |
| 374 |
double precision smax,xmag |
| 375 |
double precision sx(*) |
| 376 |
c* |
| 377 |
cmdir 0 0 |
| 378 |
c* |
| 379 |
idamax = 0 |
| 380 |
if(n.le.0) return |
| 381 |
idamax = 1 |
| 382 |
if(n.le.1)return |
| 383 |
if(incx.eq.1)goto 20 |
| 384 |
c* |
| 385 |
c* code for increments not equal to 1. |
| 386 |
c* |
| 387 |
smax = dabs(sx(1)) |
| 388 |
ns = n*incx |
| 389 |
ii = 1 |
| 390 |
do 10 i=1,ns,incx |
| 391 |
xmag = dabs(sx(i)) |
| 392 |
if(xmag.le.smax) go to 40 |
| 393 |
idamax = ii |
| 394 |
smax = xmag |
| 395 |
40 ii = ii + 1 |
| 396 |
10 continue |
| 397 |
return |
| 398 |
c* |
| 399 |
c* code for increments equal to 1. |
| 400 |
c* |
| 401 |
20 smax = dabs(sx(1)) |
| 402 |
do 30 i = 2,n |
| 403 |
xmag = dabs(sx(i)) |
| 404 |
if(xmag.le.smax) go to 30 |
| 405 |
idamax = i |
| 406 |
smax = xmag |
| 407 |
30 continue |
| 408 |
return |
| 409 |
end |
| 410 |
|