Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New ForTrilinos.h and forerror module, prefixed ierr and serr #169

Merged
merged 4 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/autogen_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def write(self, stream):
SETUP_TEST()

#ifdef HAVE_MPI
call comm%create(MPI_COMM_WORLD); CHECK_IERR()
call comm%create(MPI_COMM_WORLD); FORTRILINOS_CHECK_IERR()
#else
call comm%create()
#endif
Expand Down
3 changes: 1 addition & 2 deletions src/simple/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
Tpetra
ForTrilinosTeuchos
ForTrilinosTpetra
ForTrilinosUtils
LIB_OPTIONAL_PACKAGES
Anasazi
Ifpack2
MueLu
TEST_REQUIRED_PACKAGES # Needed to pass, not to build
ForTrilinosUtils
TEST_OPTIONAL_PACKAGES
Anasazi
Belos
Expand Down
1 change: 1 addition & 0 deletions src/simple/src/fortrilinos.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

module fortrilinos
use, intrinsic :: ISO_C_BINDING
use forerror
use forteuchos
use fortpetra

Expand Down
1 change: 1 addition & 0 deletions src/simple/src/fortrilinos.i
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

%include "copyright.i"

%import <forerror.i>
%import <forteuchos.i>
%import <fortpetra.i>

Expand Down
3 changes: 0 additions & 3 deletions src/simple/test/test_simple_eigen_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

#include "eigen_handle.hpp"

// FIXME: this is a workaround for ierr linkage errors
int ierr = 0;

