Page MenuHomec4science

cg_blas.c
No OneTemporary

File Metadata

Created
Sat, Sep 21, 18:04

cg_blas.c

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
#include "blas.h"
#include "cg.h"
#include "parameters.h"
/*
main function
reads the matrix entered as argument.
using mmio.h (from matrix market)
*/
int main ( int argc, char **argv ) {
double * A;
double * b;
double * x;
double * x0;
int m,n;
struct size_m sA,sb;
if (argc < 2)
{
fprintf(stderr, "Usage: %s [martix-market-filename]\n", argv[0]);
exit(1);
}
else
{
A = read_mat(argv[1]);
sA = get_size(argv[1]);
b = read_mat(argv[2]);
sb = get_size(argv[2]);
}
m = sA.m;
n = sA.n;
x = (double*) malloc(n * sizeof(double));
x0 = (double*) malloc(n * sizeof(double));
cgsolver( A, b, x, m, n );
printf("Solves A x = b\n");
print_mat( "\nSolution :", x,1,n );
cblas_dgemv (1, 0, m, n, 1., A, 1., x, 1., 0., x0, 1.);
print_mat( "\nCheck AX:\n", x0,1, n);
print_mat( "\nCheck b:\n", b,1, n);
free(A);
free(b);
free(x);
free(x0);
return 0;
}

Event Timeline