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
112 write(91,*)
'%SPARSE MATRIX CSR ASYM'
114 write(91,*)
'%SPARSE MATRIX CSR SPD'
116 write(91,*)
'%SPARSE MATRIX CSR SYM'
117 write(91,*) spmat%N_loc, spmat%N_loc, spmat%NZ
119 write(91,*) spmat%IRN(i)
122 write(91,*) spmat%JCN(i), spmat%A(i)
126 write(91,*)
'%SPARSE MATRIX COO ASYM'
128 write(91,*)
'%SPARSE MATRIX COO SPD'
130 write(91,*)
'%SPARSE MATRIX COO SYM'
131 write(91,*) spmat%N_loc, spmat%N_loc, spmat%NZ
133 write(91,*) spmat%IRN(i), spmat%JCN(i), spmat%A(i)
140 type (sparse_matrix),
intent(in) :: spmat
141 real(kind=
kreal),
intent(out) :: rhs_all(:)
142 integer(kind=kint) :: ierr,i
145 rhs_all(i) = spmat%rhs(i)
149 rhs_all, spmat%N_COUNTS, spmat%DISPLS, &
155 type (sparse_matrix),
intent(inout) :: spmat
156 real(kind=
kreal),
intent(in) :: rhs_all(:)
157 integer(kind=kint) :: ierr,i
160 spmat%rhs(i) = rhs_all(i)
164 rhs_all, spmat%N_COUNTS, spmat%DISPLS, &
165 spmat%rhs, spmat%N_loc, &
171 type(sparse_matrix),
intent(inout) :: spmat
178 subroutine sparse_matrix_set_dimension(spMAT, N_loc)
179 type (sparse_matrix),
intent(inout) :: spmat
180 integer(kind=kint),
intent(in) :: n_loc
181 integer(kind=kint) :: ierr
184 spmat%N = spmat%N_loc
189 end subroutine sparse_matrix_set_dimension
191 subroutine sparse_matrix_set_offsets(spMAT)
192 type (sparse_matrix),
intent(inout) :: spmat
198 if (
associated(spmat%N_COUNTS))
deallocate(spmat%N_COUNTS)
199 if (
associated(spmat%DISPLS))
deallocate(spmat%DISPLS)
200 allocate(spmat%N_COUNTS(
nprocs), spmat%DISPLS(
nprocs), stat=ierr)
202 write(*,*)
" Allocation error, spMAT%N_COUNTS, spMAT%DISPLS"
212 spmat%DISPLS(i+1)=spmat%DISPLS(i)+spmat%N_COUNTS(i)
214 spmat%offset = spmat%DISPLS(
myrank+1)
215 end subroutine sparse_matrix_set_offsets
217 subroutine sparse_matrix_allocate_arrays(spMAT, NZ)
218 type(sparse_matrix),
intent(inout) :: spmat
219 integer(kind=kint),
intent(in) :: nz
220 integer(kind=kint) :: n_loc
221 integer(kind=kint) :: ierr
222 if (
associated(spmat%IRN))
deallocate(spmat%IRN)
223 if (
associated(spmat%JCN))
deallocate(spmat%JCN)
224 if (
associated(spmat%A))
deallocate(spmat%A)
228 allocate(spmat%IRN(n_loc+1), spmat%JCN(nz), spmat%A(nz), stat=ierr)
230 allocate(spmat%IRN(nz), spmat%JCN(nz), spmat%A(nz), stat=ierr)
233 write(*,*)
" Allocation error, spMAT%IRN, spMAT%JCN, spMAT%A"
237 end subroutine sparse_matrix_allocate_arrays
239 subroutine sparse_matrix_free_arrays(spMAT)
240 type (sparse_matrix),
intent(inout) :: spmat
241 if (
associated(spmat%IRN))
deallocate(spmat%IRN)
242 if (
associated(spmat%JCN))
deallocate(spmat%JCN)
243 if (
associated(spmat%A))
deallocate(spmat%A)
244 if (
associated(spmat%N_COUNTS))
deallocate(spmat%N_COUNTS)
245 if (
associated(spmat%DISPLS))
deallocate(spmat%DISPLS)
246 if (
associated(spmat%conv_ext))
deallocate(spmat%conv_ext)
247 end subroutine sparse_matrix_free_arrays
249 subroutine sparse_matrix_clear(spMAT)
250 type(sparse_matrix),
intent(inout) :: spmat
260 spmat%N_COUNTS => null()
261 spmat%DISPLS => null()
262 spmat%conv_ext => null()
265 end subroutine sparse_matrix_clear