Skip to content

Commit cae3713

Browse files
committed
Change solver result to bool
1 parent 04c8e6d commit cae3713

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

scripts/build-yuri.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mkdir build 2>/dev/null || true
88
cd build
99

1010
module purge
11-
SPACK_VIEW=/usr/local/spack/var/spack/environments/fortrilinos/.spack-env/view
11+
SPACK_VIEW=$SPACK_ROOT/var/spack/environments/fortrilinos/.spack-env/view
1212
export CMAKE_PREFIX_PATH=$SPACK_VIEW:$CMAKE_PREFIX_PATH
1313
export PATH=$SPACK_VIEW/bin:$PATH
1414

src/fortrilinos_hl/eigen_handle.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ TrilinosEigenSolver::TrilinosEigenSolver(const Teuchos::RCP<const Teuchos::Comm<
151151
TEUCHOS_TEST_FOR_EXCEPTION(2 * eigenValues.size() < numConverged, std::runtime_error,
152152
"Insufficient space to store eigenvalues. Please provide at least two times the desired number of eigenvalues.");
153153
TEUCHOS_TEST_FOR_EXCEPTION(eigenIndex.size() < numConverged, std::runtime_error,
154-
"Insufficient space to store index. Please provide at least two times the desired number of eigenvalues.");
154+
"Insufficient space to store index. Please provide at least the desired number of eigenvalues.");
155155

