20 dbcsr_type_no_symmetry
36#include "./base/base_uses.f90"
40 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_dbcsr_redistribution'
57 INTEGER,
DIMENSION(:, :),
OPTIONAL :: block_row_ranges
59 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cp_dbcsr_to_subgroups'
61 INTEGER :: block_offset, block_size, col, col_size, handle, handle2, i_block, igroup, imep, &
62 imep_sub, msg_offset, ngroup, offset, row, row_size
63 INTEGER,
ALLOCATABLE :: counts_rec(:, :), counts_send(:, :)
64 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: blk_counter, entry_counter
66 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: data_block
70 CALL timeset(routinen, handle)
72 CALL timeset(routinen//
"_count", handle2)
76 ALLOCATE (counts_send(2, 0:para_env%num_pe - 1), counts_rec(2, 0:para_env%num_pe - 1))
79 ngroup = para_env%num_pe/num_pe_sub
85 row_size=row_size, col_size=col_size)
89 DO igroup = 0, ngroup - 1
91 IF (
PRESENT(block_row_ranges))
THEN
92 IF (row < block_row_ranges(1, igroup + 1) .OR. row > block_row_ranges(2, igroup + 1)) cycle
94 imep = imep_sub + igroup*num_pe_sub
96 counts_send(1, imep) = counts_send(1, imep) + row_size*col_size
97 counts_send(2, imep) = counts_send(2, imep) + 1
105 CALL timestop(handle2)
107 CALL timeset(routinen//
"_exchange_counts", handle2)
109 IF (para_env%num_pe > 1)
THEN
110 CALL para_env%alltoall(counts_send, counts_rec, 2)
112 counts_rec(:, :) = counts_send
115 CALL timestop(handle2)
117 CALL timeset(routinen//
"_pack", handle2)
120 counts_send(2, :), counts_rec(2, :))
122 ALLOCATE (entry_counter(0:para_env%num_pe - 1))
123 entry_counter(:) = buffer_send%msg_offset(:para_env%num_pe - 1)
125 ALLOCATE (blk_counter(0:para_env%num_pe - 1))
126 blk_counter(:) = buffer_send%indx_offset(:para_env%num_pe - 1)
132 row_size=row_size, col_size=col_size)
136 DO igroup = 0, ngroup - 1
138 IF (
PRESENT(block_row_ranges))
THEN
139 IF (row < block_row_ranges(1, igroup + 1) .OR. row > block_row_ranges(2, igroup + 1)) cycle
142 imep = imep_sub + igroup*num_pe_sub
144 msg_offset = entry_counter(imep)
146 block_size = row_size*col_size
148 buffer_send%msg(msg_offset + 1:msg_offset + block_size) = &
149 reshape(data_block(1:row_size, 1:col_size), [block_size])
151 entry_counter(imep) = entry_counter(imep) + block_size
153 blk_counter(imep) = blk_counter(imep) + 1
155 block_offset = blk_counter(imep)
158 buffer_send%indx(:, block_offset) = [row, col, msg_offset - buffer_send%msg_offset(imep)]
166 CALL timestop(handle2)
168 CALL timeset(routinen//
"_exchange_data", handle2)
172 CALL timestop(handle2)
174 CALL timeset(routinen//
"_reserve", handle2)
182 CALL timestop(handle2)
184 CALL timeset(routinen//
"_unpack", handle2)
186 DO imep = 0, para_env%num_pe - 1
187 DO i_block = buffer_rec%indx_offset(imep) + 1, buffer_rec%indx_offset(imep + 1)
188 row = buffer_rec%indx(1, i_block)
189 col = buffer_rec%indx(2, i_block)
190 offset = buffer_rec%msg_offset(imep) + buffer_rec%indx(3, i_block)
192 row_size=row_size, col_size=col_size)
194 data_block(:, :) = reshape(buffer_rec%msg(offset + 1:offset + row_size*col_size), &
195 [row_size, col_size])
199 CALL timestop(handle2)
201 CALL timestop(handle)
217 INTEGER,
DIMENSION(:),
INTENT(IN),
OPTIONAL :: row_mapping
218 LOGICAL,
INTENT(IN),
OPTIONAL :: copy_only
220 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cp_dbcsr_from_subgroups'
222 INTEGER :: block_size, col, col_size, handle, &
223 handle2, i_block, imep, mapped_row, &
224 offset, row, row_size
225 INTEGER,
ALLOCATABLE :: counts_rec(:, :), counts_send(:, :)
226 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: block_counter, entry_counter
227 LOGICAL :: found, my_copy_only
228 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: data_block
232 CALL timeset(routinen, handle)
233 my_copy_only = .false.
234 IF (
PRESENT(copy_only)) my_copy_only = copy_only
236 CALL timeset(routinen//
"_prepare", handle2)
238 IF (.NOT. my_copy_only)
THEN
243 ALLOCATE (counts_send(2, 0:para_env%num_pe - 1), counts_rec(2, 0:para_env%num_pe - 1))
250 row_size=row_size, col_size=col_size)
253 IF (
PRESENT(row_mapping)) mapped_row = row_mapping(row)
256 counts_send(1, imep) = counts_send(1, imep) + row_size*col_size
257 counts_send(2, imep) = counts_send(2, imep) + 1
263 CALL timestop(handle2)
265 CALL timeset(routinen//
"_exchange_counts", handle2)
267 IF (para_env%num_pe > 1)
THEN
268 CALL para_env%alltoall(counts_send, counts_rec, 2)
270 counts_rec(:, :) = counts_send
273 CALL timestop(handle2)
275 CALL timeset(routinen//
"_pack", handle2)
278 counts_send(2, :), counts_rec(2, :))
280 ALLOCATE (block_counter(0:para_env%num_pe - 1))
281 block_counter(:) = buffer_send%indx_offset(:para_env%num_pe - 1)
283 ALLOCATE (entry_counter(0:para_env%num_pe - 1))
284 entry_counter(:) = buffer_send%msg_offset(:para_env%num_pe - 1)
291 row_size=row_size, col_size=col_size)
294 IF (
PRESENT(row_mapping)) mapped_row = row_mapping(row)
297 block_size = row_size*col_size
299 offset = entry_counter(imep)
301 buffer_send%msg(offset + 1:offset + block_size) = &
302 reshape(data_block(1:row_size, 1:col_size), [block_size])
304 i_block = block_counter(imep) + 1
307 buffer_send%indx(:, i_block) = [mapped_row, col, offset - buffer_send%msg_offset(imep)]
309 entry_counter(imep) = entry_counter(imep) + block_size
311 block_counter(imep) = block_counter(imep) + 1
317 CALL timestop(handle2)
319 CALL timeset(routinen//
"_exchange_data", handle2)
323 CALL timestop(handle2)
325 CALL timeset(routinen//
"_unpack", handle2)
328 DO imep = 0, para_env%num_pe - 1
329 DO i_block = buffer_rec%indx_offset(imep) + 1, buffer_rec%indx_offset(imep + 1)
330 row = buffer_rec%indx(1, i_block)
331 col = buffer_rec%indx(2, i_block)
332 offset = buffer_rec%msg_offset(imep) + buffer_rec%indx(3, i_block)
334 row_size=row_size, col_size=col_size)
336 IF (my_copy_only)
THEN
337 data_block(:, :) = reshape(buffer_rec%msg(offset + 1:offset + row_size*col_size), &
338 [row_size, col_size])
340 data_block(:, :) = data_block + &
341 reshape(buffer_rec%msg(offset + 1:offset + row_size*col_size), &
342 [row_size, col_size])
347 IF (.NOT. my_copy_only)
THEN
352 IF (.NOT. my_copy_only)
THEN
357 CALL timestop(handle2)
359 CALL timestop(handle)
377 first_row, last_row, template, matrices, matrix_ptrs)
378 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
379 INTENT(INOUT) :: array
380 INTEGER,
INTENT(IN) :: nrows, ncols
382 INTEGER,
INTENT(IN) :: first_row, last_row
384 TYPE(
dbcsr_type),
DIMENSION(:),
INTENT(INOUT), &
385 OPTIONAL,
TARGET :: matrices
387 OPTIONAL :: matrix_ptrs
389 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cp_array_to_dbcsr_slices'
391 INTEGER :: flat_row, handle, i, ientry, islice, j, &
393 INTEGER,
ALLOCATABLE :: counter(:), recv_count(:), &
394 send_count(:), source_rows(:)
401 CALL timeset(routinen, handle)
402 cpassert(
PRESENT(matrices) .NEQV.
PRESENT(matrix_ptrs))
403 NULLIFY (blacs_env, fm_struct)
406 ncol_global=ncols, para_env=para_env_sub)
411 nprocs = para_env_sub%num_pe
412 ALLOCATE (send_count(0:nprocs - 1), recv_count(0:nprocs - 1), counter(0:nprocs - 1))
418 CALL para_env_sub%alltoall(send_count, recv_count, 1)
420 ALLOCATE (source_rows(
SIZE(buffer_send%msg)))
421 counter(:) = buffer_send%msg_offset(:nprocs - 1)
423 DO flat_row = first_row, last_row
424 i = (flat_row - 1)/ncols + 1
425 j = mod(flat_row - 1, ncols) + 1
426 peer = fm_ia%matrix_struct%context%blacs2mpi( &
427 fm_ia%matrix_struct%g2p_row(i), fm_ia%matrix_struct%g2p_col(j))
429 send_count(peer) = send_count(peer) + 1
431 counter(peer) = counter(peer) + 1
432 ientry = counter(peer)
433 buffer_send%indx(:, ientry) = [i, j]
434 source_rows(ientry) = flat_row - first_row + 1
440 DO ientry = 1,
SIZE(buffer_rec%msg)
441 buffer_rec%indx(1, ientry) = fm_ia%matrix_struct%g2l_row(buffer_rec%indx(1, ientry))
442 buffer_rec%indx(2, ientry) = fm_ia%matrix_struct%g2l_col(buffer_rec%indx(2, ientry))
445 DO islice = 1,
SIZE(array, 2)
446 DO ientry = 1,
SIZE(buffer_send%msg)
447 buffer_send%msg(ientry) = array(source_rows(ientry), islice)
451 DO ientry = 1,
SIZE(buffer_rec%msg)
452 i = buffer_rec%indx(1, ientry)
453 j = buffer_rec%indx(2, ientry)
454 fm_ia%local_data(i, j) = buffer_rec%msg(ientry)
457 IF (
PRESENT(matrices))
THEN
458 output_matrix => matrices(islice)
460 ALLOCATE (matrix_ptrs(islice)%matrix)
461 output_matrix => matrix_ptrs(islice)%matrix
464 m=nrows, n=ncols, sym=dbcsr_type_no_symmetry)
470 CALL timestop(handle)
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
subroutine, public cp_blacs_env_create(blacs_env, para_env, blacs_grid_layout, blacs_repeatable, row_major, grid_2d)
allocates and initializes a type that represent a blacs context
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_reserve_blocks(matrix, rows, cols)
...
subroutine, public dbcsr_get_stored_coordinates(matrix, row, column, processor)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_iterator_readonly_start(iterator, matrix, shared, dynamic, dynamic_byrows)
Like dbcsr_iterator_start() but with matrix being INTENT(IN). When invoking this routine,...
subroutine, public dbcsr_clear(matrix)
...
subroutine, public dbcsr_reserve_all_blocks(matrix)
Reserves all blocks.
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_m_by_n_from_template(matrix, template, m, n, sym)
Utility function to create an arbitrary shaped dbcsr matrix with the same processor grid as the templ...
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Redistribution of DBCSR blocks and distributed matrix slices.
subroutine, public cp_array_to_dbcsr_slices(array, nrows, ncols, para_env_sub, first_row, last_row, template, matrices, matrix_ptrs)
Consume a distributed flattened array and create a DBCSR matrix per slice.
subroutine, public cp_dbcsr_to_subgroups(mat_global, mat_local, para_env, num_pe_sub, block_row_ranges)
...
subroutine, public cp_dbcsr_from_subgroups(mat_local, mat_global, para_env, row_mapping, copy_only)
Sum subgroup blocks into the global layout, or copy mapped blocks.
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
Defines the basic variable types.
integer, parameter, public dp
Exchange numerical matrix payloads and integer metadata between MPI ranks.
subroutine, public exchange_matrix_buffers(comm, buffer_rec, buffer_send, do_indx, do_msg)
Synchronously exchange flat matrix buffers with nonempty peers.
subroutine, public allocate_matrix_buffers(send_count, recv_count, n_index, buffer_send, buffer_rec, send_blocks, recv_blocks)
Allocate flat, rank-grouped matrix buffers and their zero-based offsets.
Interface to the message passing library MPI.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
stores all the informations relevant to an mpi environment