Merge pull request #276 from mit-crpg/mem_clean

Cleanup build warnings and memory leaks
This commit is contained in:
Paul Romano 2014-05-15 23:04:56 -04:00
commit 74fb90a923
17 changed files with 549 additions and 152 deletions

View file

@ -1330,7 +1330,7 @@ contains
! Now we can fill the inelastic_data(i) attributes
do i = 1, NE_in
XSS_index = LOCC(i)
XSS_index = int(LOCC(i))
NE_out = table % inelastic_data(i) % n_e_out
do j = 1, NE_out
table % inelastic_data(i) % e_out(j) = XSS(XSS_index + 1)

View file

@ -800,7 +800,7 @@ contains
!===============================================================================
! FIX_NEUTRON_BALANCE is a method to adjust parameters to have perfect balance
!===============================================================================
#ifdef DEVELOPMENTAL
subroutine fix_neutron_balance()
use constants, only: ONE, ZERO, CMFD_NOACCEL
@ -926,6 +926,7 @@ contains
end do ZLOOP
end subroutine fix_neutron_balance
#endif
!===============================================================================
! COMPUTE_EFFECTIVE_DOWNSCATTER changes downscatter rate for zero upscatter

View file

@ -194,6 +194,7 @@ contains
if (allocated(this % dom)) deallocate(this % dom)
if (allocated(this % k_cmfd)) deallocate(this % k_cmfd)
if (allocated(this % entropy)) deallocate(this % entropy)
if (allocated(this % resnb)) deallocate(this % resnb)
end subroutine deallocate_cmfd

View file

@ -20,9 +20,6 @@ contains
use cmfd_header, only: allocate_cmfd
#ifdef PETSC
integer :: new_comm ! new mpi communicator
#endif
integer :: color ! color group of processor
! Read in cmfd input file
@ -37,12 +34,10 @@ contains
! Split up procs
#ifdef PETSC
call MPI_COMM_SPLIT(MPI_COMM_WORLD, color, 0, new_comm, mpi_err)
#endif
call MPI_COMM_SPLIT(MPI_COMM_WORLD, color, 0, cmfd_comm, mpi_err)
! assign to PETSc
#ifdef PETSC
PETSC_COMM_WORLD = new_comm
PETSC_COMM_WORLD = cmfd_comm
! Initialize PETSc on all procs
call PetscInitialize(PETSC_NULL_CHARACTER, mpi_err)

View file

@ -16,7 +16,9 @@ module cmfd_jfnk_solver
type(Matrix) :: jac_prec ! Jacobian preconditioner object
type(Matrix) :: loss ! CMFD loss matrix
type(Matrix) :: prod ! CMFD production matrix
#ifdef PETSC
type(JFNKSolver) :: jfnk ! JFNK solver object
#endif
type(Vector) :: resvec ! JFNK residual vector
type(Vector) :: xvec ! JFNK solution vector
@ -51,9 +53,9 @@ contains
#endif
! Set up residual and jacobian routines
#ifdef PETSC
jfnk_data % res_proc_ptr => compute_nonlinear_residual
jfnk_data % jac_proc_ptr => build_jacobian_matrix
#ifdef PETSC
call jfnk % set_functions(jfnk_data, resvec, jac_prec)
#endif
@ -104,8 +106,10 @@ contains
! Assemble matrices and use PETSc
call loss % assemble()
call prod % assemble()
#ifdef PETSC
call loss % setup_petsc()
call prod % setup_petsc()
#endif
! Check for mathematical adjoint
if (adjoint_calc .and. trim(cmfd_adjoint_type) == 'math') &
@ -133,14 +137,18 @@ contains
end if
! Set up vectors for PETSc
#ifdef PETSC
call resvec % setup_petsc()
call xvec % setup_petsc()
#endif
! Build jacobian from initial guess
call build_jacobian_matrix(xvec)
! Set up Jacobian for PETSc
#ifdef PETSC
call jac_prec % setup_petsc()
#endif
! Set dominance ratio to 0
cmfd % dom(current_batch) = ZERO
@ -262,7 +270,7 @@ contains
!===============================================================================
! COMPUTE_NONLINEAR_RESIDUAL computes the residual of the nonlinear equations
!===============================================================================
#ifdef PETSC
subroutine compute_nonlinear_residual(x, res)
use global, only: cmfd_write_matrices
@ -310,7 +318,9 @@ contains
else
filename = 'res.bin'
end if
#ifdef PETSC
call res % write_petsc_binary(filename)
#endif
! Write out solution vector
if (adjoint_calc) then
@ -318,11 +328,14 @@ contains
else
filename = 'x.bin'
end if
#ifdef PETSC
call x % write_petsc_binary(filename)
#endif
end if
end subroutine compute_nonlinear_residual
#endif
!===============================================================================
! COMPUTE_ADJOINT calculates mathematical adjoint by taking transposes
@ -333,13 +346,17 @@ contains
use global, only: cmfd_write_matrices
! Transpose matrices
#ifdef PETSC
call loss % transpose()
call prod % transpose()
#endif
! Write out matrix in binary file (debugging)
if (cmfd_write_matrices) then
#ifdef PETSC
call loss % write_petsc_binary('adj_lossmat.bin')
call loss % write_petsc_binary('adj_prodmat.bin')
#endif
end if
end subroutine compute_adjoint

