#include #include //-- setup and print matrices -------------------------------------------------- void initGeMatrix(int m, int n, double *A, int incRowA, int incColA) { int i, j; for (i=0; iresult) { result = fabs(x[i*incX]); } } return result; } double dgenrm1(int m, int n, const double *A, int incRowA, int incColA) { int i, j; double result = 0; for (j=0; jresult) { result = sum; } } return result; } //-- GEMV implementations ------------------------------------------------------ void dgemv_col(int m, int n, double alpha, const double *A, int incRowA, int incColA, const double *x, int incX, double beta, double *y, int incY) { // your code here } void dgemv_row(int m, int n, double alpha, const double *A, int incRowA, int incColA, const double *x, int incX, double beta, double *y, int incY) { // your code here } //------------------------------------------------------------------------------ #ifndef DIM_M #define DIM_M 5 #endif #ifndef DIM_N #define DIM_N 6 #endif #ifndef ROWMAJOR #define ROWMAJOR 0 #endif #if (ROWMAJOR==1) # define INCROW_A DIM_N # define INCCOL_A 1 #else # define INCROW_A 1 # define INCCOL_A DIM_M #endif #ifndef INC_X #define INC_X 1 #endif #ifndef INC_Y #define INC_Y 1 #endif #ifndef ALPHA #define ALPHA 2 #endif #ifndef BETA #define BETA 3 #endif // // A, x, y_ will get initialized with initGeMatrix // double A[DIM_M*DIM_N]; double x[INC_X*DIM_N]; double y_[DIM_M]; // // If BETA is not zero the result of BETA*y + ALPHA * A *x depends on the // initial value of y. We initialize y with y_ before each call of a gemv // implementation. So the results are always the same. // double y[INC_Y*DIM_M]; int main() { initGeMatrix(DIM_M, DIM_N, A, INCROW_A, INCCOL_A); initGeMatrix(DIM_N, 1, x, INC_X, 0); initGeMatrix(DIM_M, 1, y_, 1, 0); printf("A =\n"); printGeMatrix(DIM_M, DIM_N, A, INCROW_A, INCCOL_A); printf("x =\n"); printGeMatrix(DIM_N, 1, x, INC_X, 0); printf("y =\n"); printGeMatrix(DIM_M, 1, y_, INC_Y, 0); // // Aufruf von gemv_col // printf("gemv_col: %10.4lf * y + %10.4lf * A * x =\n\n", (double)BETA, (double)ALPHA); dcopy(DIM_M, y_, 1, y, INC_Y); dgemv_col(DIM_M, DIM_N, ALPHA, A, INCROW_A, INCCOL_A, x, INC_X, BETA, y, INC_Y); printGeMatrix(DIM_M, 1, y, INC_Y, 0); // // Aufruf von gemv_row // printf("gemv_row: %10.4lf * y + %10.4lf * A * x =\n\n", (double)BETA, (double)ALPHA); dcopy(DIM_M, y_, 1, y, INC_Y); dgemv_row(DIM_M, DIM_N, ALPHA, A, INCROW_A, INCCOL_A, x, INC_X, BETA, y, INC_Y); printGeMatrix(DIM_M, 1, y, INC_Y, 0); return 0; }