156156
for (size_t i = 0; i < eValues.size(); i++) {
157157
eigenValues[2*i+0] = eValues[i].realpart;

src/fortrilinos_hl/generated/fortrilinos_hl.F90

+12-12
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function swigc_TrilinosSolver_solve(farg1, farg2, farg3) &
188188
type(SwigClassWrapper), intent(in) :: farg1
189189
type(SwigClassWrapper), intent(in) :: farg2
190190
type(SwigClassWrapper), intent(in) :: farg3
191-
real(C_DOUBLE) :: fresult
191+
integer(C_INT) :: fresult
192192
end function
193193

194194
subroutine swigc_delete_TrilinosSolver(farg1) &
@@ -602,13 +602,21 @@ subroutine swigf_TrilinosSolver_setup_solver(self, paramlist)
602602
call swigc_TrilinosSolver_setup_solver(farg1, farg2)
603603
end subroutine
604604

605+
606+
subroutine SWIGTM_fout_bool(imout, fout)
607+
use, intrinsic :: ISO_C_BINDING
608+
integer(kind=C_INT), intent(in) :: imout
609+
logical, intent(out) :: fout
610+
fout = (imout /= 0)
611+
end subroutine
612+
605613
subroutine swigf_TrilinosSolver_solve(self, rhs, lhs, swig_result)
606614
use, intrinsic :: ISO_C_BINDING
607615
class(TrilinosSolver), intent(in) :: self
608616
class(TpetraMultiVector), intent(in) :: rhs
609617
class(TpetraMultiVector), intent(in) :: lhs
610-
real(C_DOUBLE), intent(out), optional :: swig_result
611-
real(C_DOUBLE) :: fresult
618+
logical, intent(out), optional :: swig_result
619+
integer(C_INT) :: fresult
612620
type(SwigClassWrapper) :: farg1
613621
type(SwigClassWrapper) :: farg2
614622
type(SwigClassWrapper) :: farg3
@@ -618,7 +626,7 @@ subroutine swigf_TrilinosSolver_solve(self, rhs, lhs, swig_result)
618626
farg3 = lhs%swigdata
619627
fresult = swigc_TrilinosSolver_solve(farg1, farg2, farg3)
620628
if (present(swig_result)) then
621-
swig_result = fresult
629+
call SWIGTM_fout_bool(fresult, swig_result)
622630
endif
623631

624632
end subroutine
@@ -800,14 +808,6 @@ function swigf_TrilinosEigenSolver_solve(self, eigenvalues, eigenvectors, eigeni
800808
swig_result = int(fresult)
801809
end function
802810

803-
804-
subroutine SWIGTM_fout_bool(imout, fout)
805-
use, intrinsic :: ISO_C_BINDING
806-
integer(kind=C_INT), intent(in) :: imout
807-
logical, intent(out) :: fout
808-
fout = (imout /= 0)
809-
end subroutine
810-
811811
function swigf_TrilinosEigenSolver_converged(self) &
812812
result(swig_result)
813813
use, intrinsic :: ISO_C_BINDING

src/fortrilinos_hl/generated/fortrilinos_hlFORTRAN_wrap.cxx

+5-5
Original file line numberDiff line numberDiff line change
@@ -851,14 +851,14 @@ SWIGEXPORT void _wrap_TrilinosSolver_setup_solver(SwigClassWrapper *farg1, SwigC
851851
}
852852

853853

854-
SWIGEXPORT double _wrap_TrilinosSolver_solve(SwigClassWrapper *farg1, SwigClassWrapper const *farg2, SwigClassWrapper const *farg3) {
855-
double fresult ;
854+
SWIGEXPORT int _wrap_TrilinosSolver_solve(SwigClassWrapper *farg1, SwigClassWrapper const *farg2, SwigClassWrapper const *farg3) {
855+
int fresult ;
856856
ForTrilinos::TrilinosSolver *arg1 = (ForTrilinos::TrilinosSolver *) 0 ;
857857
Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector const > *arg2 = 0 ;
858858
Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector > *arg3 = 0 ;
859859
Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector const > tempnull2 ;
860860
Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector > tempnull3 ;
861-
double result;
861+
bool result;
862862

863863
SWIG_check_nonnull(farg1->cptr, "ForTrilinos::TrilinosSolver const *", "TrilinosSolver", "ForTrilinos::TrilinosSolver::solve(Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector const > const &,Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector > &) const", return 0);
864864
arg1 = (ForTrilinos::TrilinosSolver *)farg1->cptr;
@@ -870,7 +870,7 @@ SWIGEXPORT double _wrap_TrilinosSolver_solve(SwigClassWrapper *farg1, SwigClassW
870870
try
871871
{
872872
// Attempt the wrapped function call
873-
result = (double)((ForTrilinos::TrilinosSolver const *)arg1)->solve((Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector const > const &)*arg2,*arg3);
873+
result = (bool)((ForTrilinos::TrilinosSolver const *)arg1)->solve((Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector const > const &)*arg2,*arg3);
874874
}
875875
catch (const std::range_error& e)
876876
{
@@ -887,7 +887,7 @@ SWIGEXPORT double _wrap_TrilinosSolver_solve(SwigClassWrapper *farg1, SwigClassW
887887
SWIG_exception_impl("ForTrilinos::TrilinosSolver::solve(Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector const > const &,Teuchos::RCP< ForTrilinos::TrilinosSolver::MultiVector > &) const", -1, "An unknown exception occurred", return 0);
888888
}
889889
}
890-
fresult = (double)(result);
890+
fresult = (result ? 1 : 0);
891891
return fresult;
892892
}
893893

src/fortrilinos_hl/solver_handle.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ TrilinosSolver::TrilinosSolver(const Teuchos::RCP<const Teuchos::Comm<int>>& com
8181
status_ = SOLVER_SETUP;
8282
}
8383

84-
double TrilinosSolver::solve(const Teuchos::RCP<const MultiVector>& B, Teuchos::RCP<MultiVector>& X) const {
84+
bool TrilinosSolver::solve(const Teuchos::RCP<const MultiVector>& B, Teuchos::RCP<MultiVector>& X) const {
8585
TEUCHOS_ASSERT(status_ == SOLVER_SETUP);
8686

8787
TEUCHOS_ASSERT(X->getMap()->isSameAs(*A_->getDomainMap()));
@@ -93,6 +93,6 @@ TrilinosSolver::TrilinosSolver(const Teuchos::RCP<const Teuchos::Comm<int>>& com
9393
auto thyraB = Thyra::createConstMultiVector(B);
9494

9595
auto status = Thyra::solve<SC>(*thyraInverseA_, Thyra::NOTRANS, *thyraB, thyraX.ptr());
96-
return status.achievedTol;
96+
return status.solveStatus == Thyra::SOLVE_STATUS_CONVERGED;
9797
}
9898
}

src/fortrilinos_hl/solver_handle.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ namespace ForTrilinos {
5555
// Setup solver based on the parameter list
5656
void setup_solver(const Teuchos::RCP<Teuchos::ParameterList>& paramList);
5757

58-
// Solve linear system given rhs; return solved tolerance
59-
double solve(const Teuchos::RCP<const MultiVector>& rhs, Teuchos::RCP<MultiVector>& lhs) const;
58+
// Solve linear system given rhs; return whether it converged
59+
bool solve(const Teuchos::RCP<const MultiVector>& rhs, Teuchos::RCP<MultiVector>& lhs) const;
6060

6161
private:
6262
Teuchos::RCP<const Teuchos::Comm<int>> comm_;

test/fortrilinos_hl/test_solver_handle.F90

+5-5
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ program main
189189
real(norm_type), dimension(:), allocatable :: norms
190190
integer(global_ordinal_type), dimension(:), allocatable :: cols
191191
real(scalar_type), dimension(:), allocatable :: vals
192-
real(scalar_type) :: r0, sone = 1., szero = 0., tol, achieved_tol
192+
real(scalar_type) :: r0, sone = 1., szero = 0., tol
193+
logical :: success
193194

194195
n = 10
195196

@@ -386,10 +387,9 @@ program main
386387
call residual%update(sone, B, -sone); FORTRILINOS_CHECK_IERR()
387388
call residual%norm2(norms); FORTRILINOS_CHECK_IERR()
388389
r0 = norms(1)
389-
call solver_handle%solve(B, X, achieved_tol); FORTRILINOS_CHECK_IERR()
390-
if (achieved_tol> tol) then
391-
write(error_unit, *) 'Achieved tolerance', achieved_tol, &
392-
'exceeds requested tolerance', tol
390+
call solver_handle%solve(B, X, success); FORTRILINOS_CHECK_IERR()
391+
if (.not. success) then
392+
write(error_unit, *) 'Solver failed to converge'
393393
stop 1
394394
end if
395395

0 commit comments

Comments
 (0)