reallocate_mat Subroutine

public subroutine reallocate_mat(m, nnz)

Reshape a boolean sparse matrix in Yale format to accomodate a larger number of non-zero elements or to trim unused non-zero elements after a guess allocation.

Arguments

Type IntentOptional Attributes Name
type(yale_sparse), intent(inout) :: m

Matrix to be reshaped

integer(kind=ip), intent(in) :: nnz

New shape for the matrix


Called by

proc~~reallocate_mat~~CalledByGraph proc~reallocate_mat reallocate_mat proc~create_new_bond create_new_bond proc~create_new_bond->proc~reallocate_mat proc~build_pg_adjacency_matrix build_pg_adjacency_matrix proc~build_pg_adjacency_matrix->proc~reallocate_mat proc~mat_mult mat_mult proc~mat_mult->proc~reallocate_mat proc~mat_mult2 mat_mult2 proc~mat_mult2->proc~reallocate_mat proc~mat_andnot mat_andnot proc~mat_andnot->proc~reallocate_mat proc~add_link_atom add_link_atom proc~add_link_atom->proc~create_new_bond proc~mmpol_prepare mmpol_prepare proc~mmpol_prepare->proc~build_pg_adjacency_matrix proc~build_conn_upto_n build_conn_upto_n proc~mmpol_prepare->proc~build_conn_upto_n proc~build_conn_upto_n->proc~mat_mult proc~build_conn_upto_n->proc~mat_andnot proc~ommp_create_link_atom ommp_create_link_atom proc~ommp_create_link_atom->proc~create_new_bond proc~ommp_create_link_atom->proc~add_link_atom proc~init_bonded_for_link_atom init_bonded_for_link_atom proc~ommp_create_link_atom->proc~init_bonded_for_link_atom proc~init_vdw_for_link_atom init_vdw_for_link_atom proc~ommp_create_link_atom->proc~init_vdw_for_link_atom proc~mmpol_init_from_mmp mmpol_init_from_mmp proc~mmpol_init_from_mmp->proc~mmpol_prepare proc~mmpol_init_from_xyz mmpol_init_from_xyz proc~mmpol_init_from_xyz->proc~mmpol_prepare proc~mmpol_init_from_xyz->proc~build_conn_upto_n proc~check_conn_matrix check_conn_matrix proc~mmpol_init_from_xyz->proc~check_conn_matrix proc~ommp_system_from_qm_helper ommp_system_from_qm_helper proc~ommp_system_from_qm_helper->proc~mmpol_prepare proc~ommp_system_from_qm_helper->proc~build_conn_upto_n proc~ommp_system_from_qm_helper->proc~check_conn_matrix proc~c_ommp_create_link_atom C_ommp_create_link_atom proc~c_ommp_create_link_atom->proc~ommp_create_link_atom proc~check_conn_matrix->proc~build_conn_upto_n proc~ommp_init_mmp ommp_init_mmp proc~ommp_init_mmp->proc~mmpol_init_from_mmp proc~init_bonded_for_link_atom->proc~check_conn_matrix proc~c_ommp_system_from_qm_helper C_ommp_system_from_qm_helper proc~c_ommp_system_from_qm_helper->proc~ommp_system_from_qm_helper proc~init_vdw_for_link_atom->proc~check_conn_matrix proc~ommp_init_xyz ommp_init_xyz proc~ommp_init_xyz->proc~mmpol_init_from_xyz proc~c_ommp_init_mmp C_ommp_init_mmp proc~c_ommp_init_mmp->proc~ommp_init_mmp proc~c_ommp_init_xyz C_ommp_init_xyz proc~c_ommp_init_xyz->proc~ommp_init_xyz

Contents

Source Code


Source Code

        subroutine reallocate_mat(m, nnz)
            !! Reshape a boolean sparse matrix in Yale format to accomodate a 
            !! larger number of non-zero elements or to trim unused non-zero
            !! elements after a guess allocation.

            implicit none

            type(yale_sparse), intent(inout) :: m
            !! Matrix to be reshaped
            integer(ip), intent(in) :: nnz
            !! New shape for the matrix
            
            integer(ip), allocatable :: tmp(:)

            if(nnz == 0) then
                ! The matrix is empty, just allocate empty ci
                deallocate(m%ci) 
                allocate(m%ci(0))
            else
                allocate(tmp(nnz))
                if(size(m%ci) > nnz) then
                    ! We are shrinking the matrix
                    tmp = m%ci(1:nnz)
                else
                    ! We are enlarging the matrix
                    tmp(1:size(m%ci)) = m%ci
                end if

                deallocate(m%ci)
                allocate(m%ci(nnz))
                m%ci = tmp
                deallocate(tmp)
            end if
        end subroutine reallocate_mat