View file

@ -29,7 +29,9 @@ module cmfd_power_solver
type(Vector) :: s_n ! new source vector
type(Vector) :: s_o ! old flux vector
type(Vector) :: serr_v ! error in source
#ifdef PETSC
type(GMRESSolver) :: gmres ! gmres solver
#endif
contains
@ -169,13 +171,17 @@ contains
use global, only: cmfd_write_matrices
! Transpose matrices
#ifdef PETSC
call loss % transpose()
call prod % transpose()
#endif
! Write out matrix in binary file (debugging)
if (cmfd_write_matrices) then
#ifdef PETSC
call loss % write_petsc_binary('adj_lossmat.bin')
call prod % write_petsc_binary('adj_prodmat.bin')
#endif
end if
end subroutine compute_adjoint
@ -320,7 +326,9 @@ contains
else
filename = 'fluxvec.bin'
end if
#ifdef PETSC
call phi_n % write_petsc_binary(filename)
#endif
end if
end subroutine extract_results

View file

@ -39,7 +39,7 @@ contains
subroutine run_eigenvalue()
type(Particle) :: p
integer :: i_work
integer(8) :: i_work
if (master) call header("K EIGENVALUE SIMULATION", level=1)
@ -256,7 +256,7 @@ contains
& temp_sites(:) ! local array of extra sites on each node
#ifdef MPI
integer :: n ! number of sites to send/recv
integer(8) :: n ! number of sites to send/recv
integer :: neighbor ! processor to send/recv data from
integer :: request(20) ! communication request for send/recving sites
integer :: n_request ! number of communication requests
@ -834,8 +834,8 @@ contains
subroutine join_bank_from_threads()
integer :: total ! total number of fission bank sites
integer :: i ! loop index for threads
integer(8) :: total ! total number of fission bank sites
integer :: i ! loop index for threads
! Initialize the total number of fission bank sites
total = 0

View file

@ -40,7 +40,10 @@ contains
#ifdef PETSC
! Finalize PETSc
if (cmfd_run) call PetscFinalize(mpi_err)
if (cmfd_run) then
call PetscFinalize(mpi_err)
call MPI_COMM_FREE(cmfd_comm, mpi_err)
end if
#endif
! Stop timers and show timing statistics

View file

@ -303,6 +303,9 @@ module global
! Is CMFD active
logical :: cmfd_run = .false.
! CMFD communicator
integer :: cmfd_comm
! Timing objects
type(Timer) :: time_cmfd ! timer for whole cmfd calculation
@ -481,8 +484,29 @@ contains
call sab_dict % clear()
call xs_listing_dict % clear()
! Clear statepoint batch set
! Clear statepoint and sourcepoint batch set
call statepoint_batch % clear()
call sourcepoint_batch % clear()
! Deallocate entropy mesh
if (associated(entropy_mesh)) then
if (allocated(entropy_mesh % lower_left)) &
deallocate(entropy_mesh % lower_left)
if (allocated(entropy_mesh % upper_right)) &
deallocate(entropy_mesh % upper_right)
if (allocated(entropy_mesh % width)) deallocate(entropy_mesh % width)
deallocate(entropy_mesh)
end if
! Deallocate ufs
if (allocated(source_frac)) deallocate(source_frac)
if (associated(ufs_mesh)) then
if (allocated(ufs_mesh % lower_left)) deallocate(ufs_mesh % lower_left)
if (allocated(ufs_mesh % upper_right)) &
deallocate(ufs_mesh % upper_right)
if (allocated(ufs_mesh % width)) deallocate(ufs_mesh % width)
deallocate(ufs_mesh)
end if
end subroutine free_memory

