34 use blas_lapack_gbl,
only: blasint
35 use const_gbl,
only: stdout
36 use precisn,
only: longint, wp
50 real(wp),
allocatable :: a_local_matrix(:,:)
51 integer(blasint) :: mat_dimen
52 integer(blasint) :: scal_block_size
53 integer(blasint) :: local_row_dimen, local_col_dimen
54 integer(blasint) :: descr_a_mat(50), descr_z_mat(50)
55 integer(blasint) :: lda
56 logical :: store_mat = .false.
98 integer,
intent(in) :: matrix_size, matrix_type, block_size
100 integer :: ifail, per_elm, dummy_int, c_update, l_update
101 real(wp) :: dummy_real
104 integer(blasint) :: ierr, ido, nb, info, nproc, nprow, npcol, myrow, mycol
105 integer(blasint),
external :: numroc
107 this % mat_dimen = matrix_size
109 nprow = grid % gprows
110 npcol = grid % gpcols
111 myrow = grid % mygrow
112 mycol = grid % mygcol
114 nproc = nprow * npcol
116 write (stdout,
"('nproc = ',i4,'matdimen = ',i4,'nrow = ',i4,' ncol = ',i4,'myrow = ',i4,' mycol = ',i4)") &
117 nproc, this % mat_dimen, nprow, npcol, myrow, mycol
119 write (stdout,
"('context = ',i4,'nprocs = ',i4,'matdimen = ',i8,'nrow = ',i8,' ncol = ',i8,'myrow = ',i8,' mycol = ',i8)")&
120 grid % gcntxt, nproc, this % mat_dimen, nprow, npcol, myrow, mycol
122 this % store_mat = .true.
124 if (.not. this % am_i_involved())
return
126 this % scal_block_size = min(int(this % mat_dimen) / nprow, this % matrix_dimension / npcol)
127 this % scal_block_size = min(this % scal_block_size, 64_blasint)
128 this % scal_block_size = max(this % scal_block_size, 1_blasint)
130 this % local_row_dimen = numroc(this % mat_dimen, this % scal_block_size, myrow, 0, nprow)
131 this % local_col_dimen = numroc(this % mat_dimen, this % scal_block_size, mycol, 0, npcol)
133 this % lda = max(1_blasint, this % local_row_dimen)
135 write (stdout,
"('block_size = ',i4,' local_row_size = ',i8,' local_col_size = ',i8,' lda = ',i8)") &
136 this % scal_block_size, this % local_row_dimen, this % local_col_dimen, this % lda
138 call descinit(this % descr_a_mat, this % mat_dimen, this % mat_dimen, this % scal_block_size, this % scal_block_size, &
139 0, 0, grid % gcntxt, this % lda, info)
141 write (stdout,
"('Error in getting description for A', i4)") info
145 call descinit(this % descr_z_mat, this % mat_dimen, this % mat_dimen, this % scal_block_size, this % scal_block_size, &
146 0, 0, grid % gcntxt, this % lda, info)
148 write (stdout,
"('Error in getting description for Z', i4)") info
152 if (
allocated(this % a_local_matrix))
then
153 call master_memory % free_memory(kind(this % a_local_matrix),
size(this % a_local_matrix))
154 deallocate(this % a_local_matrix)
157 allocate(this % a_local_matrix(this % local_row_dimen, this % local_col_dimen), stat = ifail)
158 call master_memory % track_memory(kind(this % a_local_matrix),
size(this % a_local_matrix), ifail, &
159 'SCALAPACKMATRIX::A_LOCAL_MATRIX')
161 this % a_local_matrix = 0
162 this % n = real(this % local_row_dimen) * real(this % local_col_dimen)
174 integer(blasint),
intent(in) :: proc_row, proc_col
176 is_this_me = (proc_row == grid % mygrow) .and. &
177 (proc_col == grid % mygcol)
189 integer,
intent(in) :: idx
190 integer,
intent(out) :: i, j
191 real(wp),
intent(out) :: coeff
193 integer(blasint) :: i_loc, j_loc, proc_row, proc_col
194 integer(blasint),
external :: indxl2g
196 i_loc = idx / this % local_row_dimen + 1
197 j_loc = mod(idx, int(this % local_col_dimen)) + 1
199 i = indxl2g(i_loc, this % scal_block_size, grid % mygrow, 0, grid % gprows)
200 j = indxl2g(j_loc, this % scal_block_size, grid % mygcol, 0, grid % gpcols)
202 coeff = this % a_local_matrix(i_loc, j_loc)
217 integer,
intent(in) :: row, column
218 real(wp),
intent(in) :: coefficient
220 integer(blasint) :: proc_row, proc_col, i_loc, j_loc, blas_row, blas_col
225 if (row == column)
call this % store_diagonal(row, coefficient)
226 if (.not. this % am_i_involved())
return
229 call infog2l(blas_row, blas_col, this % descr_a_mat, &
230 grid % gprows, grid % gpcols, &
231 grid % mygrow, grid % mygcol, &
232 i_loc, j_loc, proc_row, proc_col)
234 if (this % is_this_me(proc_row, proc_col))
then
235 this % a_local_matrix(i_loc, j_loc) = coefficient
251 write (stdout,
"('-------TEMP CACHE---------')")
252 call this % temp_cache % print
266 if (
allocated(this % a_local_matrix)) this % a_local_matrix = 0
278 if (
allocated(this % a_local_matrix))
then
279 call master_memory % free_memory(kind(this % a_local_matrix),
size(this % a_local_matrix))
280 if (
allocated(this % a_local_matrix))
deallocate(this % a_local_matrix)