(git:e5b1968)
Loading...
Searching...
No Matches
cp_blacs_types.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief wrappers for the actual blacs calls.
10!> all functionality needed in the code should actually be provide by cp_blacs_env
11!> these functions should be private members of that module
12!> \note
13!> http://www.netlib.org/blacs/BLACS/QRef.html
14!> \par History
15!> 12.2003 created [Joost]
16!> \author Joost VandeVondele
17! **************************************************************************************************
19
20 USE kinds, ONLY: dp
22#include "../base/base_uses.f90"
23
24 IMPLICIT NONE
25 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_blacs_types'
26 PRIVATE
27
28 PUBLIC :: cp_blacs_type
29
31 PRIVATE
32#if defined(__parallel)
33 INTEGER :: context_handle = -1
34#endif
35 INTEGER, DIMENSION(2), PUBLIC :: mepos = -1, num_pe = -1
36 CONTAINS
37 PROCEDURE, PUBLIC, pass(this), non_overridable :: gridinit => cp_blacs_gridinit
38 PROCEDURE, PUBLIC, pass(this), non_overridable :: gridexit => cp_blacs_gridexit
39 PROCEDURE, PRIVATE, pass(this), non_overridable :: gridinfo => cp_blacs_gridinfo
40 PROCEDURE, PUBLIC, pass(this), non_overridable :: set => cp_blacs_set
41 PROCEDURE, PUBLIC, pass(this), non_overridable :: zgebs2d => cp_blacs_zgebs2d
42 PROCEDURE, PUBLIC, pass(this), non_overridable :: dgebs2d => cp_blacs_dgebs2d
43 PROCEDURE, PUBLIC, pass(this), non_overridable :: zgebr2d => cp_blacs_zgebr2d
44 PROCEDURE, PUBLIC, pass(this), non_overridable :: dgebr2d => cp_blacs_dgebr2d
45 PROCEDURE, PUBLIC, pass(this), non_overridable :: get_handle => cp_blacs_get_handle
46
47 PROCEDURE, PRIVATE, pass(this), non_overridable :: cp_context_is_equal
48 generic, PUBLIC :: OPERATOR(==) => cp_context_is_equal
49
50 PROCEDURE, PRIVATE, pass(this), non_overridable :: cp_context_is_not_equal
51 generic, PUBLIC :: OPERATOR(/=) => cp_context_is_not_equal
52
53 PROCEDURE, PUBLIC, pass(this), non_overridable :: interconnect => cp_blacs_interconnect
54 END TYPE
55
56!***
57CONTAINS
58
59! **************************************************************************************************
60!> \brief ...
61!> \param this ...
62!> \param comm ...
63!> \param order ...
64!> \param nprow ...
65!> \param npcol ...
66! **************************************************************************************************
67 SUBROUTINE cp_blacs_gridinit(this, comm, order, nprow, npcol)
68 CLASS(cp_blacs_type), INTENT(OUT) :: this
69 CLASS(mp_comm_type), INTENT(IN) :: comm
70 CHARACTER(len=1), INTENT(IN):: order
71 INTEGER, INTENT(IN) :: nprow, npcol
72#if defined(__parallel)
73 INTEGER :: context_handle
74 context_handle = comm%get_handle()
75 CALL blacs_gridinit(context_handle, order, nprow, npcol)
76 this%context_handle = context_handle
77#else
78 mark_used(this)
79 mark_used(comm)
80 mark_used(order)
81 mark_used(nprow)
82 mark_used(npcol)
83#endif
84 CALL this%gridinfo()
85 END SUBROUTINE cp_blacs_gridinit
86
87! **************************************************************************************************
88!> \brief ...
89!> \param this ...
90! **************************************************************************************************
91 SUBROUTINE cp_blacs_gridexit(this)
92 CLASS(cp_blacs_type), INTENT(IN) :: this
93#if defined(__parallel)
94 CALL blacs_gridexit(this%context_handle)
95#else
96 mark_used(this)
97#endif
98 END SUBROUTINE cp_blacs_gridexit
99
100! **************************************************************************************************
101!> \brief ...
102!> \param this ...
103! **************************************************************************************************
104 SUBROUTINE cp_blacs_gridinfo(this)
105 CLASS(cp_blacs_type), INTENT(INOUT) :: this
106#if defined(__parallel)
107 CALL blacs_gridinfo(this%context_handle, this%num_pe(1), this%num_pe(2), this%mepos(1), this%mepos(2))
108#else
109 mark_used(this)
110 this%num_pe = 1
111 this%mepos = 0
112#endif
113 END SUBROUTINE cp_blacs_gridinfo
114
115! **************************************************************************************************
116!> \brief ...
117!> \param this ...
118!> \param what :
119!> WHAT = 0 : Handle indicating default system context; ! DO NOT USE (i.e. use para_env)
120!> WHAT = 1 : The BLACS message ID range;
121!> WHAT = 2 : The BLACS debug level the library was compiled with;
122!> WHAT = 10: Handle indicating the system context used to define the BLACS context whose handle is ICONTXT;
123!> WHAT = 11: Number of rings multiring topology is presently using;
124!> WHAT = 12: Number of branches general tree topology is presently using.
125!> WHAT = 15: If non-zero, makes topology choice for repeatable collectives
126!> \param val ...
127! **************************************************************************************************
128 SUBROUTINE cp_blacs_set(this, what, val)
129 CLASS(cp_blacs_type), INTENT(IN) :: this
130 INTEGER, INTENT(IN) :: what, val
131#if defined(__parallel)
132 CALL blacs_set(this%context_handle, what, val)
133#else
134 mark_used(this)
135 mark_used(what)
136 mark_used(val)
137#endif
138 END SUBROUTINE cp_blacs_set
139
140! **************************************************************************************************
141!> \brief ...
142!> \param this ...
143!> \param SCOPE ...
144!> \param TOP ...
145!> \param M ...
146!> \param N ...
147!> \param A ...
148!> \param LDA ...
149! **************************************************************************************************
150 SUBROUTINE cp_blacs_zgebs2d(this, SCOPE, TOP, M, N, A, LDA)
151 CLASS(cp_blacs_type), INTENT(IN) :: this
152 CHARACTER(len=1), INTENT(IN) :: SCOPE, TOP
153 INTEGER, INTENT(IN) :: M, N, LDA
154 COMPLEX(KIND=dp) :: A
155#if defined(__parallel)
156 CALL zgebs2d(this%context_handle, scope, top, m, n, a, lda)
157#else
158 mark_used(this)
159 mark_used(scope)
160 mark_used(top)
161 mark_used(m)
162 mark_used(n)
163 mark_used(a)
164 mark_used(lda)
165#endif
166 END SUBROUTINE
167! **************************************************************************************************
168!> \brief ...
169!> \param this ...
170!> \param SCOPE ...
171!> \param TOP ...
172!> \param M ...
173!> \param N ...
174!> \param A ...
175!> \param LDA ...
176!> \param RSRC ...
177!> \param CSRC ...
178! **************************************************************************************************
179 SUBROUTINE cp_blacs_zgebr2d(this, SCOPE, TOP, M, N, A, LDA, RSRC, CSRC)
180 CLASS(cp_blacs_type), INTENT(IN) :: this
181 CHARACTER(len=1), INTENT(IN) :: SCOPE, TOP
182 INTEGER, INTENT(IN) :: M, N, LDA
183 INTEGER, INTENT(IN) :: RSRC, CSRC
184 COMPLEX(KIND=dp) :: A
185#if defined(__parallel)
186 CALL zgebr2d(this%context_handle, scope, top, m, n, a, lda, rsrc, csrc)
187#else
188 mark_used(this)
189 mark_used(scope)
190 mark_used(top)
191 mark_used(m)
192 mark_used(n)
193 mark_used(a)
194 mark_used(lda)
195 mark_used(rsrc)
196 mark_used(csrc)
197#endif
198 END SUBROUTINE
199
200! **************************************************************************************************
201!> \brief ...
202!> \param this ...
203!> \param SCOPE ...
204!> \param TOP ...
205!> \param M ...
206!> \param N ...
207!> \param A ...
208!> \param LDA ...
209! **************************************************************************************************
210 SUBROUTINE cp_blacs_dgebs2d(this, SCOPE, TOP, M, N, A, LDA)
211 CLASS(cp_blacs_type), INTENT(IN) :: this
212 CHARACTER(len=1), INTENT(IN) :: SCOPE, TOP
213 INTEGER, INTENT(IN) :: M, N, LDA
214 REAL(KIND=dp) :: a
215#if defined(__parallel)
216 CALL dgebs2d(this%context_handle, scope, top, m, n, a, lda)
217#else
218 mark_used(this)
219 mark_used(scope)
220 mark_used(top)
221 mark_used(m)
222 mark_used(n)
223 mark_used(a)
224 mark_used(lda)
225#endif
226 END SUBROUTINE
227! **************************************************************************************************
228!> \brief ...
229!> \param this ...
230!> \param SCOPE ...
231!> \param TOP ...
232!> \param M ...
233!> \param N ...
234!> \param A ...
235!> \param LDA ...
236!> \param RSRC ...
237!> \param CSRC ...
238! **************************************************************************************************
239 SUBROUTINE cp_blacs_dgebr2d(this, SCOPE, TOP, M, N, A, LDA, RSRC, CSRC)
240 CLASS(cp_blacs_type), INTENT(IN) :: this
241 CHARACTER(len=1), INTENT(IN) :: scope, top
242 INTEGER, INTENT(IN) :: m, n, lda
243 INTEGER, INTENT(IN) :: rsrc, csrc
244 REAL(kind=dp) :: a
245#if defined(__parallel)
246 CALL dgebr2d(this%context_handle, scope, top, m, n, a, lda, rsrc, csrc)
247#else
248 mark_used(this)
249 mark_used(scope)
250 mark_used(top)
251 mark_used(m)
252 mark_used(n)
253 mark_used(a)
254 mark_used(lda)
255 mark_used(rsrc)
256 mark_used(csrc)
257#endif
258 END SUBROUTINE
259
260! **************************************************************************************************
261!> \brief ...
262!> \param this ...
263!> \return ...
264! **************************************************************************************************
265 ELEMENTAL INTEGER FUNCTION cp_blacs_get_handle(this)
266 CLASS(cp_blacs_type), INTENT(IN) :: this
267#if defined(__parallel)
268 cp_blacs_get_handle = this%context_handle
269#else
270 mark_used(this)
271 cp_blacs_get_handle = -1
272#endif
273 END FUNCTION
274
275! **************************************************************************************************
276!> \brief ...
277!> \param this ...
278!> \param other ...
279!> \return ...
280! **************************************************************************************************
281 ELEMENTAL LOGICAL FUNCTION cp_context_is_equal(this, other)
282 CLASS(cp_blacs_type), INTENT(IN) :: this, other
283#if defined(__parallel)
284 cp_context_is_equal = (this%context_handle == other%context_handle)
285#else
286 mark_used(this)
287 mark_used(other)
288 cp_context_is_equal = .true.
289#endif
290 END FUNCTION cp_context_is_equal
291
292! **************************************************************************************************
293!> \brief ...
294!> \param this ...
295!> \param other ...
296!> \return ...
297! **************************************************************************************************
298 ELEMENTAL LOGICAL FUNCTION cp_context_is_not_equal(this, other)
299 CLASS(cp_blacs_type), INTENT(IN) :: this, other
300#if defined(__parallel)
301 cp_context_is_not_equal = (this%context_handle /= other%context_handle)
302#else
303 mark_used(this)
304 mark_used(other)
305 cp_context_is_not_equal = .false.
306#endif
307 END FUNCTION cp_context_is_not_equal
308
309! **************************************************************************************************
310!> \brief ...
311!> \param this ...
312!> \param comm_super ...
313!> \return ...
314! **************************************************************************************************
315 TYPE(mp_comm_type) FUNCTION cp_blacs_interconnect(this, comm_super)
316 CLASS(cp_blacs_type), INTENT(IN) :: this
317 CLASS(mp_comm_type), INTENT(IN) :: comm_super
318
319 INTEGER :: blacs_coord
320
321! We enumerate the processes within the process grid in a linear fashion
322 blacs_coord = this%mepos(1)*this%num_pe(2) + this%mepos(2)
323
324 CALL cp_blacs_interconnect%from_split(comm_super, blacs_coord)
325
326 END FUNCTION cp_blacs_interconnect
327
328END MODULE cp_blacs_types
wrappers for the actual blacs calls. all functionality needed in the code should actually be provide ...
subroutine cp_blacs_gridinit(this, comm, order, nprow, npcol)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.