fowfewpfeopwjpfwe

next
parent d01e2efec5
commit 4b6295d0df

6
.gitignore vendored

@ -1,2 +1,6 @@
build*/
.spack-env/
.spack-env/
*.log
*.out
*.lock?

@ -4,6 +4,7 @@
"Arnoldi",
"AXPY",
"DHSEQR",
"eigvals",
"Hessenberg",
"Krylov",
"LAPACK",

@ -126,11 +126,16 @@ int main(int argc, char **argv) {
// PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[Arnoldi] Starting iteration\n"));
// ARNOLDI TIME START
PetscLogDouble arnoldi_start_time;
PetscCall(PetscTime(&arnoldi_start_time));
PetscCall(ArnoldiIteration(A, b, l, n, Q, H));
{
PetscCall(ArnoldiIteration(A, b, l, n, Q, H));
}
PetscLogDouble arnoldi_end_time;
PetscCall(PetscTime(&arnoldi_end_time));
PetscLogDouble arnoldi_time = arnoldi_end_time - arnoldi_start_time;
if (rank == 0)
PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[Arnoldi] Arnoldi time: %f seconds\n", arnoldi_time));
// PetscCall(MatSetValue(H, 2, 3, -1, INSERT_VALUES));
// PetscCall(MatAssemblyBegin(H, MAT_FINAL_ASSEMBLY));
@ -149,15 +154,16 @@ int main(int argc, char **argv) {
double *work = (double *)malloc(3 * l * sizeof(double));
int info;
// call LAPACK function "DHSEQR" to compute the eigenvalues of the Hessenberg matrix
LAPACKE_dhseqr(LAPACK_ROW_MAJOR, 'E', 'I', l, 1, l, H, l, wr, wi, z, l);
PetscLogDouble arnoldi_end_time;
PetscCall(PetscTime(&arnoldi_end_time));
PetscLogDouble arnoldi_time = arnoldi_end_time - arnoldi_start_time;
if (rank == 0)
PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[Arnoldi] Arnoldi time: %f seconds\n", arnoldi_time));
// ARNOLDI TIME END
PetscLogDouble lapack_start_time;
PetscCall(PetscTime(&lapack_start_time));
{
// call LAPACK function "DHSEQR" to compute the eigenvalues of the Hessenberg matrix
LAPACKE_dhseqr(LAPACK_ROW_MAJOR, 'E', 'I', l, 1, l, H, l, wr, wi, z, l);
}
PetscLogDouble lapack_end_time;
PetscCall(PetscTime(&lapack_end_time));
PetscLogDouble lapack_time = lapack_end_time - lapack_start_time;
PetscCall(PetscPrintf(PETSC_COMM_WORLD, "[Arnoldi] LAPACK time: %f seconds\n", lapack_time));
// // print Hessenberg matrix
// printf("H = \n");

@ -2,16 +2,70 @@ using SparseArrays
using LinearAlgebra
using MAT
# 11 x 16
nx = 10
ny = 15
# 20 x 20 x 20 grid
nx = 20 - 1
ny = 20 - 1
nz = 20 - 1
ex = fill(1, nx)
ey = fill(1, ny)
Dxx = diagm(-1 => ex, 0 => -2 * ex, +1 => ex)
Dyy = diagm(-1 => ey, 0 => -2 * ey, +1 => ey)
L = kron(Dyy, diagm(0 => [ex; 1])) + kron(diagm(0 => [ey; 1]), Dxx);
ez = fill(1, nz)
Dxx = spdiagm(-1 => ex, 0 => -2 * ex, +1 => ex)
Dyy = spdiagm(-1 => ey, 0 => -2 * ey, +1 => ey)
Dzz = spdiagm(-1 => ez, 0 => -2 * ez, +1 => ez)
Ix = spdiagm(0 => [ex; 1])
Iy = spdiagm(0 => [ey; 1])
Iz = spdiagm(0 => [ez; 1])
# L = kron(Dxx, Iy, Iz) + kron(Ix, Dyy, Iz) + kron(Ix, Iy, Dzz)
# # 10 x 17 grid
# nx = 11 - 1
# ny = 16 - 1
# ex = fill(1, nx)
# ey = fill(1, ny)
# Dxx = spdiagm(-1 => ex, 0 => -2 * ex, +1 => ex)
# Dyy = spdiagm(-1 => ey, 0 => -2 * ey, +1 => ey)
# Ix = spdiagm(0 => [ex; 1])
# Iy = spdiagm(0 => [ey; 1])
# L = kron(Dxx, Iy) + kron(Ix, Dyy)
println("Laplacian matrix L:")
display(sparse(L))
display(eigvals(L))
l = 100
# arnoldi iteration
Q = Matrix{Float64}(undef, size(L, 1), l)
Q[:, 1] = ones(size(L, 1))
H = zeros(l, l)
for j in 2:l
# Arnoldi iteration
v = L * Q[:, j - 1]
# Reorthogonalization
for i in 1:(j - 1)
H[i, j - 1] = dot(Q[:, i], v)
v -= H[i, j - 1] * Q[:, i]
end
H[j, j - 1] = norm(v)
if H[j, j - 1] < 1e-10
break
end
Q[:, j] = v / H[j, j - 1]
end
H = H[1:(l-1), 1:(l-1)]
println("Hessenberg matrix H:")
display(H)
display(eigvals(H))

Loading…
Cancel
Save