#include #include #include #include #include #include //tolerance for result of CG #define TOLERANCE 1e-6 //max iteration by CG #define MAX_ITRN 100 //max file name length #define MAX_FILE_LEN 80 #define MILLISECOND 1000000.0 struct Vector { int n; //number of elements float *p; //values }; typedef struct Vector Vec; struct Matrix { int n; //# of rows int m; //# of columns float *p; //values }; typedef struct Matrix Mat; //========== Vec/Mat allocation and free ==== Vec * createVec(int n); void destroyVec(Vec * vecP); Mat * createMat(int n, int m); void destroyMat(Mat * matP); //========== Vec/Mat io ===================== Vec * readVec(FILE * vecInFile); void writeVec(Vec * vecP, FILE * outFile); Mat * readMat(FILE * matInFile); void writeMat(Mat * matP, FILE * outFile); //========== CG functions =================== Vec * CG(const gsl_matrix_float * A, const gsl_vector_float * b, float tol, int maxItn);