Octopus
states_elec_group.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22
24 use batch_oct_m
25 use debug_oct_m
26 use global_oct_m
30 use types_oct_m
32 use mpi_oct_m
33
34 implicit none
35
36 private
37
38 public :: &
42
51 !
53 ! Components are public by default
54 type(wfs_elec_t), allocatable :: psib(:, :)
55 integer :: nblocks
56 integer :: block_start
57 integer :: block_end
58 integer, allocatable :: iblock(:)
59 integer, allocatable :: block_range(:, :)
60 integer, allocatable :: block_size(:)
61 logical, allocatable :: block_is_local(:, :)
62 integer, allocatable :: block_node(:,:)
63 type(MPI_Win), allocatable :: rma_win(:, :)
65 logical :: block_initialized = .false.
66 end type states_elec_group_t
67
68contains
69
70 ! ---------------------------------------------------------
72 !
73 subroutine states_elec_group_end(this, d)
74 type(states_elec_group_t), intent(inout) :: this
75 type(states_elec_dim_t), intent(in) :: d
76
77 integer :: ib, iq
78
79 push_sub(states_elec_group_end)
80
81 if (this%block_initialized) then
82 do ib = 1, this%nblocks
83 do iq = d%kpt%start, d%kpt%end
84 if (this%block_is_local(ib, iq)) then
85 call this%psib(ib, iq)%end()
86 end if
87 end do
88 end do
89
90 safe_deallocate_a(this%psib)
91
92 safe_deallocate_a(this%iblock)
93 safe_deallocate_a(this%block_range)
94 safe_deallocate_a(this%block_size)
95 safe_deallocate_a(this%block_is_local)
96 safe_deallocate_a(this%block_node)
97 safe_deallocate_a(this%rma_win)
98 this%block_initialized = .false.
99 end if
100
101 pop_sub(states_elec_group_end)
102 end subroutine states_elec_group_end
103
104 !---------------------------------------------------------
106 !
107 subroutine states_elec_group_copy(d, group_in, group_out, copy_data, special, dest_type)
108 type(states_elec_dim_t), intent(in) :: d
109 type(states_elec_group_t), intent(in) :: group_in
110 type(states_elec_group_t), intent(inout) :: group_out
111 logical, optional, intent(in) :: copy_data
112 logical, optional, intent(in) :: special
113 type(type_t), optional, intent(in) :: dest_type
114
115 integer :: qn_start, qn_end, ib, iqn
116
117 push_sub(states_elec_group_copy)
119 call states_elec_group_end(group_out, d)
120
121 group_out%nblocks = group_in%nblocks
122 group_out%block_start = group_in%block_start
123 group_out%block_end = group_in%block_end
124 group_out%block_initialized = group_in%block_initialized
125
126 if (group_out%block_initialized) then
127
128 assert(allocated(group_in%psib))
129
130 qn_start = d%kpt%start
131 qn_end = d%kpt%end
132
133 safe_allocate(group_out%psib(1:group_out%nblocks, qn_start:qn_end))
134
135 do iqn = qn_start, qn_end
136 do ib = group_out%block_start, group_out%block_end
137 call group_in%psib(ib, iqn)%copy_to(group_out%psib(ib, iqn), &
138 copy_data = optional_default(copy_data, .true.), special = special, dest_type = dest_type)
139 end do
140 end do
141
142 safe_allocate_source_a(group_out%iblock, group_in%iblock)
143 safe_allocate_source_a(group_out%block_range, group_in%block_range)
144 safe_allocate_source_a(group_out%block_size, group_in%block_size)
145 safe_allocate_source_a(group_out%block_is_local, group_in%block_is_local)
146 safe_allocate_source_a(group_out%block_node, group_in%block_node)
147 !TODO: Fix this. This wont duplicate MPI window resources
148 safe_allocate_source_a(group_out%rma_win, group_in%rma_win)
150 end if
158!! Local Variables:
159!! mode: f90
160!! coding: utf-8
161!! End:
This module implements batches of mesh functions.
Definition: batch.F90:135
This module handles spin dimensions of the states and the k-point distribution.
This module handles groups of electronic batches and their parallel distribution.
subroutine, public states_elec_group_copy(d, group_in, group_out, copy_data, special, dest_type)
make a copy of a group
subroutine, public states_elec_group_end(this, d)
finalize the local blocks of wave functions and release local arrays
int true(void)