1
<?xml version="1.0" encoding="utf-8"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
6
<title>Literate version of PEXSI LDOS calculator</title>
7
<!-- 2015-11-05 Thu 12:35 -->
8
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
9
<meta name="generator" content="Org-mode" />
10
<meta name="author" content="Alberto Garcia" />
11
<style type="text/css">
12
<!--/*--><![CDATA[/*><!--*/
13
.title { text-align: center; }
14
.todo { font-family: monospace; color: red; }
15
.done { color: green; }
16
.tag { background-color: #eee; font-family: monospace;
17
padding: 2px; font-size: 80%; font-weight: normal; }
18
.timestamp { color: #bebebe; }
19
.timestamp-kwd { color: #5f9ea0; }
20
.right { margin-left: auto; margin-right: 0px; text-align: right; }
21
.left { margin-left: 0px; margin-right: auto; text-align: left; }
22
.center { margin-left: auto; margin-right: auto; text-align: center; }
23
.underline { text-decoration: underline; }
24
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
25
p.verse { margin-left: 3%; }
27
border: 1px solid #ccc;
28
box-shadow: 3px 3px 3px #eee;
30
font-family: monospace;
42
background-color: white;
46
border: 1px solid black;
48
pre.src:hover:before { display: inline;}
49
pre.src-sh:before { content: 'sh'; }
50
pre.src-bash:before { content: 'sh'; }
51
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
52
pre.src-R:before { content: 'R'; }
53
pre.src-perl:before { content: 'Perl'; }
54
pre.src-java:before { content: 'Java'; }
55
pre.src-sql:before { content: 'SQL'; }
57
table { border-collapse:collapse; }
58
caption.t-above { caption-side: top; }
59
caption.t-bottom { caption-side: bottom; }
60
td, th { vertical-align:top; }
61
th.right { text-align: center; }
62
th.left { text-align: center; }
63
th.center { text-align: center; }
64
td.right { text-align: right; }
65
td.left { text-align: left; }
66
td.center { text-align: center; }
67
dt { font-weight: bold; }
68
.footpara:nth-child(2) { display: inline; }
69
.footpara { display: block; }
70
.footdef { margin-bottom: 1em; }
71
.figure { padding: 1em; }
72
.figure p { text-align: center; }
75
border: 2px solid gray;
80
{ text-align: right; font-size: 70%; white-space: nowrap; }
81
textarea { overflow-x: auto; }
82
.linenr { font-size: smaller }
83
.code-highlighted { background-color: #ffff00; }
84
.org-info-js_info-navigation { border-style: none; }
85
#org-info-js_console-label
86
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
87
.org-info-js_search-highlight
88
{ background-color: #ffff00; color: #000000; font-weight: bold; }
91
<script type="text/javascript">
93
@licstart The following is the entire license notice for the
94
JavaScript code in this tag.
96
Copyright (C) 2012-2013 Free Software Foundation, Inc.
98
The JavaScript code in this tag is free software: you can
99
redistribute it and/or modify it under the terms of the GNU
100
General Public License (GNU GPL) as published by the Free Software
101
Foundation, either version 3 of the License, or (at your option)
102
any later version. The code is distributed WITHOUT ANY WARRANTY;
103
without even the implied warranty of MERCHANTABILITY or FITNESS
104
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
106
As additional permission under GNU GPL version 3 section 7, you
107
may distribute non-source (e.g., minimized or compacted) forms of
108
that code without the copy of the GNU GPL normally required by
109
section 4, provided you include this license notice and a URL
110
through which recipients can access the Corresponding Source.
113
@licend The above is the entire license notice
114
for the JavaScript code in this tag.
116
<!--/*--><![CDATA[/*><!--*/
117
function CodeHighlightOn(elem, id)
119
var target = document.getElementById(id);
121
elem.cacheClassElem = elem.className;
122
elem.cacheClassTarget = target.className;
123
target.className = "code-highlighted";
124
elem.className = "code-highlighted";
127
function CodeHighlightOff(elem, id)
129
var target = document.getElementById(id);
130
if(elem.cacheClassElem)
131
elem.className = elem.cacheClassElem;
132
if(elem.cacheClassTarget)
133
target.className = elem.cacheClassTarget;
140
<h1 class="title">Literate version of PEXSI LDOS calculator</h1>
141
<div id="table-of-contents">
142
<h2>Table of Contents</h2>
143
<div id="text-table-of-contents">
145
<li><a href="#sec-1">1. Introduction</a></li>
146
<li><a href="#sec-2">2. Parent routine with dispatch to Siesta post-processing</a></li>
147
<li><a href="#sec-3">3. PEXSI LDOS routine</a>
149
<li><a href="#sec-3-1">3.1. Main structure</a></li>
150
<li><a href="#sec-3-2">3.2. Routine header</a>
152
<li><a href="#sec-3-2-1">3.2.1. Used modules</a></li>
155
<li><a href="#sec-3-3">3.3. Routine variables</a></li>
156
<li><a href="#sec-3-4">3.4. Define communicators</a></li>
157
<li><a href="#sec-3-5">3.5. Re-distribute matrices</a></li>
158
<li><a href="#sec-3-6">3.6. Set options</a></li>
159
<li><a href="#sec-3-7">3.7. Prepare plan</a></li>
160
<li><a href="#sec-3-8">3.8. Load H and S matrices</a></li>
161
<li><a href="#sec-3-9">3.9. Factorization</a></li>
162
<li><a href="#sec-3-10">3.10. Compute the LDOS</a></li>
163
<li><a href="#sec-3-11">3.11. Copy information to Siesta side</a></li>
164
<li><a href="#sec-3-12">3.12. Clean up</a></li>
165
<li><a href="#sec-3-13">3.13. Support routines</a>
167
<li><a href="#sec-3-13-1">3.13.1. Row and column partition of npPerPole</a></li>
168
<li><a href="#sec-3-13-2">3.13.2. Error dispatcher</a></li>
180
<div id="outline-container-sec-1" class="outline-2">
181
<h2 id="sec-1"><span class="section-number-2">1</span> Introduction</h2>
182
<div class="outline-text-2" id="text-1">
184
This is a spin-polarized version of the SIESTA-PEXSI interface for the calculation of
185
the LDOS (which is a "partial" DM computed in a restricted energy window).
189
<div class="org-src-container">
191
<pre class="src src-f90"><span style="color: #a020f0;">MODULE</span> <span style="color: #0000ff;">m_pexsi_local_dos</span>
192
<span style="color: #a020f0;">private</span>
193
<span style="color: #a020f0;">public</span> :: pexsi_local_dos
195
<span style="color: #a020f0;">CONTAINS</span>
196
<<siesta-side-parent-routine>>
197
<<pexsi-ldos-routine>>
198
<span style="color: #a020f0;">end module</span> <span style="color: #0000ff;">m_pexsi_local_dos</span>
204
<div id="outline-container-sec-2" class="outline-2">
205
<h2 id="sec-2"><span class="section-number-2">2</span> Parent routine with dispatch to Siesta post-processing</h2>
206
<div class="outline-text-2" id="text-2">
208
This routine defines the energy window (<code>energy</code> and <code>broadening</code>),
209
and calls the PEXSI routine to compute the partial DM, which is then
210
passed to the <code>dhscf</code> machinery for the calculation of the
211
corresponding charge, which is just the LDOS needed. The output file
212
will have extension <code>.LDSI</code>.
215
<div class="org-src-container">
217
<pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">pexsi_local_dos</span>( )
218
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">m_energies</span>
220
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">sparse_matrices</span>
221
<span style="color: #a020f0;">USE</span> <span style="color: #0000ff;">siesta_options</span>
222
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">siesta_geom</span>
223
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">atomlist</span>, <span style="color: #a020f0;">only</span>: indxuo, indxua
224
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">atomlist</span>, <span style="color: #a020f0;">only</span>: qtot, no_u, no_l
225
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">atomlist</span>, <span style="color: #a020f0;">only</span>: iphorb
226
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">atomlist</span>, <span style="color: #a020f0;">only</span>: datm, no_s, iaorb
227
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">fdf</span>
228
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">files</span>, <span style="color: #a020f0;">only</span> : slabel
229
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">files</span>, <span style="color: #a020f0;">only</span> : filesOut_t <span style="color: #b22222;">! </span><span style="color: #b22222;">type for output file names</span>
230
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">parallel</span>, <span style="color: #a020f0;">only</span>: SIESTA_worker
231
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">m_ntm</span>
232
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">m_forces</span>, <span style="color: #a020f0;">only</span>: fa
233
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">m_spin</span>, <span style="color: #a020f0;">only</span>: nspin, qs, efs
234
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">m_dhscf</span>, <span style="color: #a020f0;">only</span>: dhscf
236
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
238
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> dummy_iscf = 1</span>
239
<span style="color: #228b22;">real</span>(dp) ::<span style="color: #a0522d;"> dummy_str(3,3), dummy_strl(3,3) </span><span style="color: #b22222;">! </span><span style="color: #b22222;">for dhscf call</span>
240
<span style="color: #228b22;">real</span>(dp) ::<span style="color: #a0522d;"> dummy_dipol(3)</span>
242
<span style="color: #228b22;">real</span>(dp) ::<span style="color: #a0522d;"> factor, g2max</span>
243
<span style="color: #228b22;">real</span>(dp) ::<span style="color: #a0522d;"> energy, broadening</span>
245
<span style="color: #228b22;">type(filesOut_t)</span> :: <span style="color: #a0522d;">filesOut </span><span style="color: #b22222;">! </span><span style="color: #b22222;">blank output file names</span>
247
energy = fdf_get(<span style="color: #8b2252;">'PEXSI.LocalDOS.Energy'</span>,0.0_dp,<span style="color: #8b2252;">"Ry"</span>)
248
broadening = fdf_get(<span style="color: #8b2252;">'PEXSI.LocalDOS.Broadening'</span>,0.01_dp,<span style="color: #8b2252;">"Ry"</span>)
250
<span style="color: #b22222;">! </span><span style="color: #b22222;">Note that we re-use Dscf, so it will be obliterated</span>
251
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">get_LDOS_SI</span>( no_u, no_l, nspin, <span style="color: #a020f0;">&</span>
252
maxnh, numh, listh, H, S, <span style="color: #a020f0;">&</span>
253
Dscf, energy, broadening)
255
<span style="color: #a020f0;">if</span> (SIESTA_worker) <span style="color: #a020f0;">then</span>
256
<span style="color: #b22222;">!</span><span style="color: #b22222;">Find the LDOS in the real space mesh</span>
257
filesOut%rho = <span style="color: #a020f0;">trim</span>(slabel) // <span style="color: #8b2252;">'.LDSI'</span>
260
<span style="color: #b22222;">! </span><span style="color: #b22222;">There is too much clutter here, because dhscf is</span>
261
<span style="color: #b22222;">! </span><span style="color: #b22222;">a "kitchen-sink" routine that does too many things</span>
263
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">dhscf</span>( nspin, no_s, iaorb, iphorb, no_l, <span style="color: #a020f0;">&</span>
264
no_u, na_u, na_s, isa, xa_last, indxua, <span style="color: #a020f0;">&</span>
265
ntm, 0, 0, 0, filesOut, <span style="color: #a020f0;">&</span>
266
maxnh, numh, listhptr, listh, Dscf, Datm, maxnh, H, <span style="color: #a020f0;">&</span>
267
Enaatm, Enascf, Uatm, Uscf, DUscf, DUext, Exc, Dxc, <span style="color: #a020f0;">&</span>
268
dummy_dipol, dummy_str, fa, dummy_strl )
269
<span style="color: #a020f0;">endif</span>
271
<span style="color: #a020f0;">END subroutine</span> <span style="color: #0000ff;">pexsi_local_dos</span>
278
<div id="outline-container-sec-3" class="outline-2">
279
<h2 id="sec-3"><span class="section-number-2">3</span> PEXSI LDOS routine</h2>
280
<div class="outline-text-2" id="text-3">
281
</div><div id="outline-container-sec-3-1" class="outline-3">
282
<h3 id="sec-3-1"><span class="section-number-3">3.1</span> Main structure</h3>
283
<div class="outline-text-3" id="text-3-1">
285
This is the main structure of the LDOS routine.
288
<div class="org-src-container">
290
<pre class="src src-f90"><<routine-header>>
291
<<routine-variables>>
292
<span style="color: #b22222;">! </span><span style="color: #b22222;">-------- for serial compilation</span>
293
<span style="color: #483d8b;">#ifndef</span> MPI
294
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">die</span>(<span style="color: #8b2252;">"PEXSI LDOS needs MPI"</span>)
295
<span style="color: #483d8b;">#else</span>
296
<<define-communicators>>
297
<<re-<span style="color: #a020f0;">distribute</span>-matrices>>
298
<<set-options>>
299
<<prepare-plan>>
300
<<load-hs-matrices>>
301
<<factorization>>
302
<<compute-ldos>>
303
<<copy-to-siesta-side>>
304
<<clean-up>>
305
<span style="color: #483d8b;">#endif</span>
307
<span style="color: #a020f0;">CONTAINS</span>
309
<<support-routines>>
311
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">get_LDOS_SI</span>
318
<div id="outline-container-sec-3-2" class="outline-3">
319
<h3 id="sec-3-2"><span class="section-number-3">3.2</span> Routine header</h3>
320
<div class="outline-text-3" id="text-3-2">
321
<div class="org-src-container">
323
<pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">get_LDOS_SI</span>( no_u, no_l, nspin_in, <span style="color: #a020f0;">&</span>
324
maxnh, numh, listh, H, S, <span style="color: #a020f0;">&</span>
325
LocalDOSDM, energy, broadening)
327
<<used-modules>>
329
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
331
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> maxnh, no_u, no_l, nspin_in</span>
332
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">target</span> ::<span style="color: #a0522d;"> listh(maxnh), numh(no_l)</span>
333
<span style="color: #228b22;">real</span>(dp), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">target</span> ::<span style="color: #a0522d;"> H(maxnh,nspin_in), S(maxnh)</span>
334
<span style="color: #228b22;">real</span>(dp), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> energy, broadening</span>
335
<span style="color: #228b22;">real</span>(dp), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> LocalDOSDM(maxnh,nspin_in)</span>
340
<div id="outline-container-sec-3-2-1" class="outline-4">
341
<h4 id="sec-3-2-1"><span class="section-number-4">3.2.1</span> Used modules</h4>
342
<div class="outline-text-4" id="text-3-2-1">
343
<div class="org-src-container">
345
<pre class="src src-f90"> <span style="color: #a020f0;">use</span> <span style="color: #0000ff;">precision</span>, <span style="color: #a020f0;">only</span> : dp
346
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">fdf</span>
347
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">units</span>, <span style="color: #a020f0;">only</span>: eV, pi
348
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">sys</span>, <span style="color: #a020f0;">only</span>: die
349
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">m_mpi_utils</span>, <span style="color: #a020f0;">only</span>: broadcast
350
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">parallel</span>, <span style="color: #a020f0;">only</span> : SIESTA_worker, BlockSize
351
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">parallel</span>, <span style="color: #a020f0;">only</span> : SIESTA_Group, SIESTA_Comm
352
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">m_redist_spmatrix</span>, <span style="color: #a020f0;">only</span>: aux_matrix, redistribute_spmatrix
353
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">class_Distribution</span>
354
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">alloc</span>, <span style="color: #a020f0;">only</span>: re_alloc, de_alloc
355
<span style="color: #483d8b;">#ifdef</span> MPI
356
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">mpi_siesta</span>
357
<span style="color: #483d8b;">#endif</span>
358
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">iso_c_binding</span>
359
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">f_ppexsi_interface</span>, <span style="color: #a020f0;">only</span>: f_ppexsi_options
360
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">f_ppexsi_interface</span>, <span style="color: #a020f0;">only</span>: f_ppexsi_plan_finalize
361
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">f_ppexsi_interface</span>, <span style="color: #a020f0;">only</span>: f_ppexsi_plan_initialize
362
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">f_ppexsi_interface</span>, <span style="color: #a020f0;">only</span>: f_ppexsi_selinv_complex_symmetric_matrix
363
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">f_ppexsi_interface</span>, <span style="color: #a020f0;">only</span>: f_ppexsi_load_real_symmetric_hs_matrix
364
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">f_ppexsi_interface</span>, <span style="color: #a020f0;">only</span>: f_ppexsi_set_default_options
365
<span style="color: #a020f0;">use</span> <span style="color: #0000ff;">f_ppexsi_interface</span>, <span style="color: #a020f0;">&</span>
366
<span style="color: #a020f0;">only</span>: f_ppexsi_symbolic_factorize_complex_symmetric_matrix
373
<div id="outline-container-sec-3-3" class="outline-3">
374
<h3 id="sec-3-3"><span class="section-number-3">3.3</span> Routine variables</h3>
375
<div class="outline-text-3" id="text-3-3">
377
The local variables for the routine must be declared in a certain
378
place for the compiler, but it is more clear to introduce them as they
379
are needed. The <code>routine-variables</code> noweb-ref will be used for this
380
throughout this document.
383
<div class="org-src-container">
385
<pre class="src src-f90"><span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> ih, i</span>
386
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> info</span>
387
<span style="color: #228b22;">logical</span> ::<span style="color: #a0522d;"> write_ok</span>
388
<span style="color: #b22222;">!</span><span style="color: #b22222;">------------</span>
389
<span style="color: #a020f0;">external</span> :: timer
395
<div id="outline-container-sec-3-4" class="outline-3">
396
<h3 id="sec-3-4"><span class="section-number-3">3.4</span> Define communicators</h3>
397
<div class="outline-text-3" id="text-3-4">
399
<code>World_Comm</code>, which is in principle set to Siesta's copy of
400
<code>MPI_Comm_World</code>, is the global communicator.
403
<div class="org-src-container">
405
<pre class="src src-f90"><span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> World_Comm, mpirank, ierr</span>
406
<span style="color: #b22222;">!</span>
407
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> norbs</span>
408
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> nspin</span>
412
<div class="org-src-container">
414
<pre class="src src-f90"><span style="color: #b22222;">!</span>
415
<span style="color: #b22222;">! </span><span style="color: #b22222;">Our global communicator is a duplicate of the passed communicator</span>
416
<span style="color: #b22222;">!</span>
417
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Dup</span>(true_MPI_Comm_World, World_Comm, ierr)
418
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">mpi_comm_rank</span>( World_Comm, mpirank, ierr )
420
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"pexsi-ldos"</span>, 1)
422
<span style="color: #a020f0;">if</span> (SIESTA_worker) <span style="color: #a020f0;">then</span>
423
<span style="color: #b22222;">! </span><span style="color: #b22222;">rename some intent(in) variables, which are only</span>
424
<span style="color: #b22222;">! </span><span style="color: #b22222;">defined for the Siesta subset</span>
427
<span style="color: #a020f0;">endif</span>
428
<span style="color: #b22222;">!</span>
429
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">broadcast</span>(norbs,comm=World_Comm)
430
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">broadcast</span>(nspin,World_Comm)
435
Now we need to define the Siesta distribution object and the
436
communicator and distribution object for the first team of PEXSI
437
workers, for the purposes of re-distribution of the relevant
442
For spin, things are a bit more complicated. We need to make sure that
443
the distributions are defined and known to all processors (via actual
444
ranks) with respect to the same reference bridge communicator. For
445
now, this is World<sub>Comm</sub>.
448
<div class="org-src-container">
450
<pre class="src src-f90"><span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> PEXSI_Pole_Group, PEXSI_Spatial_Group, World_Group</span>
451
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">allocatable</span> ::<span style="color: #a0522d;"> pexsi_pole_ranks_in_world(:)</span>
452
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> nworkers_SIESTA</span>
453
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">allocatable</span> ::<span style="color: #a0522d;"> siesta_ranks_in_world(:)</span>
454
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> PEXSI_Pole_Group_in_World</span>
455
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">allocatable</span> ::<span style="color: #a0522d;"> PEXSI_Pole_ranks_in_World_Spin(:,:)</span>
456
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> PEXSI_Pole_Comm, PEXSI_Spatial_Comm, PEXSI_Spin_Comm</span>
457
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> numNodesTotal</span>
458
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> npPerPole</span>
459
<span style="color: #228b22;">logical</span> ::<span style="color: #a0522d;"> PEXSI_worker</span>
460
<span style="color: #b22222;">!</span>
461
<span style="color: #228b22;">type(Distribution)</span> :: <span style="color: #a0522d;">dist1</span>
462
<span style="color: #228b22;">type(Distribution)</span>, <span style="color: #a020f0;">allocatable</span>, <span style="color: #a020f0;">target</span> :: <span style="color: #a0522d;">dist2_spin(:)</span>
463
<span style="color: #228b22;">type(Distribution)</span>, <span style="color: #a020f0;">pointer</span> :: <span style="color: #a0522d;">dist2</span>
464
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> pbs, color, spatial_rank, spin_rank</span>
469
Define the Siesta distribution. Note that this is known to all nodes.
472
<div class="org-src-container">
474
<pre class="src src-f90"><span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Group</span>(World_Comm,World_Group, ierr)
475
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Group_Size</span>(SIESTA_Group, nworkers_SIESTA, ierr)
476
<span style="color: #a020f0;">allocate</span>(siesta_ranks_in_world(nworkers_SIESTA))
477
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Group_translate_ranks</span>( SIESTA_Group, nworkers_SIESTA, <span style="color: #a020f0;">&</span>
478
(/ (i,i=0,nworkers_SIESTA-1) /), <span style="color: #a020f0;">&</span>
479
World_Group, siesta_ranks_in_world, ierr )
480
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">newDistribution</span>(dist1,World_Comm,siesta_ranks_in_world, <span style="color: #a020f0;">&</span>
481
TYPE_BLOCK_CYCLIC,BlockSize,<span style="color: #8b2252;">"bc dist"</span>)
482
<span style="color: #a020f0;">deallocate</span>(siesta_ranks_in_world)
483
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Barrier</span>(World_Comm,ierr)
488
For possibly spin-polarized calculations, we split the communicator.
489
Note that we give the user the option of requesting more processors
490
per pole for the LDOS calculation.
493
<div class="org-src-container">
495
<pre class="src src-f90"><span style="color: #a020f0;">call</span> <span style="color: #0000ff;">mpi_comm_size</span>( World_Comm, numNodesTotal, ierr )
497
npPerPole = fdf_get(<span style="color: #8b2252;">"PEXSI.np-per-pole"</span>,4)
498
npPerPole = fdf_get(<span style="color: #8b2252;">"PEXSI.LocalDOS.np-per-pole"</span>,npPerPole)
499
<span style="color: #a020f0;">if</span> (nspin*npPerPole > numNodesTotal) <span style="color: #a020f0;">&</span>
500
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">die</span>(<span style="color: #8b2252;">"PEXSI.np-per-pole is too big for MPI size"</span>)
502
<span style="color: #b22222;">! </span><span style="color: #b22222;">"Row" communicator for independent PEXSI operations on each spin</span>
503
<span style="color: #b22222;">! </span><span style="color: #b22222;">The name refers to "spatial" degrees of freedom.</span>
504
color = <span style="color: #a020f0;">mod</span>(mpirank,nspin) <span style="color: #b22222;">! </span><span style="color: #b22222;">{0,1} for nspin = 2, or {0} for nspin = 1</span>
505
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Split</span>(World_Comm, color, mpirank, PEXSI_Spatial_Comm, ierr)
507
<span style="color: #b22222;">! </span><span style="color: #b22222;">"Column" communicator for spin reductions</span>
508
color = mpirank/nspin
509
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Split</span>(World_Comm, color, mpirank, PEXSI_Spin_Comm, ierr)
511
<span style="color: #b22222;">! </span><span style="color: #b22222;">Group and Communicator for first-pole team of PEXSI workers</span>
512
<span style="color: #b22222;">!</span>
513
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Group</span>(PEXSI_Spatial_Comm, PEXSI_Spatial_Group, Ierr)
514
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Group_incl</span>(PEXSI_Spatial_Group, npPerPole, <span style="color: #a020f0;">&</span>
515
(/ (i,i=0,npPerPole-1) /),<span style="color: #a020f0;">&</span>
516
PEXSI_Pole_Group, Ierr)
517
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_create</span>(PEXSI_Spatial_Comm, PEXSI_Pole_Group,<span style="color: #a020f0;">&</span>
518
PEXSI_Pole_Comm, Ierr)
521
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">mpi_comm_rank</span>( PEXSI_Spatial_Comm, spatial_rank, ierr )
522
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">mpi_comm_rank</span>( PEXSI_Spin_Comm, spin_rank, ierr )
523
PEXSI_worker = (spatial_rank < npPerPole) <span style="color: #b22222;">! </span><span style="color: #b22222;">Could be spin up or spin down</span>
525
<span style="color: #b22222;">! </span><span style="color: #b22222;">PEXSI blocksize </span>
526
pbs = norbs/npPerPole
528
<span style="color: #b22222;">! </span><span style="color: #b22222;">Careful with this. For the purposes of matrix transfers,</span>
529
<span style="color: #b22222;">! </span><span style="color: #b22222;">we need the ranks of the Pole group</span>
530
<span style="color: #b22222;">! </span><span style="color: #b22222;">in the "bridge" communicator/group (World)</span>
532
<span style="color: #a020f0;">allocate</span>(pexsi_pole_ranks_in_world(npPerPole))
533
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Group</span>(World_Comm, World_Group, Ierr)
535
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Group_translate_ranks</span>( PEXSI_Pole_Group, npPerPole, <span style="color: #a020f0;">&</span>
536
(/ (i,i=0,npPerPole-1) /), <span style="color: #a020f0;">&</span>
537
World_Group, pexsi_pole_ranks_in_world, ierr )
539
<span style="color: #b22222;">! </span><span style="color: #b22222;">What we need is to include the actual world ranks</span>
540
<span style="color: #b22222;">! </span><span style="color: #b22222;">in the distribution object</span>
541
<span style="color: #a020f0;">allocate</span> (PEXSI_Pole_ranks_in_World_Spin(npPerPole,nspin))
542
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_AllGather</span>(pexsi_pole_ranks_in_world,npPerPole,MPI_integer,<span style="color: #a020f0;">&</span>
543
PEXSI_Pole_Ranks_in_World_Spin,npPerPole, <span style="color: #a020f0;">&</span>
544
MPI_integer,PEXSI_Spin_Comm,ierr)
546
<span style="color: #b22222;">! </span><span style="color: #b22222;">Create distributions known to all nodes</span>
547
<span style="color: #a020f0;">allocate</span>(dist2_spin(nspin))
548
<span style="color: #a020f0;">do</span> ispin = 1, nspin
549
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">newDistribution</span>(dist2_spin(ispin), World_Comm, <span style="color: #a020f0;">&</span>
550
PEXSI_Pole_Ranks_in_World_Spin(:,ispin), <span style="color: #a020f0;">&</span>
551
TYPE_PEXSI, pbs, <span style="color: #8b2252;">"px dist"</span>)
552
<span style="color: #a020f0;">enddo</span>
553
<span style="color: #a020f0;">deallocate</span>(pexsi_pole_ranks_in_world,PEXSI_Pole_Ranks_in_World_Spin)
554
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Barrier</span>(World_Comm,ierr)
560
<div id="outline-container-sec-3-5" class="outline-3">
561
<h3 id="sec-3-5"><span class="section-number-3">3.5</span> Re-distribute matrices</h3>
562
<div class="outline-text-3" id="text-3-5">
564
This is slightly unseemly, but it works. The <code>aux_matrix</code> derived
565
types are used to store and retrieve the matrices in either side. The
566
code is in external auxiliary modules.
569
<div class="org-src-container">
571
<pre class="src src-f90"><span style="color: #228b22;">type(aux_matrix)</span>, <span style="color: #a020f0;">allocatable</span>, <span style="color: #a020f0;">target</span> :: <span style="color: #a0522d;">m1_spin(:)</span>
572
<span style="color: #228b22;">type(aux_matrix)</span> :: <span style="color: #a0522d;">m2</span>
573
<span style="color: #228b22;">type(aux_matrix)</span>, <span style="color: #a020f0;">pointer</span> :: <span style="color: #a0522d;">m1</span>
574
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> nrows, nnz, nnzLocal, numColLocal</span>
575
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">pointer</span>, <span style="color: #a020f0;">dimension</span>(:) ::<span style="color: #a0522d;"> colptrLocal=> null(), rowindLocal=>null()</span>
576
<span style="color: #b22222;">!</span>
577
<span style="color: #228b22;">real</span>(dp), <span style="color: #a020f0;">pointer</span>, <span style="color: #a020f0;">dimension</span>(:) ::<span style="color: #a0522d;"> </span><span style="color: #a020f0;">&</span>
578
HnzvalLocal=>null(), SnzvalLocal=>null(), <span style="color: #a020f0;">&</span>
579
DMnzvalLocal => <span style="color: #a020f0;">null</span>()
580
<span style="color: #b22222;">!</span>
581
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> ispin, pexsi_spin</span>
584
<div class="org-src-container">
586
<pre class="src src-f90">pexsi_spin = spin_rank+1 <span style="color: #b22222;">! </span><span style="color: #b22222;">{1,2}</span>
587
<span style="color: #b22222;">! </span><span style="color: #b22222;">This is done serially on the Siesta side, each time</span>
588
<span style="color: #b22222;">! </span><span style="color: #b22222;">filling in the structures in one PEXSI set</span>
590
<span style="color: #a020f0;">allocate</span>(m1_spin(nspin))
591
<span style="color: #a020f0;">do</span> ispin = 1, nspin
593
m1 => m1_spin(ispin)
595
<span style="color: #a020f0;">if</span> (SIESTA_worker) <span style="color: #a020f0;">then</span>
598
m1%nnzl = <span style="color: #a020f0;">sum</span>(numH(1:no_l))
599
m1%numcols => numH
601
<span style="color: #a020f0;">allocate</span>(m1%vals(2))
602
m1%vals(1)%data => S(:)
603
m1%vals(2)%data => H(:,ispin)
605
<span style="color: #a020f0;">endif</span> <span style="color: #b22222;">! </span><span style="color: #b22222;">SIESTA_worker</span>
607
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"redist_orbs_fwd"</span>, 1)
609
<span style="color: #b22222;">! </span><span style="color: #b22222;">Note that we cannot simply wrap this in a pexsi_spin test, as</span>
610
<span style="color: #b22222;">! </span><span style="color: #b22222;">there are Siesta nodes in both spin sets.</span>
611
<span style="color: #b22222;">! </span><span style="color: #b22222;">We must discriminate the PEXSI workers by the distribution info</span>
612
dist2 => dist2_spin(ispin)
613
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">redistribute_spmatrix</span>(norbs,m1,dist1,m2,dist2,World_Comm)
615
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"redist_orbs_fwd"</span>, 2)
617
<span style="color: #a020f0;">if</span> (PEXSI_worker <span style="color: #a020f0;">.and.</span> (pexsi_spin == ispin) ) <span style="color: #a020f0;">then</span>
619
nrows = m2%norbs <span style="color: #b22222;">! </span><span style="color: #b22222;">or simply 'norbs'</span>
620
numColLocal = m2%no_l
622
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_AllReduce</span>(nnzLocal,nnz,1,MPI_integer,MPI_sum,PEXSI_Pole_Comm,ierr)
624
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">re_alloc</span>(colptrLocal,1,numColLocal+1,<span style="color: #8b2252;">"colptrLocal"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
626
<span style="color: #a020f0;">do</span> ih = 1,numColLocal
627
colptrLocal(ih+1) = colptrLocal(ih) + m2%numcols(ih)
628
<span style="color: #a020f0;">enddo</span>
630
rowindLocal => m2%cols
631
SnzvalLocal => m2%vals(1)%data
632
HnzvalLocal => m2%vals(2)%data
634
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">re_alloc</span>(DMnzvalLocal,1,nnzLocal,<span style="color: #8b2252;">"DMnzvalLocal"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
636
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">memory_all</span>(<span style="color: #8b2252;">"after setting up H+S for PEXSI (PEXSI_workers)"</span>,PEXSI_Pole_Comm)
638
<span style="color: #a020f0;">endif</span> <span style="color: #b22222;">! </span><span style="color: #b22222;">PEXSI worker</span>
639
<span style="color: #a020f0;">enddo</span>
641
<span style="color: #b22222;">! </span><span style="color: #b22222;">Make these available to all</span>
642
<span style="color: #b22222;">! </span><span style="color: #b22222;">(Note that the values are those on process 0, which is in the spin=1 set</span>
643
<span style="color: #b22222;">! </span><span style="color: #b22222;">In fact, they are only needed for calls to the interface, so the broadcast</span>
644
<span style="color: #b22222;">! </span><span style="color: #b22222;">could be over PEXSI_Spatial_Comm only.</span>
646
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Bcast</span>(nrows,1,MPI_integer,0,World_Comm,ierr)
647
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Bcast</span>(nnz,1,MPI_integer,0,World_Comm,ierr)
649
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">memory_all</span>(<span style="color: #8b2252;">"after setting up H+S for PEXSI"</span>,World_comm)
655
<div id="outline-container-sec-3-6" class="outline-3">
656
<h3 id="sec-3-6"><span class="section-number-3">3.6</span> Set options</h3>
657
<div class="outline-text-3" id="text-3-6">
659
We use the options interface to get a template with default values,
660
and then fill in a few custom options based on fdf variables.
663
<div class="org-src-container">
665
<pre class="src src-f90"><span style="color: #228b22;">type(f_ppexsi_options)</span> :: <span style="color: #a0522d;">options</span>
666
<span style="color: #b22222;">!</span>
667
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> isSIdentity</span>
668
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> verbosity</span>
672
<div class="org-src-container">
674
<pre class="src src-f90"><span style="color: #b22222;">! </span><span style="color: #b22222;">-- </span>
676
<span style="color: #b22222;">!</span>
677
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">f_ppexsi_set_default_options</span>( options )
678
<span style="color: #b22222;">! </span><span style="color: #b22222;">Ordering flag:</span>
679
<span style="color: #b22222;">! </span><span style="color: #b22222;">1: Use METIS</span>
680
<span style="color: #b22222;">! </span><span style="color: #b22222;">0: Use PARMETIS/PTSCOTCH</span>
681
options%ordering = fdf_get(<span style="color: #8b2252;">"PEXSI.ordering"</span>,1)
682
<span style="color: #b22222;">! </span><span style="color: #b22222;">Number of processors for symbolic factorization</span>
683
<span style="color: #b22222;">! </span><span style="color: #b22222;">Only relevant for PARMETIS/PT_SCOTCH</span>
684
options%npSymbFact = fdf_get(<span style="color: #8b2252;">"PEXSI.np-symbfact"</span>,1)
685
options%verbosity = fdf_get(<span style="color: #8b2252;">"PEXSI.verbosity"</span>,1)
691
<div id="outline-container-sec-3-7" class="outline-3">
692
<h3 id="sec-3-7"><span class="section-number-3">3.7</span> Prepare plan</h3>
693
<div class="outline-text-3" id="text-3-7">
695
Each spin-set of PEXSI processors has its own plan, but we only
696
include the first-pole group of nodes…
698
<div class="org-src-container">
700
<pre class="src src-f90"><span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_intptr_t</span>) ::<span style="color: #a0522d;"> plan</span>
701
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> numProcRow, numProcCol</span>
702
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> outputFileIndex</span>
706
<div class="org-src-container">
708
<pre class="src src-f90"> <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">get_row_col</span>(npPerPole,numProcRow,numProcCol)
710
<span style="color: #b22222;">! </span><span style="color: #b22222;">Set the outputFileIndex to be the pole index.</span>
711
<span style="color: #b22222;">! </span><span style="color: #b22222;">Starting from PEXSI v0.8.0, the first processor for each pole outputs</span>
712
<span style="color: #b22222;">! </span><span style="color: #b22222;">information</span>
714
<span style="color: #a020f0;">if</span>( <span style="color: #a020f0;">mod</span>( mpirank, npPerPole ) <span style="color: #a020f0;">.eq.</span> 0 ) <span style="color: #a020f0;">then</span>
715
outputFileIndex = mpirank / npPerPole;
716
<span style="color: #a020f0;">else</span>
717
outputFileIndex = -1;
718
<span style="color: #a020f0;">endif</span>
719
<span style="color: #b22222;">!</span>
720
<span style="color: #b22222;">! </span><span style="color: #b22222;">Note that we only use one pole's worth of processors in</span>
721
<span style="color: #b22222;">! </span><span style="color: #b22222;">the global PEXSI communicator</span>
722
<span style="color: #b22222;">!</span>
723
plan = f_ppexsi_plan_initialize(<span style="color: #a020f0;">&</span>
724
PEXSI_Pole_Comm,<span style="color: #a020f0;">&</span>
725
numProcRow,<span style="color: #a020f0;">&</span>
726
numProcCol,<span style="color: #a020f0;">&</span>
727
outputFileIndex,<span style="color: #a020f0;">&</span>
730
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">check_info</span>(info,<span style="color: #8b2252;">"plan_initialize in LDOS"</span>)
736
<div id="outline-container-sec-3-8" class="outline-3">
737
<h3 id="sec-3-8"><span class="section-number-3">3.8</span> Load H and S matrices</h3>
738
<div class="outline-text-3" id="text-3-8">
740
In this version H and S are symmetric. We associate them with the plan
741
(I really do not know very well what happens behind the
742
scenes. Presumably no copy is made.)
745
<div class="org-src-container">
747
<pre class="src src-f90"><span style="color: #a020f0;">call</span> <span style="color: #0000ff;">f_ppexsi_load_real_symmetric_hs_matrix</span>(<span style="color: #a020f0;">&</span>
748
plan,<span style="color: #a020f0;">&</span>
749
options,<span style="color: #a020f0;">&</span>
750
nrows,<span style="color: #a020f0;">&</span>
751
nnz,<span style="color: #a020f0;">&</span>
752
nnzLocal,<span style="color: #a020f0;">&</span>
753
numColLocal,<span style="color: #a020f0;">&</span>
754
colptrLocal,<span style="color: #a020f0;">&</span>
755
rowindLocal,<span style="color: #a020f0;">&</span>
756
HnzvalLocal,<span style="color: #a020f0;">&</span>
757
isSIdentity,<span style="color: #a020f0;">&</span>
758
SnzvalLocal,<span style="color: #a020f0;">&</span>
761
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">check_info</span>(info,<span style="color: #8b2252;">"load_real_sym_hs_matrix in LDOS"</span>)
767
<div id="outline-container-sec-3-9" class="outline-3">
768
<h3 id="sec-3-9"><span class="section-number-3">3.9</span> Factorization</h3>
769
<div class="outline-text-3" id="text-3-9">
771
This is a bit ambiguous, as we have loaded a "symmetric" matrix
772
(actually H and S), but I believe that inside (and in the plan)
773
specifically complex structures are handled and filled in.
776
<div class="org-src-container">
778
<pre class="src src-f90"> <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">f_ppexsi_symbolic_factorize_complex_symmetric_matrix</span>(<span style="color: #a020f0;">&</span>
779
plan, <span style="color: #a020f0;">&</span>
780
options,<span style="color: #a020f0;">&</span>
782
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">check_info</span>(info,<span style="color: #8b2252;">"factorize complex matrix in LDOS"</span>)
784
options%isSymbolicFactorize = 0 <span style="color: #b22222;">! </span><span style="color: #b22222;">We do not need it anymore</span>
790
<div id="outline-container-sec-3-10" class="outline-3">
791
<h3 id="sec-3-10"><span class="section-number-3">3.10</span> Compute the LDOS</h3>
792
<div class="outline-text-3" id="text-3-10">
793
<div class="org-src-container">
795
<pre class="src src-f90"><span style="color: #228b22;">real</span>(dp), <span style="color: #a020f0;">pointer</span>, <span style="color: #a020f0;">dimension</span>(:) ::<span style="color: #a0522d;"> AnzvalLocal => null()</span>
796
<span style="color: #228b22;">real</span>(dp), <span style="color: #a020f0;">pointer</span>, <span style="color: #a020f0;">dimension</span>(:) ::<span style="color: #a0522d;"> AinvnzvalLocal => null()</span>
797
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> loc</span>
802
Note that only the first-pole team does this.
805
<div class="org-src-container">
807
<pre class="src src-f90"><span style="color: #a020f0;">if</span> (PEXSI_worker) <span style="color: #a020f0;">then</span>
809
<span style="color: #a020f0;">if</span>(mpirank == 0) <span style="color: #a020f0;">then</span>
810
<span style="color: #a020f0;">write</span>(6,<span style="color: #8b2252;">"(a,f16.5,f10.5)"</span>) <span style="color: #a020f0;">&</span>
811
<span style="color: #8b2252;">'Calling PEXSI LDOS routine. Energy and broadening (eV) '</span>, <span style="color: #a020f0;">&</span>
812
energy/eV, broadening/eV
813
<span style="color: #a020f0;">write</span>(6,<span style="color: #8b2252;">"(a,i4)"</span>) <span style="color: #a020f0;">&</span>
814
<span style="color: #8b2252;">'Processors working on selected inversion: '</span>, npPerPole
815
<span style="color: #a020f0;">endif</span>
817
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"pexsi-ldos-selinv"</span>, 1)
819
<span style="color: #b22222;">! </span><span style="color: #b22222;">Build AnzvalLocal as H-zS, where z=(E,broadening), and treat</span>
820
<span style="color: #b22222;">! </span><span style="color: #b22222;">it as a one-dimensional real array with 2*nnzlocal entries</span>
822
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">re_alloc</span>(AnzvalLocal,1,2*nnzLocal,<span style="color: #8b2252;">"AnzvalLocal"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
823
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">re_alloc</span>(AinvnzvalLocal,1,2*nnzLocal,<span style="color: #8b2252;">"AinvnzvalLocal"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
826
<span style="color: #a020f0;">do</span> i = 1, nnzLocal
827
AnzvalLocal(loc) = Hnzvallocal(i) - energy*Snzvallocal(i)
828
AnzvalLocal(loc+1) = - broadening*Snzvallocal(i)
830
<span style="color: #a020f0;">enddo</span>
832
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">f_ppexsi_selinv_complex_symmetric_matrix</span>(<span style="color: #a020f0;">&</span>
833
plan,<span style="color: #a020f0;">&</span>
834
options,<span style="color: #a020f0;">&</span>
835
AnzvalLocal,<span style="color: #a020f0;">&</span>
836
AinvnzvalLocal,<span style="color: #a020f0;">&</span>
839
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">check_info</span>(info,<span style="color: #8b2252;">"selinv complex matrix in LDOS"</span>)
841
<span style="color: #b22222;">! </span><span style="color: #b22222;">Get DMnzvalLocal as 1/pi * Imag(Ainv...)</span>
844
<span style="color: #a020f0;">do</span> i = 1, nnzLocal
845
DMnzvalLocal(i) = (1.0_dp/pi) * AinvnzvalLocal(loc+1)
847
<span style="color: #a020f0;">enddo</span>
848
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(AnzvalLocal,<span style="color: #8b2252;">"AnzvalLocal"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
849
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(AinvnzvalLocal,<span style="color: #8b2252;">"AinvnzvalLocal"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
851
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"pexsi-ldos-selinv"</span>, 2)
852
<span style="color: #b22222;">!</span>
853
<span style="color: #a020f0;">endif</span> <span style="color: #b22222;">! </span><span style="color: #b22222;">PEXSI_worker</span>
859
<div id="outline-container-sec-3-11" class="outline-3">
860
<h3 id="sec-3-11"><span class="section-number-3">3.11</span> Copy information to Siesta side</h3>
861
<div class="outline-text-3" id="text-3-11">
862
<div class="org-src-container">
864
<pre class="src src-f90"><span style="color: #a020f0;">do</span> ispin = 1, nspin
866
m1 => m1_spin(ispin)
868
<span style="color: #a020f0;">if</span> (PEXSI_worker <span style="color: #a020f0;">.and.</span> (pexsi_spin == ispin)) <span style="color: #a020f0;">then</span>
869
<span style="color: #b22222;">! </span><span style="color: #b22222;">Prepare m2 to transfer</span>
871
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(colPtrLocal,<span style="color: #8b2252;">"colPtrLocal"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
873
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(m2%vals(1)%data,<span style="color: #8b2252;">"m2%vals(1)%data"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
874
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(m2%vals(2)%data,<span style="color: #8b2252;">"m2%vals(2)%data"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
876
<span style="color: #a020f0;">deallocate</span>(m2%vals)
877
<span style="color: #a020f0;">allocate</span>(m2%vals(1))
878
m2%vals(1)%data => DMnzvalLocal(1:nnzLocal)
880
<span style="color: #a020f0;">endif</span>
882
<span style="color: #b22222;">! </span><span style="color: #b22222;">Prepare m1 to receive the results</span>
883
<span style="color: #a020f0;">if</span> (SIESTA_worker) <span style="color: #a020f0;">then</span>
884
<span style="color: #a020f0;">nullify</span>(m1%vals(1)%data) <span style="color: #b22222;">! </span><span style="color: #b22222;">formerly pointing to S</span>
885
<span style="color: #a020f0;">nullify</span>(m1%vals(2)%data) <span style="color: #b22222;">! </span><span style="color: #b22222;">formerly pointing to H</span>
886
<span style="color: #a020f0;">deallocate</span>(m1%vals)
887
<span style="color: #a020f0;">nullify</span>(m1%numcols) <span style="color: #b22222;">! </span><span style="color: #b22222;">formerly pointing to numH</span>
888
<span style="color: #a020f0;">nullify</span>(m1%cols) <span style="color: #b22222;">! </span><span style="color: #b22222;">formerly pointing to listH</span>
889
<span style="color: #a020f0;">endif</span>
891
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"redist_orbs_bck"</span>, 1)
892
dist2 => dist2_spin(ispin)
893
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">redistribute_spmatrix</span>(norbs,m2,dist2,m1,dist1,World_Comm)
894
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"redist_orbs_bck"</span>, 2)
896
<span style="color: #a020f0;">if</span> (PEXSI_worker <span style="color: #a020f0;">.and.</span> (pexsi_spin == ispin)) <span style="color: #a020f0;">then</span>
897
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(DMnzvalLocal, <span style="color: #8b2252;">"DMnzvalLocal"</span>, <span style="color: #8b2252;">"pexsi_ldos"</span>)
899
<span style="color: #a020f0;">nullify</span>(m2%vals(1)%data) <span style="color: #b22222;">! </span><span style="color: #b22222;">formerly pointing to DM</span>
900
<span style="color: #a020f0;">deallocate</span>(m2%vals)
901
<span style="color: #b22222;">! </span><span style="color: #b22222;">allocated in the direct transfer</span>
902
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(m2%numcols,<span style="color: #8b2252;">"m2%numcols"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
903
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(m2%cols, <span style="color: #8b2252;">"m2%cols"</span>, <span style="color: #8b2252;">"pexsi_ldos"</span>)
904
<span style="color: #a020f0;">endif</span>
906
<span style="color: #a020f0;">if</span> (SIESTA_worker) <span style="color: #a020f0;">then</span>
908
LocalDOSDM(:,ispin) = m1%vals(1)%data(:)
909
<span style="color: #b22222;">! </span><span style="color: #b22222;">Check no_l</span>
910
<span style="color: #a020f0;">if</span> (no_l /= m1%no_l) <span style="color: #a020f0;">then</span>
911
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">die</span>(<span style="color: #8b2252;">"Mismatch in no_l"</span>)
912
<span style="color: #a020f0;">endif</span>
913
<span style="color: #b22222;">! </span><span style="color: #b22222;">Check listH</span>
914
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">any</span>(listH(:) /= m1%cols(:))) <span style="color: #a020f0;">then</span>
915
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">die</span>(<span style="color: #8b2252;">"Mismatch in listH"</span>)
916
<span style="color: #a020f0;">endif</span>
918
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(m1%vals(1)%data,<span style="color: #8b2252;">"m1%vals(1)%data"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
919
<span style="color: #a020f0;">deallocate</span>(m1%vals)
920
<span style="color: #b22222;">! </span><span style="color: #b22222;">allocated in the direct transfer</span>
921
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(m1%numcols,<span style="color: #8b2252;">"m1%numcols"</span>,<span style="color: #8b2252;">"pexsi_ldos"</span>)
922
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">de_alloc</span>(m1%cols, <span style="color: #8b2252;">"m1%cols"</span>, <span style="color: #8b2252;">"pexsi_ldos"</span>)
924
<span style="color: #a020f0;">endif</span>
925
<span style="color: #a020f0;">enddo</span>
926
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"pexsi-ldos"</span>, 2)
932
<div id="outline-container-sec-3-12" class="outline-3">
933
<h3 id="sec-3-12"><span class="section-number-3">3.12</span> Clean up</h3>
934
<div class="outline-text-3" id="text-3-12">
935
<div class="org-src-container">
937
<pre class="src src-f90"><span style="color: #a020f0;">call</span> <span style="color: #0000ff;">delete</span>(dist1)
938
<span style="color: #a020f0;">do</span> ispin = 1, nspin
939
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">delete</span>(dist2_spin(ispin))
940
<span style="color: #a020f0;">enddo</span>
941
<span style="color: #a020f0;">deallocate</span>(dist2_spin)
942
<span style="color: #a020f0;">deallocate</span>(m1_spin)
944
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Free</span>(PEXSI_Spatial_Comm, ierr)
945
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Free</span>(PEXSI_Spin_Comm, ierr)
946
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Free</span>(World_Comm, ierr)
948
<span style="color: #b22222;">! </span><span style="color: #b22222;">This communicator was created from a subgroup.</span>
949
<span style="color: #b22222;">! </span><span style="color: #b22222;">As such, it is MPI_COMM_NULL for those processes</span>
950
<span style="color: #b22222;">! </span><span style="color: #b22222;">not in the subgroup (non PEXSI_workers). Only</span>
951
<span style="color: #b22222;">! </span><span style="color: #b22222;">defined communicators can be freed</span>
952
<span style="color: #b22222;">! </span><span style="color: #b22222;">Also, we finalize the plan here</span>
953
<span style="color: #a020f0;">if</span> (PEXSI_worker) <span style="color: #a020f0;">then</span>
954
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">f_ppexsi_plan_finalize</span>( plan, info )
955
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Comm_Free</span>(PEXSI_Pole_Comm, ierr)
956
<span style="color: #a020f0;">endif</span>
958
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Group_Free</span>(PEXSI_Spatial_Group, ierr)
959
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Group_Free</span>(PEXSI_Pole_Group, ierr)
960
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Group_Free</span>(World_Group, ierr)
966
<div id="outline-container-sec-3-13" class="outline-3">
967
<h3 id="sec-3-13"><span class="section-number-3">3.13</span> Support routines</h3>
968
<div class="outline-text-3" id="text-3-13">
973
<div class="org-src-container">
975
<pre class="src src-f90"><<get-row-col>>
976
<<check-info>>
981
<div id="outline-container-sec-3-13-1" class="outline-4">
982
<h4 id="sec-3-13-1"><span class="section-number-4">3.13.1</span> Row and column partition of npPerPole</h4>
983
<div class="outline-text-4" id="text-3-13-1">
984
<div class="org-src-container">
986
<pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">get_row_col</span>(np,nrow,ncol)
987
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> np</span>
988
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> nrow, ncol</span>
989
<span style="color: #b22222;">!</span>
990
<span style="color: #b22222;">! </span><span style="color: #b22222;">Finds the factors nrow and ncol such that nrow*ncol=np,</span>
991
<span style="color: #b22222;">! </span><span style="color: #b22222;">are as similar as possible, and nrow>=ncol.</span>
992
<span style="color: #b22222;">! </span><span style="color: #b22222;">For prime np, ncol=1, nrow=np.</span>
994
ncol = <span style="color: #a020f0;">floor</span>(<span style="color: #a020f0;">sqrt</span>(<span style="color: #a020f0;">dble</span>(np)))
995
<span style="color: #a020f0;">do</span>
997
<span style="color: #a020f0;">if</span> (nrow*ncol == np) <span style="color: #a020f0;">exit</span>
999
<span style="color: #a020f0;">enddo</span>
1000
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">get_row_col</span>
1005
<div id="outline-container-sec-3-13-2" class="outline-4">
1006
<h4 id="sec-3-13-2"><span class="section-number-4">3.13.2</span> Error dispatcher</h4>
1007
<div class="outline-text-4" id="text-3-13-2">
1008
<div class="org-src-container">
1010
<pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">check_info</span>(info,str)
1011
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> info</span>
1012
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> str</span>
1014
<span style="color: #a020f0;">if</span>(mpirank == 0) <span style="color: #a020f0;">then</span>
1015
<span style="color: #a020f0;">if</span> (info /= 0) <span style="color: #a020f0;">then</span>
1016
<span style="color: #a020f0;">write</span>(6,*) <span style="color: #a020f0;">trim</span>(str) // <span style="color: #8b2252;">" info : "</span>, info
1017
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">die</span>(<span style="color: #8b2252;">"Error exit from "</span> // <span style="color: #a020f0;">trim</span>(str) // <span style="color: #8b2252;">" routine"</span>)
1018
<span style="color: #a020f0;">endif</span>
1019
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">pxfflush</span>(6)
1020
<span style="color: #a020f0;">endif</span>
1021
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">check_info</span>
1029
<div id="postamble" class="status">
1030
<p class="author">Author: Alberto Garcia</p>
1031
<p class="date">Created: 2015-11-05 Thu 12:35</p>
1032
<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.5.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10)</p>
1033
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>