View file

@ -416,7 +416,7 @@ contains
#ifdef _OPENMP
! Read and set number of OpenMP threads
n_threads = str_to_int(argv(i))
n_threads = int(str_to_int(argv(i)), 4)
if (n_threads < 1) then
message = "Invalid number of threads specified on command line."
call fatal_error()

View file

@ -27,13 +27,17 @@ module matrix_header
procedure :: assemble => matrix_assemble
procedure :: get_row => matrix_get_row
procedure :: get_col => matrix_get_col
procedure :: vector_multiply => matrix_vector_multiply
#ifdef PETSC
procedure :: transpose => matrix_transpose
procedure :: setup_petsc => matrix_setup_petsc
procedure :: write_petsc_binary => matrix_write_petsc_binary
procedure :: transpose => matrix_transpose
procedure :: vector_multiply => matrix_vector_multiply
#endif
end type matrix
#ifdef PETSC
integer :: petsc_err
#endif
contains
@ -267,6 +271,7 @@ contains
! MATRIX_SETUP_PETSC configures the row/col vectors and links to a PETSc object
!===============================================================================
#ifdef PETSC
subroutine matrix_setup_petsc(self)
class(Matrix), intent(inout) :: self ! matrix instance
@ -276,50 +281,49 @@ contains
self % col = self % col - 1
! Link to petsc
#ifdef PETSC
call MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD, self % n, self % n, &
self % row, self % col, self % val, self % petsc_mat, petsc_err)
#endif
! Petsc is now active
self % petsc_active = .true.
end subroutine matrix_setup_petsc
#endif
!===============================================================================
! MATRIX_WRITE_PETSC_BINARY writes a PETSc matrix binary file
!===============================================================================
#ifdef PETSC
subroutine matrix_write_petsc_binary(self, filename)
character(*), intent(in) :: filename ! file name to write to
class(Matrix), intent(in) :: self ! matrix instance
#ifdef PETSC
type(PetscViewer) :: viewer ! a petsc viewer instance
call PetscViewerBinaryOpen(PETSC_COMM_WORLD, trim(filename), &
FILE_MODE_WRITE, viewer, petsc_err)
call MatView(self % petsc_mat, viewer, petsc_err)
call PetscViewerDestroy(viewer, petsc_err)
#endif
end subroutine matrix_write_petsc_binary
#endif
!===============================================================================
! MATRIX_TRANSPOSE uses PETSc to transpose a matrix
!===============================================================================
#ifdef PETSC
subroutine matrix_transpose(self)
class(Matrix), intent(inout) :: self ! matrix instance
#ifdef PETSC
call MatTranspose(self % petsc_mat, MAT_REUSE_MATRIX, self % petsc_mat, &
petsc_err)
#endif
end subroutine matrix_transpose
#endif
!===============================================================================
! MATRIX_VECTOR_MULTIPLY allow a vector to multiply the matrix

File diff suppressed because it is too large Load diff

View file

@ -158,7 +158,7 @@ contains
call position_rgb(p, pl, rgb, id)
! Create a pixel at (x,y) with color (r,g,b)
call set_pixel(img, x, y, rgb(1), rgb(2), rgb(3))
call set_pixel(img, x-1, y-1, rgb(1), rgb(2), rgb(3))
! Advance pixel in first direction
p % coord0 % xyz(in_i) = p % coord0 % xyz(in_i) + in_pixel
@ -175,6 +175,9 @@ contains
! Free up space
call deallocate_image(img)
! Clear particle
call p % clear()
end subroutine create_ppm
!===============================================================================

View file

