20 public :: sparse_matrix
37 integer(kind=kint) :: type
38 integer(kind=kint) :: symtype
39 integer(kind=kint) :: n, n_loc
40 integer(kind=kint) :: nz
41 integer(kind=kint),
pointer :: irn(:) => null()
42 integer(kind=kint),
pointer :: jcn(:) => null()
43 real(kind=
kreal),
pointer :: a(:) => null()
44 real(kind=
kreal),
pointer :: rhs(:)
45 integer(kind=kint) :: offset
46 integer(kind=kint),
pointer :: n_counts(:) => null()
47 integer(kind=kint),
pointer :: displs(:) => null()
48 integer(kind=kint),
pointer :: conv_ext(:) => null()
49 integer(kind=kint) :: iterlog
50 integer(kind=kint) :: timelog
51 logical :: is_initialized = .false.
52 end type sparse_matrix
59 type (sparse_matrix),
intent(inout) :: spmat
60 integer(kind=kint),
intent(in) :: type
61 integer(kind=kint),
intent(in) :: symtype
66 write(*,*)
'ERROR: unknown sparse matrix type'
72 spmat%symtype = symtype
74 write(*,*)
'ERROR: unknown symmetry type for sparse matrix'
80 type (sparse_matrix),
intent(inout) :: spmat
81 integer(kind=kint),
intent(in) :: n_loc
82 integer(kind=kint),
intent(in) :: nz
83 if (spmat%is_initialized)
then
87 call sparse_matrix_set_dimension(spmat, n_loc)
88 call sparse_matrix_set_offsets(spmat)
89 call sparse_matrix_allocate_arrays(spmat, nz)
90 spmat%is_initialized = .true.
94 type (sparse_matrix),
intent(inout) :: spmat
95 call sparse_matrix_free_arrays(spmat)
96 call sparse_matrix_clear(spmat)
97 spmat%is_initialized = .false.
101 type(sparse_matrix),
intent(in) :: spmat
102 integer(kind=kint),
save :: num_call
103 character(len=128) :: fname
104 integer(kind=kint) :: i,myrank
106 write(fname,
'(A,I0,A,I0)')
'sparse-matrix-',num_call,
'.coo.',myrank
107 num_call = num_call + 1
108 write(*,*)
'Dumping sparse matrix to ', fname
109 open(91,file=fname,iostat=i)
113 write(91,*)
'%SPARSE MATRIX CSR ASYM'
115 write(91,*)
'%SPARSE MATRIX CSR SPD'
117 write(91,*)
'%SPARSE MATRIX CSR SYM'
118 write(91,*) spmat%N_loc, spmat%N_loc, spmat%NZ
120 write(91,*) spmat%IRN(i)
123 write(91,*) spmat%JCN(i), spmat%A(i)
127 write(91,*)
'%SPARSE MATRIX COO ASYM'
129 write(91,*)
'%SPARSE MATRIX COO SPD'
131 write(91,*)
'%SPARSE MATRIX COO SYM'
132 write(91,*) spmat%N_loc, spmat%N_loc, spmat%NZ
134 write(91,*) spmat%IRN(i), spmat%JCN(i), spmat%A(i)
141 type (sparse_matrix),
intent(in) :: spmat
142 real(kind=
kreal),
intent(out) :: rhs_all(:)
143 integer(kind=kint) :: ierr,i
146 rhs_all(i) = spmat%rhs(i)
150 rhs_all, spmat%N_COUNTS, spmat%DISPLS, &
156 type (sparse_matrix),
intent(inout) :: spmat
157 real(kind=
kreal),
intent(in) :: rhs_all(:)
158 integer(kind=kint) :: ierr,i
161 spmat%rhs(i) = rhs_all(i)
165 rhs_all, spmat%N_COUNTS, spmat%DISPLS, &
166 spmat%rhs, spmat%N_loc, &
172 type(sparse_matrix),
intent(inout) :: spmat
179 subroutine sparse_matrix_set_dimension(spMAT, N_loc)
180 type (sparse_matrix),
intent(inout) :: spmat
181 integer(kind=kint),
intent(in) :: n_loc
182 integer(kind=kint) :: ierr
185 spmat%N = spmat%N_loc
190 end subroutine sparse_matrix_set_dimension
192 subroutine sparse_matrix_set_offsets(spMAT)
193 type (sparse_matrix),
intent(inout) :: spmat
194 integer(kind=kint) :: i,ierr,nprocs,myrank
199 if (
associated(spmat%N_COUNTS))
deallocate(spmat%N_COUNTS)
200 if (
associated(spmat%DISPLS))
deallocate(spmat%DISPLS)
201 allocate(spmat%N_COUNTS(nprocs), spmat%DISPLS(nprocs), stat=ierr)
203 write(*,*)
" Allocation error, spMAT%N_COUNTS, spMAT%DISPLS"
213 spmat%DISPLS(i+1)=spmat%DISPLS(i)+spmat%N_COUNTS(i)
215 spmat%offset = spmat%DISPLS(myrank+1)
216 end subroutine sparse_matrix_set_offsets
218 subroutine sparse_matrix_allocate_arrays(spMAT, NZ)
219 type(sparse_matrix),
intent(inout) :: spmat
220 integer(kind=kint),
intent(in) :: nz
221 integer(kind=kint) :: n_loc
222 integer(kind=kint) :: ierr
223 if (
associated(spmat%IRN))
deallocate(spmat%IRN)
224 if (
associated(spmat%JCN))
deallocate(spmat%JCN)
225 if (
associated(spmat%A))
deallocate(spmat%A)
229 allocate(spmat%IRN(n_loc+1), spmat%JCN(nz), spmat%A(nz), stat=ierr)
231 allocate(spmat%IRN(nz), spmat%JCN(nz), spmat%A(nz), stat=ierr)
234 write(*,*)
" Allocation error, spMAT%IRN, spMAT%JCN, spMAT%A"
238 end subroutine sparse_matrix_allocate_arrays
240 subroutine sparse_matrix_free_arrays(spMAT)
241 type (sparse_matrix),
intent(inout) :: spmat
242 if (
associated(spmat%IRN))
deallocate(spmat%IRN)
243 if (
associated(spmat%JCN))
deallocate(spmat%JCN)
244 if (
associated(spmat%A))
deallocate(spmat%A)
245 if (
associated(spmat%N_COUNTS))
deallocate(spmat%N_COUNTS)
246 if (
associated(spmat%DISPLS))
deallocate(spmat%DISPLS)
247 if (
associated(spmat%conv_ext))
deallocate(spmat%conv_ext)
248 end subroutine sparse_matrix_free_arrays
250 subroutine sparse_matrix_clear(spMAT)
251 type(sparse_matrix),
intent(inout) :: spmat
261 spmat%N_COUNTS => null()
262 spmat%DISPLS => null()
263 spmat%conv_ext => null()
266 end subroutine sparse_matrix_clear
integer(kind=kint), parameter hecmw_sum
integer(kind=kint) function hecmw_comm_get_size()
integer(kind=kint) function hecmw_comm_get_comm()
integer(kind=4), parameter kreal
integer(kind=kint) function hecmw_comm_get_rank()
subroutine hecmw_abort(comm)
subroutine hecmw_gatherv_real(sbuf, sc, rbuf, rcs, disp, root, comm)
subroutine hecmw_scatterv_real(sbuf, scs, disp, rbuf, rc, root, comm)
subroutine hecmw_allgather_int_1(sval, rbuf, comm)
subroutine hecmw_allreduce_int_1(sval, rval, op, comm)
This module provides DOF based sparse matrix data structure (CSR and COO)
subroutine, public sparse_matrix_init(spMAT, N_loc, NZ)
logical function, public sparse_matrix_is_sym(spMAT)
integer(kind=kint), parameter, public sparse_matrix_type_coo
integer(kind=kint), parameter, public sparse_matrix_type_csr
integer(kind=kint), parameter, public sparse_matrix_symtype_sym
subroutine, public sparse_matrix_finalize(spMAT)
subroutine, public sparse_matrix_gather_rhs(spMAT, rhs_all)
subroutine, public sparse_matrix_scatter_rhs(spMAT, rhs_all)
subroutine, public sparse_matrix_dump(spMAT)
integer(kind=kint), parameter, public sparse_matrix_symtype_asym
integer(kind=kint), parameter, public sparse_matrix_symtype_spd
subroutine, public sparse_matrix_set_type(spMAT, type, symtype)