56 type,
extends(distributedmatrix) :: writermatrix
59 type(matrixcache) :: write_cache
61 integer :: num_elements_per_record
62 integer :: matrix_unit
64 procedure,
public :: print => print_writer
65 procedure,
public :: finalize_matrix_self => finalize_matrix_writer
66 procedure,
public :: set_options => set_options_writer
67 procedure,
public :: get_matelem_self => get_matelem_writer
68 procedure,
public :: clear_matrix => clear_writer
69 procedure,
public :: destroy_matrix => destroy_writer
70 procedure,
public :: write_cache_to_unit
71 procedure,
public :: insert_into_diag_matrix => insert_into_write_cache
72 procedure,
public :: get_matrix_unit
93 subroutine set_options_writer (this, option_val)
94 class(writermatrix) :: this
95 class(options),
intent(in) :: option_val
97 this % matrix_unit = option_val % hamiltonian_unit
98 this % num_elements_per_record = option_val % num_matrix_elements_per_rec
101 call this % write_cache % construct(this % num_elements_per_record + 1)
132 subroutine write_cache_to_unit (this)
133 class(writermatrix) :: this
134 integer :: record_count
136 if (this % write_cache % is_empty())
return
138 record_count = this % write_cache % get_size()
141 call wrtem(this % matrix_unit, record_count, this % num_elements_per_record, &
142 this % write_cache % matrix_arrays(1) % ij(1:2,1:record_count), &
143 this % write_cache % matrix_arrays(1) % coefficient(1:record_count))
144 call this % write_cache % clear
158 logical function insert_into_write_cache (this, row, column, coefficient)
159 class(writermatrix) :: this
160 integer,
intent(in) :: row, column
161 real(wp),
intent(in) :: coefficient
162 integer :: record_count
164 if (grid % grank /= master)
then
165 insert_into_write_cache = .false.
169 if (row == column)
then
170 if (row >
size(this % diagonal))
then
171 write (stdout,
"('Row greater than size of diagonal!!!!',2i12)") row,
size(this % diagonal)
174 this % diagonal(row) = coefficient
177 insert_into_write_cache = .true.
178 if (abs(coefficient) < this % threshold)
return
180 call this % write_cache % insert_into_cache(row, column, coefficient)
181 record_count = this % write_cache % get_size()
184 this % n = this % n + 1
185 insert_into_write_cache = .true.
187 if (record_count == this % num_elements_per_record)
then
189 call this % write_cache_to_unit
202 subroutine finalize_matrix_writer (this)
203 class(writermatrix) :: this
204 integer :: dummy_ij(2, this % num_elements_per_record), record_count = 0
205 real(wp) :: dummy_coeff(this % num_elements_per_record)
207 if (grid % grank /= master)
return
209 write (stdout,
"('finishing unit')")
210 call this % write_cache_to_unit
212 call wrtem(this % matrix_unit, record_count, this % num_elements_per_record, dummy_ij, dummy_coeff)
213 write (stdout,
"('done')")