int main(int argc, char *argv[]) {
bool success = false;
bool verbose = true;
Expand Down
51 changes: 28 additions & 23 deletions src/simple/test/test_simple_eigen_handle.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
program main

#include "ForTrilinosSimpleInterface_config.hpp"
#include "FortranTestUtilities.h"
#include "ForTrilinos.h"

use ISO_FORTRAN_ENV
use, intrinsic :: ISO_C_BINDING

#ifdef HAVE_MPI
use mpi
#endif

#include "ForTrilinos.h"
use fortrilinos
use forteuchos
use fortpetra
use fortest
#ifdef HAVE_MPI
use mpi
#endif

implicit none

integer(int_type) :: my_rank, num_procs
Expand All @@ -25,6 +29,7 @@ program main
integer(int_type) :: num_eigen_int
integer(int_type) :: row_nnz

integer :: ierr
integer(local_ordinal_type) :: i
integer(global_ordinal_type) :: offset
real(scalar_type) :: one = 1.0
Expand Down Expand Up @@ -61,16 +66,16 @@ program main
write(*,*) "Processor ", my_rank, " of ", num_procs

! Read in the parameterList
call plist%create("Anasazi"); CHECK_IERR()
call load_from_xml(plist, "davidson.xml"); CHECK_IERR()
call plist%create("Anasazi"); FORTRILINOS_CHECK_IERR()
call load_from_xml(plist, "davidson.xml"); FORTRILINOS_CHECK_IERR()

num_eigen_int = num_eigen
call plist%set("NumEV", num_eigen_int); CHECK_IERR()
call plist%set("NumEV", num_eigen_int); FORTRILINOS_CHECK_IERR()

! ------------------------------------------------------------------
! Step 0: Construct tri-diagonal matrix
n_global = -1
call map%create(n_global, n, comm); CHECK_IERR()
call map%create(n_global, n, comm); FORTRILINOS_CHECK_IERR()

max_entries_per_row = 3
call A%create(map, max_entries_per_row, TpetraDynamicProfile)
Expand All @@ -94,31 +99,31 @@ program main
row_nnz = row_nnz + 1
end if

call A%insertGlobalValues(offset + i, cols(1:row_nnz-1), vals(1:row_nnz-1)); CHECK_IERR()
call A%insertGlobalValues(offset + i, cols(1:row_nnz-1), vals(1:row_nnz-1)); FORTRILINOS_CHECK_IERR()
end do
call A%fillComplete(); CHECK_IERR()
call A%fillComplete(); FORTRILINOS_CHECK_IERR()

! The solution
allocate(evalues(num_eigen))
call X%create(map, num_eigen)

! Step 0: crate a handle
call eigen_handle%create(); CHECK_IERR()
call eigen_handle%create(); FORTRILINOS_CHECK_IERR()

! ------------------------------------------------------------------
! Explicit setup and solve
! ------------------------------------------------------------------
! Step 1: initialize a handle
call eigen_handle%init(comm); CHECK_IERR()
call eigen_handle%init(comm); FORTRILINOS_CHECK_IERR()

! Step 2: setup the problem
call eigen_handle%setup_matrix(A); CHECK_IERR()
call eigen_handle%setup_matrix(A); FORTRILINOS_CHECK_IERR()

! Step 3: setup the solver
call eigen_handle%setup_solver(plist); CHECK_IERR()
call eigen_handle%setup_solver(plist); FORTRILINOS_CHECK_IERR()

! Step 4: solve the system
call eigen_handle%solve(evalues, X); CHECK_IERR()
call eigen_handle%solve(evalues, X); FORTRILINOS_CHECK_IERR()

! FIXME: Check the solution
if (size(evalues) /= num_eigen) then
Expand All @@ -128,14 +133,14 @@ program main
write(*,*) "Computed eigenvalues: ", evalues(1)

! Step 5: clean up
call eigen_handle%finalize(); CHECK_IERR()

call eigen_handle%release(); CHECK_IERR()
call plist%release(); CHECK_IERR()
call X%release(); CHECK_IERR()
call A%release(); CHECK_IERR()
call map%release(); CHECK_IERR()
call comm%release(); CHECK_IERR()
call eigen_handle%finalize(); FORTRILINOS_CHECK_IERR()

call eigen_handle%release(); FORTRILINOS_CHECK_IERR()
call plist%release(); FORTRILINOS_CHECK_IERR()
call X%release(); FORTRILINOS_CHECK_IERR()
call A%release(); FORTRILINOS_CHECK_IERR()
call map%release(); FORTRILINOS_CHECK_IERR()
call comm%release(); FORTRILINOS_CHECK_IERR()
deallocate(evalues)
deallocate(cols)
deallocate(vals)
Expand Down
3 changes: 0 additions & 3 deletions src/simple/test/test_simple_eigen_handle_preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

#include "eigen_handle.hpp"

// FIXME: this is a workaround for ierr linkage errors
int ierr = 0;

int main(int argc, char *argv[]) {
bool success = false;
bool verbose = true;
Expand Down
3 changes: 0 additions & 3 deletions src/simple/test/test_simple_solver_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

#include "solver_handle.hpp"

// FIXME: this is a workaround for ierr linkage errors
int ierr = 0;

int main(int argc, char *argv[]) {
bool success = false;
bool verbose = true;
Expand Down
60 changes: 32 additions & 28 deletions src/simple/test/test_simple_solver_handle.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
program main

#include "ForTrilinosSimpleInterface_config.hpp"
#include "FortranTestUtilities.h"
#include "ForTrilinos.h"

use ISO_FORTRAN_ENV
use, intrinsic :: ISO_C_BINDING

#ifdef HAVE_MPI
use mpi
#endif

#include "ForTrilinos.h"
use fortrilinos
use forteuchos
use fortpetra
use fortest
#ifdef HAVE_MPI
use mpi
#endif
implicit none

integer(int_type) :: my_rank, num_procs
Expand All @@ -24,6 +27,7 @@ program main
integer(size_type) :: n, max_entries_per_row, num_vecs = 1, lda
integer(int_type) :: row_nnz

integer :: ierr
integer(local_ordinal_type) :: i
integer(global_ordinal_type) :: offset
real(scalar_type) :: one = 1.0
Expand Down Expand Up @@ -62,13 +66,13 @@ program main
write(*,*) "Processor ", my_rank, " of ", num_procs

! Read in the parameterList
call plist%create("Stratimikos"); CHECK_IERR()
call load_from_xml(plist, "stratimikos.xml"); CHECK_IERR()
call plist%create("Stratimikos"); FORTRILINOS_CHECK_IERR()
call load_from_xml(plist, "stratimikos.xml"); FORTRILINOS_CHECK_IERR()

! ------------------------------------------------------------------
! Step 0: Construct tri-diagonal matrix
n_global = -1
call map%create(n_global, n, comm); CHECK_IERR()
call map%create(n_global, n, comm); FORTRILINOS_CHECK_IERR()

max_entries_per_row = 3
call A%create(map, max_entries_per_row, TpetraDynamicProfile)
Expand All @@ -92,12 +96,12 @@ program main
row_nnz = row_nnz + 1
end if

call A%insertGlobalValues(offset + i, cols(1:row_nnz-1), vals(1:row_nnz-1)); CHECK_IERR()
call A%insertGlobalValues(offset + i, cols(1:row_nnz-1), vals(1:row_nnz-1)); FORTRILINOS_CHECK_IERR()
end do
call A%fillComplete(); CHECK_IERR()
call A%fillComplete(); FORTRILINOS_CHECK_IERR()

! This automatically zeroes out X
call X%create(map, num_vecs); CHECK_IERR()
call X%create(map, num_vecs); FORTRILINOS_CHECK_IERR()

! The solution X(i) = i-1
allocate(lhs(n))
Expand All @@ -120,28 +124,28 @@ program main
end do
lda = n

call Xtrue%create(map, lhs, lda, num_vecs); CHECK_IERR()
call B%create(map, rhs, lda, num_vecs); CHECK_IERR()
call Xtrue%create(map, lhs, lda, num_vecs); FORTRILINOS_CHECK_IERR()
call B%create(map, rhs, lda, num_vecs); FORTRILINOS_CHECK_IERR()

! Step 0: create a handle
call solver_handle%create(); CHECK_IERR()
call solver_handle%create(); FORTRILINOS_CHECK_IERR()

! Step 1: initialize a handle
call solver_handle%init(comm); CHECK_IERR()
call solver_handle%init(comm); FORTRILINOS_CHECK_IERR()

! Step 2: setup the problem
call solver_handle%setup_matrix(A); CHECK_IERR()
call solver_handle%setup_matrix(A); FORTRILINOS_CHECK_IERR()

! Step 3: setup the solver
call solver_handle%setup_solver(plist); CHECK_IERR()
call solver_handle%setup_solver(plist); FORTRILINOS_CHECK_IERR()

! Step 4: solve the system
call solver_handle%solve(B, X); CHECK_IERR()
call solver_handle%solve(B, X); FORTRILINOS_CHECK_IERR()

! Check the solution
allocate(norms(1))
call X%update(-one, Xtrue, one); CHECK_IERR()
call X%norm2(norms); CHECK_IERR()
call X%update(-one, Xtrue, one); FORTRILINOS_CHECK_IERR()
call X%norm2(norms); FORTRILINOS_CHECK_IERR()

! TODO: Get the tolerance out of the parameter list
if (norms(1) > 1e-6) then
Expand All @@ -150,15 +154,15 @@ program main
end if

! Step 5: clean up
call solver_handle%finalize(); CHECK_IERR()

call solver_handle%release(); CHECK_IERR()
call plist%release(); CHECK_IERR()
call X%release(); CHECK_IERR()
call B%release(); CHECK_IERR()
call A%release(); CHECK_IERR()
call map%release(); CHECK_IERR()
call comm%release(); CHECK_IERR()
call solver_handle%finalize(); FORTRILINOS_CHECK_IERR()

call solver_handle%release(); FORTRILINOS_CHECK_IERR()
call plist%release(); FORTRILINOS_CHECK_IERR()
call X%release(); FORTRILINOS_CHECK_IERR()
call B%release(); FORTRILINOS_CHECK_IERR()
call A%release(); FORTRILINOS_CHECK_IERR()
call map%release(); FORTRILINOS_CHECK_IERR()
call comm%release(); FORTRILINOS_CHECK_IERR()
deallocate(norms)
deallocate(cols)
deallocate(vals)
Expand Down
1 change: 0 additions & 1 deletion src/teuchos/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
LIB_REQUIRED_PACKAGES
Teuchos
TEST_REQUIRED_PACKAGES
ForTrilinosUtils
)
1 change: 1 addition & 0 deletions src/teuchos/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ IF (ForTrilinos_ENABLE_DeveloperMode)
LIST(APPEND CMAKE_SWIG_FLAGS -I${CMAKE_CURRENT_SOURCE_DIR}/../../utils/src/)
MAKE_SWIG(MODULE forteuchos
SOURCE forteuchos.i
DEPLIBS ${Trilinos_LIBRARIES}
EXTRASRC ${EXTRA_SOURCE}
)

Expand Down
2 changes: 0 additions & 2 deletions src/teuchos/src/Teuchos_Exceptions.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* SPDX-License-Identifier: BSD-3-Clause
* License-Filename: LICENSE
*/
%include <std_except.i>

%{
#include "Teuchos_Exceptions.hpp"
%}
Expand Down
10 changes: 1 addition & 9 deletions src/teuchos/src/forteuchos.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

module forteuchos
use, intrinsic :: ISO_C_BINDING
use forerror
implicit none
private

Expand All @@ -25,10 +26,6 @@ module forteuchos
public :: TeuchosEType, TeuchosFULL, TeuchosLOWER, TeuchosUPPER, TeuchosHESSENBERG, TeuchosSYM_BAND_L, TeuchosSYM_BAND_U, &
TeuchosBAND
public :: TeuchosDataAccess, TeuchosCopy, TeuchosView

public :: ierr
public :: serr

public :: TeuchosComm
public :: string
public :: ParameterList
Expand Down Expand Up @@ -79,11 +76,6 @@ module forteuchos
enumerator :: TeuchosCopy = 0
enumerator :: TeuchosView = TeuchosCopy + 1
end enum
integer(C_INT), parameter, public :: SWIG_FORTRAN_ERROR_STRLEN = 1024_C_INT

integer(C_INT), bind(C) :: ierr = 0
character(kind=C_CHAR, len=1024), bind(C) :: serr = ""


! TYPES
type :: VectorInt
Expand Down
2 changes: 2 additions & 0 deletions src/teuchos/src/forteuchos.i
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

%include "copyright.i"

%import <forerror.i>

%include "ForTrilinosTeuchos_config.hpp"

%include <std_vector.i>
Expand Down
Loading