00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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)}