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
31 use mpi_oct_m
32
33 implicit none
34
35 private
36
37 public :: &
41
50 !
52 ! Components are public by default
53 type(wfs_elec_t), allocatable :: psib(:, :)
54 integer :: nblocks
55 integer :: block_start
56 integer :: block_end
57 integer, allocatable :: iblock(:)
58 integer, allocatable :: block_range(:, :)
59 integer, allocatable :: block_size(:)
60 logical, allocatable :: block_is_local(:, :)
61 integer, allocatable :: block_node(:,:)
62 type(MPI_Win), allocatable :: rma_win(:, :)
64 logical :: block_initialized = .false.
65 end type states_elec_group_t
66
67contains
68
69 ! ---------------------------------------------------------
71 !
72 subroutine states_elec_group_end(this, d)
73 type(states_elec_group_t), intent(inout) :: this
74 type(states_elec_dim_t), intent(in) :: d
75
76 integer :: ib, iq
77
78 push_sub(states_elec_group_end)
79
80 if (this%block_initialized) then
81 do ib = 1, this%nblocks
82 do iq = d%kpt%start, d%kpt%end
83 if (this%block_is_local(ib, iq)) then
84 call this%psib(ib, iq)%end()
85 end if
86 end do
87 end do
88
89 safe_deallocate_a(this%psib)
90
91 safe_deallocate_a(this%iblock)
92 safe_deallocate_a(this%block_range)
93 safe_deallocate_a(this%block_size)
94 safe_deallocate_a(this%block_is_local)
95 safe_deallocate_a(this%block_node)
96 safe_deallocate_a(this%rma_win)
97 this%block_initialized = .false.
98 end if
99
100 pop_sub(states_elec_group_end)
101 end subroutine states_elec_group_end
102
103 !---------------------------------------------------------
105 !
106 subroutine states_elec_group_copy(d, group_in, group_out, copy_data, special)
107 type(states_elec_dim_t), intent(in) :: d
108 type(states_elec_group_t), intent(in) :: group_in
109 type(states_elec_group_t), intent(inout) :: group_out
110 logical, optional, intent(in) :: copy_data
111 logical, optional, intent(in) :: special
112
113 integer :: qn_start, qn_end, ib, iqn
114
115 push_sub(states_elec_group_copy)
117 call states_elec_group_end(group_out, d)
118
119 group_out%nblocks = group_in%nblocks
120 group_out%block_start = group_in%block_start
121 group_out%block_end = group_in%block_end
122 group_out%block_initialized = group_in%block_initialized
123
124 if (group_out%block_initialized) then
125
126 assert(allocated(group_in%psib))
127
128 qn_start = d%kpt%start
129 qn_end = d%kpt%end
130
131 safe_allocate(group_out%psib(1:group_out%nblocks, qn_start:qn_end))
132
133 do iqn = qn_start, qn_end
134 do ib = group_out%block_start, group_out%block_end
135 call group_in%psib(ib, iqn)%copy_to(group_out%psib(ib, iqn), &
136 copy_data = optional_default(copy_data, .true.), special = special)
137 end do
138 end do
139
140 safe_allocate_source_a(group_out%iblock, group_in%iblock)
141 safe_allocate_source_a(group_out%block_range, group_in%block_range)
142 safe_allocate_source_a(group_out%block_size, group_in%block_size)
143 safe_allocate_source_a(group_out%block_is_local, group_in%block_is_local)
144 safe_allocate_source_a(group_out%block_node, group_in%block_node)
145 !TODO: Fix this. This wont duplicate MPI window resources
146 safe_allocate_source_a(group_out%rma_win, group_in%rma_win)
148 end if
156!! Local Variables:
157!! mode: f90
158!! coding: utf-8
159!! End:
This module implements batches of mesh functions.
Definition: batch.F90:133
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)
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)