blas_dh.c

00002 // ***********************************************************************
00003 //
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2009) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00028 */
00029
00030 #include "blas_dh.h"
00031
00032 #undef __FUNC__
00033 #define __FUNC__ "matvec_euclid_seq"
00034 void
00035 matvec_euclid_seq (int n, int *rp, int *cval, double *aval, double *x,
00036            double *y)
00037 {
00038   START_FUNC_DH int i, j;
00039   int from, to, col;
00040   double sum;
00041
00042   if (np_dh > 1)
00043     SET_V_ERROR ("only for sequential case!\n");
00044
00045   {
00046     for (i = 0; i < n; ++i)
00047       {
00048     sum = 0.0;
00049     from = rp[i];
00050     to = rp[i + 1];
00051     for (j = from; j < to; ++j)
00052       {
00053         col = cval[j];
00054         sum += (aval[j] * x[col]);
00055       }
00056     y[i] = sum;
00057       }
00058   }
00059 END_FUNC_DH}
00060
00061 #undef __FUNC__
00062 #define __FUNC__ "Axpy"
00063 void
00064 Axpy (int n, double alpha, double *x, double *y)
00065 {
00066   START_FUNC_DH int i;
00067
00068   for (i = 0; i < n; ++i)
00069     {
00070       y[i] = alpha * x[i] + y[i];
00071     }
00072 END_FUNC_DH}
00073
00074
00075 #undef __FUNC__
00076 #define __FUNC__ "CopyVec"
00077 void
00078 CopyVec (int n, double *xIN, double *yOUT)
00079 {
00080   START_FUNC_DH int i;
00081
00082   for (i = 0; i < n; ++i)
00083     {
00084       yOUT[i] = xIN[i];
00085     }
00086 END_FUNC_DH}
00087
00088
00089 #undef __FUNC__
00090 #define __FUNC__ "ScaleVec"
00091 void
00092 ScaleVec (int n, double alpha, double *x)
00093 {
00094   START_FUNC_DH int i;
00095
00096   for (i = 0; i < n; ++i)
00097     {
00098       x[i] *= alpha;
00099     }
00100 END_FUNC_DH}
00101
00102 #undef __FUNC__
00103 #define __FUNC__ "InnerProd"
00104 double
00105 InnerProd (int n, double *x, double *y)
00106 {
00107   START_FUNC_DH double result, local_result = 0.0;
00108
00109   int i;
00110
00111   for (i = 0; i < n; ++i)
00112     {
00113       local_result += x[i] * y[i];
00114     }
00115
00116   if (np_dh > 1)
00117     {
00118       MPI_Allreduce (&local_result, &result, 1, MPI_DOUBLE, MPI_SUM, comm_dh);
00119     }
00120   else
00121     {
00122       result = local_result;
00123     }
00124
00125 END_FUNC_VAL (result)}
00126
00127 #undef __FUNC__
00128 #define __FUNC__ "Norm2"
00129 double
00130 Norm2 (int n, double *x)
00131 {
00132   START_FUNC_DH double result, local_result = 0.0;
00133   int i;
00134
00135   for (i = 0; i < n; ++i)
00136     {
00137       local_result += (x[i] * x[i]);
00138     }
00139
00140   if (np_dh > 1)
00141     {
00142       MPI_Allreduce (&local_result, &result, 1, MPI_DOUBLE, MPI_SUM, comm_dh);
00143     }
00144   else
00145     {
00146       result = local_result;
00147     }
00148   result = sqrt (result);
00149 END_FUNC_VAL (result)}

Generated on Wed May 12 21:30:17 2010 for IFPACK by  1.4.7