@ -21,11 +21,15 @@ module vector_header
procedure :: create => vector_create
procedure :: destroy => vector_destroy
procedure :: add_value => vector_add_value
#ifdef PETSC
procedure :: setup_petsc => vector_setup_petsc
procedure :: write_petsc_binary => vector_write_petsc_binary
#endif
end type Vector
#ifdef PETSC
integer :: petsc_err ! petsc error code
#endif
contains
@ -88,39 +92,39 @@ contains
! VECTOR_SETUP_PETSC links the data to a PETSc vector
!===============================================================================
#ifdef PETSC
subroutine vector_setup_petsc(self)
class(Vector), intent(inout) :: self ! vector instance
! Link to PETSc
#ifdef PETSC
call VecCreateSeqWithArray(PETSC_COMM_WORLD, 1, self % n, self % val, &
self % petsc_vec, petsc_err)
#endif
! Set that PETSc is now active
self % petsc_active = .true.
end subroutine vector_setup_petsc
#endif
!===============================================================================
! VECTOR_WRITE_PETSC_BINARY writes the PETSc vector to a binary file
!===============================================================================
#ifdef PETSC
subroutine vector_write_petsc_binary(self, filename)
character(*), intent(in) :: filename ! name of file to write to
class(Vector), intent(in) :: self ! vector instance
#ifdef PETSC
type(PetscViewer) :: viewer ! PETSc viewer instance
call PetscViewerBinaryOpen(PETSC_COMM_WORLD, trim(filename), &
FILE_MODE_WRITE, viewer, petsc_err)
call VecView(self % petsc_vec, viewer, petsc_err)
call PetscViewerDestroy(viewer, petsc_err)
#endif
end subroutine vector_write_petsc_binary
#endif
end module vector_header

View file

@ -41,6 +41,8 @@ module openmc_fox
logical :: doneChildren, doneAttributes, allElements
integer :: i, i_tree
list => null()
if (.not.associated(doc)) then
if (getFoX_checks().or.FoX_NODE_IS_NULL<200) then
call throw_exception(FoX_NODE_IS_NULL, "getElementsByTagName", ex)

View file

@ -76,6 +76,7 @@ set(CTEST_UPDATE_COMMAND "git")
set(CTEST_CONFIGURE_COMMAND "${{CMAKE_COMMAND}} -H${{CTEST_SOURCE_DIRECTORY}} -B${{CTEST_BINARY_DIRECTORY}} ${{CTEST_BUILD_OPTIONS}}")
set(CTEST_MEMORYCHECK_COMMAND "{valgrind_cmd}")
set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes")
set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE ${{CTEST_SOURCE_DIRECTORY}}/../tests/valgrind.supp)
set(MEM_CHECK {mem_check})
set(ENV{{MEM_CHECK}} ${{MEM_CHECK}})

63
tests/valgrind.supp Normal file
View file

@ -0,0 +1,63 @@
{
Create HDF5 statepoint file
Memcheck:Addr4
fun:H5_build_extpath
fun:H5F_open
fun:H5Fcreate
fun:h5fcreate_c_
fun:__h5f_MOD_h5fcreate_f
fun:__hdf5_interface_MOD_hdf5_file_create
fun:__output_interface_MOD_file_create
fun:__state_point_MOD_write_state_point
fun:__eigenvalue_MOD_finalize_batch
fun:__eigenvalue_MOD_run_eigenvalue
fun:MAIN__
fun:main
}
{
Open HDF5 statepoint file
Memcheck:Addr4
fun:H5_build_extpath
fun:H5F_open
fun:H5Fopen
fun:h5fopen_c_
fun:__h5f_MOD_h5fopen_f
fun:__hdf5_interface_MOD_hdf5_file_open
fun:__output_interface_MOD_file_open
fun:__state_point_MOD_write_source_point
fun:__eigenvalue_MOD_finalize_batch
fun:__eigenvalue_MOD_run_eigenvalue
fun:MAIN__
fun:main
}
{
Create HDF5 summary file
Memcheck:Addr4
fun:H5_build_extpath
fun:H5F_open
fun:H5Fcreate
fun:h5fcreate_c_
fun:__h5f_MOD_h5fcreate_f
fun:__hdf5_interface_MOD_hdf5_file_create
fun:__output_interface_MOD_file_create
fun:__hdf5_summary_MOD_hdf5_write_summary
fun:__initialize_MOD_initialize_run
fun:MAIN__
fun:main
}
{
Create HDF5 track file
Memcheck:Addr4
fun:H5_build_extpath
fun:H5F_open
fun:H5Fcreate
fun:h5fcreate_c_
fun:__h5f_MOD_h5fcreate_f
fun:__hdf5_interface_MOD_hdf5_file_create
fun:__output_interface_MOD_file_create
fun:__track_output_MOD_finalize_particle_track
fun:__tracking_MOD_transport
fun:__eigenvalue_MOD_run_eigenvalue
fun:MAIN__
fun:main
}