template_blas_axpy.h

Go to the documentation of this file.
00001 /* Ergo, version 3.2, a program for linear scaling electronic structure
00002  * calculations.
00003  * Copyright (C) 2012 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
00004  * 
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  * 
00018  * Primary academic reference:
00019  * Kohn−Sham Density Functional Theory Electronic Structure Calculations 
00020  * with Linearly Scaling Computational Time and Memory Usage,
00021  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
00022  * J. Chem. Theory Comput. 7, 340 (2011),
00023  * <http://dx.doi.org/10.1021/ct100611z>
00024  * 
00025  * For further information about Ergo, see <http://www.ergoscf.org>.
00026  */
00027  
00028  /* This file belongs to the template_lapack part of the Ergo source 
00029   * code. The source files in the template_lapack directory are modified
00030   * versions of files originally distributed as CLAPACK, see the
00031   * Copyright/license notice in the file template_lapack/COPYING.
00032   */
00033  
00034 
00035 #ifndef TEMPLATE_BLAS_AXPY_HEADER
00036 #define TEMPLATE_BLAS_AXPY_HEADER
00037 
00038 #include "template_blas_common.h"
00039 
00040 template<class Treal>
00041 int template_blas_axpy(const integer *n, const Treal *da, const Treal *dx, 
00042         const integer *incx, Treal *dy, const integer *incy)
00043 {
00044     /* System generated locals */
00045     integer i__1;
00046     /* Local variables */
00047      integer i__, m, ix, iy, mp1;
00048 /*     constant times a vector plus a vector.   
00049        uses unrolled loops for increments equal to one.   
00050        jack dongarra, linpack, 3/11/78.   
00051        modified 12/3/93, array(1) declarations changed to array(*)   
00052        Parameter adjustments */
00053     --dy;
00054     --dx;
00055     /* Function Body */
00056     if (*n <= 0) {
00057         return 0;
00058     }
00059     if (*da == 0.) {
00060         return 0;
00061     }
00062     if (*incx == 1 && *incy == 1) {
00063         goto L20;
00064     }
00065 /*        code for unequal increments or equal increments   
00066             not equal to 1 */
00067     ix = 1;
00068     iy = 1;
00069     if (*incx < 0) {
00070         ix = (-(*n) + 1) * *incx + 1;
00071     }
00072     if (*incy < 0) {
00073         iy = (-(*n) + 1) * *incy + 1;
00074     }
00075     i__1 = *n;
00076     for (i__ = 1; i__ <= i__1; ++i__) {
00077         dy[iy] += *da * dx[ix];
00078         ix += *incx;
00079         iy += *incy;
00080 /* L10: */
00081     }
00082     return 0;
00083 /*        code for both increments equal to 1   
00084           clean-up loop */
00085 L20:
00086     m = *n % 4;
00087     if (m == 0) {
00088         goto L40;
00089     }
00090     i__1 = m;
00091     for (i__ = 1; i__ <= i__1; ++i__) {
00092         dy[i__] += *da * dx[i__];
00093 /* L30: */
00094     }
00095     if (*n < 4) {
00096         return 0;
00097     }
00098 L40:
00099     mp1 = m + 1;
00100     i__1 = *n;
00101     for (i__ = mp1; i__ <= i__1; i__ += 4) {
00102         dy[i__] += *da * dx[i__];
00103         dy[i__ + 1] += *da * dx[i__ + 1];
00104         dy[i__ + 2] += *da * dx[i__ + 2];
00105         dy[i__ + 3] += *da * dx[i__ + 3];
00106 /* L50: */
00107     }
00108     return 0;
00109 } /* daxpy_ */
00110 
00111 #endif

Generated on Mon Sep 17 14:32:56 2012 for ergo by  doxygen 1.4.7