Skip to content

Commit

Permalink
Fix array size and move initialization outside of outer loop
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Hahn <[email protected]>
  • Loading branch information
quantumsteve committed Nov 28, 2023
1 parent ac5515f commit f904230
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 5 additions & 8 deletions src/asgard_resources_cuda.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,13 @@ getCudaMemcpyKind(resource destination, resource source)
{
if (source == resource::host)
return cudaMemcpyHostToHost;
else if (source == resource::device)
else
return cudaMemcpyDeviceToHost;
}
else if (destination == resource::device)
{
if (source == resource::host)
return cudaMemcpyHostToDevice;
else if (source == resource::device)
return cudaMemcpyDeviceToDevice;
}
if (source == resource::host)
return cudaMemcpyHostToDevice;
else
return cudaMemcpyDeviceToDevice;
}

template<resource out, resource in, typename P>
Expand Down
13 changes: 7 additions & 6 deletions src/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ simple_gmres(matrix_abstraction mat, fk::vector<P, mem_type::view, resrc> x,
fk::vector<P> krylov_proj(restart * (restart + 1) / 2);
fk::vector<P> sines(restart + 1);
fk::vector<P> cosines(restart + 1);
fk::vector<P> krylov_sol(restart + 1);

int total_iterations{0};
int outer_iterations{0};
int inner_iterations{0};
int total_iterations = 0;
int outer_iterations = 0;
int inner_iterations = 0;

P inner_res{0.};
P outer_res{tolerance + P{1.}};
P inner_res = 0.;
P outer_res = tolerance + 1.;
while ((outer_res > tolerance) && (outer_iterations < max_outer_iterations))
{
fk::vector<P, mem_type::view, resrc> scaled(basis, 0, 0, basis.nrows() - 1);
Expand All @@ -162,7 +163,6 @@ simple_gmres(matrix_abstraction mat, fk::vector<P, mem_type::view, resrc> x,
precondition(scaled);
++total_iterations;

fk::vector<P> krylov_sol(n + 1);
inner_res = fm::nrm2(scaled);
scaled.scale(P{1.} / inner_res);
krylov_sol[0] = inner_res;
Expand Down Expand Up @@ -216,6 +216,7 @@ simple_gmres(matrix_abstraction mat, fk::vector<P, mem_type::view, resrc> x,

if ((inner_res > tolerance) && (inner_iterations < restart))
{
krylov_sol[inner_iterations + 1] = 0.;
lib_dispatch::rot(1, krylov_sol.data(inner_iterations), 1,
krylov_sol.data(inner_iterations + 1), 1,
cosines[inner_iterations], sines[inner_iterations]);
Expand Down

0 comments on commit f904230

Please sign in to comment.