Skip to content

Commit

Permalink
Rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
seharshah committed Jul 23, 2019
1 parent de6a5a1 commit 6656d45
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
15 changes: 5 additions & 10 deletions src/S.txt
@@ -1,10 +1,5 @@
-2.0744e-09 -1.4771e-09 -1.6283e-09 -1.4702e-09 -1.5409e-09 -1.2351e-09 -1.2841e-09 -1.7886e-09 -1.4983e-09 -1.5203e-09
6.5676e-11 -1.8419e-09 -6.538e-10 -1.0473e-09 -4.5144e-10 -5.6441e-10 -7.4527e-10 -6.3213e-10 -7.3984e-10 -8.6216e-10
2.0352e-10 3.0106e-10 -1.2172e-09 -5.6884e-10 -9.3086e-11 -6.9548e-10 -4.2201e-10 -3.1559e-10 4.0804e-11 -9.8588e-11
-2.1511e-10 6.7193e-11 -1.2348e-10 1.6039e-09 6.763e-10 7.4096e-10 1.4327e-10 -1.2269e-10 4.7248e-10 5.1893e-10
-3.3031e-11 -1.4398e-10 6.0496e-11 1.6459e-10 1.6609e-09 7.0444e-10 4.2782e-10 -3.3496e-10 9.8674e-11 1.0869e-10
6.7337e-11 1.2568e-10 1.4395e-10 -1.7813e-10 -2.2096e-10 -1.4643e-09 -1.7036e-10 3.2127e-10 -2.8903e-10 -2.3015e-10
1.0454e-10 -7.844e-11 1.3878e-11 -4.4572e-12 7.2791e-11 -4.0635e-11 1.3188e-09 1.6542e-10 3.0899e-10 3.5544e-10
-3.2989e-10 -2.3889e-10 -1.6728e-10 -1.2695e-10 -1.8873e-11 3.9935e-11 -1.8182e-10 -1.6119e-09 -1.4045e-10 -2.9886e-10
-4.241e-10 -2.3563e-10 -5.0035e-10 -3.901e-10 -3.2605e-10 -4.6985e-10 -3.408e-10 -3.6317e-10 9.8576e-10 -8.1507e-10
2.5997e-10 8.2902e-11 5.1509e-11 -1.4167e-10 -4.8262e-12 2.4282e-11 -1.1685e-11 4.0036e-10 6.9682e-11 -9.1017e-10
7.0582e-07 -1.7965e-07 2.0789e-07 2.0937e-08 2.348e-08 2.8434e-07
2.5598e-07 9.5657e-08 7.9435e-08 3.9232e-09 6.6423e-08 -1.0946e-07
-1.4375e-08 5.0701e-08 2.084e-07 1.0267e-07 6.2087e-08 -1.0946e-07
1.5282e-07 -3.9283e-08 -3.1781e-07 -8.0349e-07 1.6174e-09 -9.9902e-08
-2.3985e-07 1.1494e-07 -5.1098e-08 -6.4127e-08 1.2269e-07 -1.0022e-07
45 changes: 35 additions & 10 deletions src/bgmres.c
Expand Up @@ -39,6 +39,7 @@ void matrixsub(double xx[], double yy[], double result[], int num);
void scalvec(int n, double sa, double *sx, double *sy, int incx);
void GRot(double dx, double dy, double cs, double sn);
void matrixadd(double xx[], double yy[], double result[], int num);
void writeMatrixtoFile(int row, int column, double *m);

int main (int argc, char * argv[])
{
Expand Down Expand Up @@ -114,17 +115,21 @@ filename = argv[1]; //Passing on the file
********************************/
iter = 0;
rows = A.rows;

/*
printf("\n\n Enter the required no of RHS\n");
scanf("%d", &rhs);
printf("\n\nEntered RHS: %d\n",rhs );
*/

//rhs = 10; //Change it to get rhs from user
//restart = 10; //Change it later to get it from user
rhs = 6; //Change it to get rhs from user
restart = 5; //Change it later to get it from user

/*
printf("\n\n Enter the restart value\n");
scanf("%d", &restart);
printf("\n\nEntered RHS: %d\n",restart );

*/

eps = 0.1;
tol = 1e-6;
Expand Down Expand Up @@ -162,7 +167,7 @@ scal = calloc(rhs*rhs, sizeof(double)); //R factor of QR factorization of R

for(i =0; i<rows;i++){
for (j = 0; j<rhs; j++){
B[i*rhs+j]= randf(0,1);
B[i*rhs+j]= randf(-1,1);
}
}

Expand Down Expand Up @@ -312,16 +317,19 @@ for (int initer = p;initer<m;initer++){

while(!feof(fp)){
for(i=0;i<restart;i++){
for(j=0;j<p;j++){
fscanf(fp,"%lf",&S[i*restart+j]);
for(j=0;j<rhs;j++){
fscanf(fp,"%lf",&S[i*rhs+j]);
}
}
} //End of while loop for reading matrix

cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans, rows, p, p, 1.0, V, rows, S, p, 0.0, C, p); //V(:,1:k_in)*S = C
cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans, rows, rhs, restart, 1.0, V, rows, S, rhs, 0.0, C, rhs); //V(:,1:k_in)*S = C
//X = X0+(V*S = C), num = rows*cols
// matrixadd(double xx[], double yy[], double result[], int num);
matrixadd(X, C, X,rows*rhs);

matrixadd(X, C, X,rows*rhs);
printf("\n\n X we obtained\n");
print_matrix(X, rows, rhs);

//Assigning transpose of X to tmp so that its columns gets called for multiplication
get_trans(X, tmp1, rows, rhs);
Expand Down Expand Up @@ -357,10 +365,10 @@ printf("\n\nThe Hessenberg Matrix is\n\n");
print_matrix(H,m, restart);

printf("\n\nThe matrix S is\n");
print_matrix(S, p, p);
print_matrix(S, restart, rhs);

printf("\n\nV and S gives\n");
print_matrix(C, rows, p);
print_matrix(C, rows, rhs);

printf("\n\n X we obtained\n");
print_matrix(X, rows, p);
Expand Down Expand Up @@ -602,3 +610,20 @@ void GRot(double dx, double dy, double cs, double sn)
sn = temp * cs;
}
}

void writeMatrixtoFile(int row, int column, double *m)
{
FILE *matrix=fopen("matrix.txt", "w");
int a=0, b=0;

for(a=0;a<row;a++)
{
for(b=0;b<column;b++)
{
fprintf(matrix, "%lf\t", m[a*column+b]);
}
fprintf(matrix, "\n");
}

fclose(matrix);
}
2 changes: 1 addition & 1 deletion src/dbgmres.c
Expand Up @@ -3,7 +3,7 @@ Testing Block GMRES Method with Deflation
Author: Sehar Naveed
sehar.naveed@stud-inf.unibz.it
January 2019
July 2019
Supervisor: Dr. Bruno Carpentieri
Dr. Flavio Vella
Expand Down

0 comments on commit 6656d45

Please sign in to comment.