~nickpapior/siesta/trunk-buds-format0.92

« back to all changes in this revision

Viewing changes to Docs/LitCode/pexsi-ldos.html

  • Committer: Alberto Garcia
  • Date: 2015-11-05 13:08:52 UTC
  • mto: This revision was merged to the branch mainline in revision 538.
  • Revision ID: albertog@icmab.es-20151105130852-akm5pz95hd73xe4m
Avoid stopping the program when the solver does not converge. Update documentation.

Rather than stopping the program immediately, we allow the
density-matrix normalization step to try to recover the correct number
of electrons. This is non-optimal but can recover from occassional
instabilities.

Update the manual.

Create Docs/LitCode to hold the .html files produced (manually for now) from
the .lit files in Src.

added:
  Docs/LitCode/
  Docs/LitCode/README
  Docs/LitCode/pexsi-dos.html
  Docs/LitCode/pexsi-ldos.html
  Docs/LitCode/pexsi-lit.html
  Docs/LitCode/pexsi-solver.html
  Docs/LitCode/redist-spmatrix.html
renamed:
  Src/redist-spmatrix.org => Src/redist-spmatrix.lit
modified:
  Docs/siesta.tex
  Src/Makefile
  Src/m_pexsi_driver.F90
  Src/makefile.lit
  Src/pexsi-solver.lit
  Src/redist-spmatrix.lit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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">
 
5
<head>
 
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%; }
 
26
  pre {
 
27
    border: 1px solid #ccc;
 
28
    box-shadow: 3px 3px 3px #eee;
 
29
    padding: 8pt;
 
30
    font-family: monospace;
 
31
    overflow: auto;
 
32
    margin: 1.2em;
 
33
  }
 
34
  pre.src {
 
35
    position: relative;
 
36
    overflow: visible;
 
37
    padding-top: 1.2em;
 
38
  }
 
39
  pre.src:before {
 
40
    display: none;
 
41
    position: absolute;
 
42
    background-color: white;
 
43
    top: -10px;
 
44
    right: 10px;
 
45
    padding: 3px;
 
46
    border: 1px solid black;
 
47
  }
 
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'; }
 
56
 
 
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; }
 
73
  .inlinetask {
 
74
    padding: 10px;
 
75
    border: 2px solid gray;
 
76
    margin: 10px;
 
77
    background: #ffffcc;
 
78
  }
 
79
  #org-div-home-and-up
 
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; }
 
89
  /*]]>*/-->
 
90
</style>
 
91
<script type="text/javascript">
 
92
/*
 
93
@licstart  The following is the entire license notice for the
 
94
JavaScript code in this tag.
 
95
 
 
96
Copyright (C) 2012-2013 Free Software Foundation, Inc.
 
97
 
 
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.
 
105
 
 
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.
 
111
 
 
112
 
 
113
@licend  The above is the entire license notice
 
114
for the JavaScript code in this tag.
 
115
*/
 
116
<!--/*--><![CDATA[/*><!--*/
 
117
 function CodeHighlightOn(elem, id)
 
118
 {
 
119
   var target = document.getElementById(id);
 
120
   if(null != target) {
 
121
     elem.cacheClassElem = elem.className;
 
122
     elem.cacheClassTarget = target.className;
 
123
     target.className = "code-highlighted";
 
124
     elem.className   = "code-highlighted";
 
125
   }
 
126
 }
 
127
 function CodeHighlightOff(elem, id)
 
128
 {
 
129
   var target = document.getElementById(id);
 
130
   if(elem.cacheClassElem)
 
131
     elem.className = elem.cacheClassElem;
 
132
   if(elem.cacheClassTarget)
 
133
     target.className = elem.cacheClassTarget;
 
134
 }
 
135
/*]]>*///-->
 
136
</script>
 
137
</head>
 
138
<body>
 
139
<div id="content">
 
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">
 
144
<ul>
 
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>
 
148
<ul>
 
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>
 
151
<ul>
 
152
<li><a href="#sec-3-2-1">3.2.1. Used modules</a></li>
 
153
</ul>
 
154
</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>
 
166
<ul>
 
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>
 
169
</ul>
 
170
</li>
 
171
</ul>
 
172
</li>
 
173
</ul>
 
174
</div>
 
175
</div>
 
176
<p>
 
177
-*- mode: Org -*-
 
178
</p>
 
179
 
 
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">
 
183
<p>
 
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).
 
186
Module structure:
 
187
</p>
 
188
 
 
189
<div class="org-src-container">
 
190
 
 
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
 
194
 
 
195
<span style="color: #a020f0;">CONTAINS</span>
 
196
&lt;&lt;siesta-side-parent-routine&gt;&gt;
 
197
&lt;&lt;pexsi-ldos-routine&gt;&gt;
 
198
<span style="color: #a020f0;">end module</span> <span style="color: #0000ff;">m_pexsi_local_dos</span>
 
199
</pre>
 
200
</div>
 
201
</div>
 
202
</div>
 
203
 
 
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">
 
207
<p>
 
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>.
 
213
</p>
 
214
 
 
215
<div class="org-src-container">
 
216
 
 
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>
 
219
 
 
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
 
235
 
 
236
  <span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
 
237
 
 
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>
 
241
 
 
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>
 
244
 
 
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>
 
246
 
 
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>)
 
249
 
 
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;">&amp;</span>
 
252
       maxnh, numh, listh, H, S,  <span style="color: #a020f0;">&amp;</span>
 
253
       Dscf, energy, broadening)
 
254
 
 
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>
 
258
     g2max = g2cut
 
259
 
 
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>
 
262
 
 
263
     <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">dhscf</span>( nspin, no_s, iaorb, iphorb, no_l, <span style="color: #a020f0;">&amp;</span>
 
264
          no_u, na_u, na_s, isa, xa_last, indxua,  <span style="color: #a020f0;">&amp;</span>
 
265
          ntm, 0, 0, 0, filesOut,                  <span style="color: #a020f0;">&amp;</span>
 
266
          maxnh, numh, listhptr, listh, Dscf, Datm, maxnh, H, <span style="color: #a020f0;">&amp;</span>
 
267
          Enaatm, Enascf, Uatm, Uscf, DUscf, DUext, Exc, Dxc, <span style="color: #a020f0;">&amp;</span>
 
268
          dummy_dipol, dummy_str, fa, dummy_strl )
 
269
  <span style="color: #a020f0;">endif</span>
 
270
 
 
271
<span style="color: #a020f0;">END subroutine</span> <span style="color: #0000ff;">pexsi_local_dos</span>
 
272
</pre>
 
273
</div>
 
274
</div>
 
275
</div>
 
276
 
 
277
 
 
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">
 
284
<p>
 
285
This is the main structure of the LDOS routine.
 
286
</p>
 
287
 
 
288
<div class="org-src-container">
 
289
 
 
290
<pre class="src src-f90">&lt;&lt;routine-header&gt;&gt;
 
291
&lt;&lt;routine-variables&gt;&gt;
 
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
&lt;&lt;define-communicators&gt;&gt;
 
297
&lt;&lt;re-<span style="color: #a020f0;">distribute</span>-matrices&gt;&gt;
 
298
&lt;&lt;set-options&gt;&gt;
 
299
&lt;&lt;prepare-plan&gt;&gt;
 
300
&lt;&lt;load-hs-matrices&gt;&gt;
 
301
&lt;&lt;factorization&gt;&gt;
 
302
&lt;&lt;compute-ldos&gt;&gt;
 
303
&lt;&lt;copy-to-siesta-side&gt;&gt;
 
304
&lt;&lt;clean-up&gt;&gt;
 
305
<span style="color: #483d8b;">#endif</span>
 
306
 
 
307
<span style="color: #a020f0;">CONTAINS</span>
 
308
 
 
309
&lt;&lt;support-routines&gt;&gt;
 
310
 
 
311
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">get_LDOS_SI</span>
 
312
</pre>
 
313
</div>
 
314
</div>
 
315
</div>
 
316
 
 
317
 
 
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">
 
322
 
 
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;">&amp;</span>
 
324
     maxnh, numh, listh, H, S,  <span style="color: #a020f0;">&amp;</span>
 
325
     LocalDOSDM, energy, broadening)
 
326
 
 
327
&lt;&lt;used-modules&gt;&gt;
 
328
 
 
329
<span style="color: #a020f0;">implicit</span>          <span style="color: #228b22;">none</span>
 
330
 
 
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>
 
336
</pre>
 
337
</div>
 
338
</div>
 
339
 
 
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">
 
344
 
 
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;">&amp;</span>
 
366
          <span style="color: #a020f0;">only</span>: f_ppexsi_symbolic_factorize_complex_symmetric_matrix
 
367
</pre>
 
368
</div>
 
369
</div>
 
370
</div>
 
371
</div>
 
372
 
 
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">
 
376
<p>
 
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.
 
381
</p>
 
382
 
 
383
<div class="org-src-container">
 
384
 
 
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
 
390
</pre>
 
391
</div>
 
392
</div>
 
393
</div>
 
394
 
 
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">
 
398
<p>
 
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.
 
401
</p>
 
402
 
 
403
<div class="org-src-container">
 
404
 
 
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>
 
409
</pre>
 
410
</div>
 
411
 
 
412
<div class="org-src-container">
 
413
 
 
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 )
 
419
 
 
420
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"pexsi-ldos"</span>, 1)  
 
421
 
 
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>
 
425
   norbs = no_u
 
426
   nspin = nspin_in
 
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)
 
431
</pre>
 
432
</div>
 
433
 
 
434
<p>
 
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
 
438
matrices.
 
439
</p>
 
440
 
 
441
<p>
 
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>.
 
446
</p>
 
447
 
 
448
<div class="org-src-container">
 
449
 
 
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>
 
465
</pre>
 
466
</div>
 
467
 
 
468
<p>
 
469
Define the Siesta distribution. Note that this is known to all nodes.
 
470
</p>
 
471
 
 
472
<div class="org-src-container">
 
473
 
 
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;">&amp;</span>
 
478
     (/ (i,i=0,nworkers_SIESTA-1) /), <span style="color: #a020f0;">&amp;</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;">&amp;</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)
 
484
</pre>
 
485
</div>
 
486
 
 
487
<p>
 
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.
 
491
</p>
 
492
 
 
493
<div class="org-src-container">
 
494
 
 
495
<pre class="src src-f90"><span style="color: #a020f0;">call</span> <span style="color: #0000ff;">mpi_comm_size</span>( World_Comm, numNodesTotal, ierr )
 
496
 
 
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 &gt; numNodesTotal) <span style="color: #a020f0;">&amp;</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>)
 
501
 
 
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)
 
506
 
 
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)
 
510
 
 
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;">&amp;</span>
 
515
     (/ (i,i=0,npPerPole-1) /),<span style="color: #a020f0;">&amp;</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;">&amp;</span>
 
518
     PEXSI_Pole_Comm, Ierr)
 
519
 
 
520
 
 
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 &lt; npPerPole)   <span style="color: #b22222;">! </span><span style="color: #b22222;">Could be spin up or spin down</span>
 
524
 
 
525
<span style="color: #b22222;">! </span><span style="color: #b22222;">PEXSI blocksize </span>
 
526
pbs = norbs/npPerPole
 
527
 
 
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>
 
531
 
 
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)
 
534
 
 
535
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">MPI_Group_translate_ranks</span>( PEXSI_Pole_Group, npPerPole, <span style="color: #a020f0;">&amp;</span>
 
536
     (/ (i,i=0,npPerPole-1) /), <span style="color: #a020f0;">&amp;</span>
 
537
     World_Group, pexsi_pole_ranks_in_world, ierr )
 
538
 
 
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;">&amp;</span>
 
543
     PEXSI_Pole_Ranks_in_World_Spin,npPerPole, <span style="color: #a020f0;">&amp;</span>
 
544
     MPI_integer,PEXSI_Spin_Comm,ierr)
 
545
 
 
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;">&amp;</span>
 
550
        PEXSI_Pole_Ranks_in_World_Spin(:,ispin),  <span style="color: #a020f0;">&amp;</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)
 
555
</pre>
 
556
</div>
 
557
</div>
 
558
</div>
 
559
 
 
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">
 
563
<p>
 
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.
 
567
</p>
 
568
 
 
569
<div class="org-src-container">
 
570
 
 
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=&gt; null(), rowindLocal=&gt;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;">&amp;</span>
 
578
        HnzvalLocal=&gt;null(), SnzvalLocal=&gt;null(),  <span style="color: #a020f0;">&amp;</span>
 
579
        DMnzvalLocal =&gt; <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>
 
582
</pre>
 
583
</div>
 
584
<div class="org-src-container">
 
585
 
 
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>
 
589
 
 
590
<span style="color: #a020f0;">allocate</span>(m1_spin(nspin))
 
591
<span style="color: #a020f0;">do</span> ispin = 1, nspin
 
592
 
 
593
   m1 =&gt; m1_spin(ispin)
 
594
 
 
595
   <span style="color: #a020f0;">if</span> (SIESTA_worker) <span style="color: #a020f0;">then</span>
 
596
      m1%norbs = norbs
 
597
      m1%no_l  = no_l
 
598
      m1%nnzl  = <span style="color: #a020f0;">sum</span>(numH(1:no_l))
 
599
      m1%numcols =&gt; numH
 
600
      m1%cols    =&gt; listH
 
601
      <span style="color: #a020f0;">allocate</span>(m1%vals(2))
 
602
      m1%vals(1)%data =&gt; S(:)
 
603
      m1%vals(2)%data =&gt; H(:,ispin)
 
604
 
 
605
   <span style="color: #a020f0;">endif</span>  <span style="color: #b22222;">! </span><span style="color: #b22222;">SIESTA_worker</span>
 
606
 
 
607
   <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"redist_orbs_fwd"</span>, 1)
 
608
 
 
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 =&gt; dist2_spin(ispin)
 
613
   <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">redistribute_spmatrix</span>(norbs,m1,dist1,m2,dist2,World_Comm)
 
614
 
 
615
   <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"redist_orbs_fwd"</span>, 2)
 
616
 
 
617
   <span style="color: #a020f0;">if</span> (PEXSI_worker <span style="color: #a020f0;">.and.</span> (pexsi_spin == ispin) ) <span style="color: #a020f0;">then</span>
 
618
 
 
619
      nrows = m2%norbs          <span style="color: #b22222;">! </span><span style="color: #b22222;">or simply 'norbs'</span>
 
620
      numColLocal = m2%no_l
 
621
      nnzLocal    = m2%nnzl
 
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)
 
623
 
 
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>)
 
625
      colptrLocal(1) = 1
 
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>
 
629
 
 
630
      rowindLocal =&gt; m2%cols
 
631
      SnzvalLocal =&gt; m2%vals(1)%data
 
632
      HnzvalLocal =&gt; m2%vals(2)%data
 
633
 
 
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>)
 
635
 
 
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)
 
637
 
 
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>
 
640
 
 
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>
 
645
 
 
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)
 
648
 
 
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)
 
650
</pre>
 
651
</div>
 
652
</div>
 
653
</div>
 
654
 
 
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">
 
658
<p>
 
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.
 
661
</p>
 
662
 
 
663
<div class="org-src-container">
 
664
 
 
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>
 
669
</pre>
 
670
</div>
 
671
 
 
672
<div class="org-src-container">
 
673
 
 
674
<pre class="src src-f90"><span style="color: #b22222;">! </span><span style="color: #b22222;">-- </span>
 
675
  isSIdentity = 0
 
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)
 
686
</pre>
 
687
</div>
 
688
</div>
 
689
</div>
 
690
 
 
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">
 
694
<p>
 
695
Each spin-set of PEXSI processors has its own plan, but we only 
 
696
include the first-pole group of nodes&#x2026;
 
697
</p>
 
698
<div class="org-src-container">
 
699
 
 
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>
 
703
</pre>
 
704
</div>
 
705
 
 
706
<div class="org-src-container">
 
707
 
 
708
<pre class="src src-f90">  <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">get_row_col</span>(npPerPole,numProcRow,numProcCol)
 
709
 
 
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>
 
713
 
 
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;">&amp;</span>
 
724
      PEXSI_Pole_Comm,<span style="color: #a020f0;">&amp;</span>
 
725
      numProcRow,<span style="color: #a020f0;">&amp;</span>
 
726
      numProcCol,<span style="color: #a020f0;">&amp;</span>
 
727
      outputFileIndex,<span style="color: #a020f0;">&amp;</span>
 
728
      info) 
 
729
 
 
730
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">check_info</span>(info,<span style="color: #8b2252;">"plan_initialize in LDOS"</span>)
 
731
</pre>
 
732
</div>
 
733
</div>
 
734
</div>
 
735
 
 
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">
 
739
<p>
 
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.)
 
743
</p>
 
744
 
 
745
<div class="org-src-container">
 
746
 
 
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;">&amp;</span>
 
748
      plan,<span style="color: #a020f0;">&amp;</span>
 
749
      options,<span style="color: #a020f0;">&amp;</span>
 
750
      nrows,<span style="color: #a020f0;">&amp;</span>
 
751
      nnz,<span style="color: #a020f0;">&amp;</span>
 
752
      nnzLocal,<span style="color: #a020f0;">&amp;</span>
 
753
      numColLocal,<span style="color: #a020f0;">&amp;</span>
 
754
      colptrLocal,<span style="color: #a020f0;">&amp;</span>
 
755
      rowindLocal,<span style="color: #a020f0;">&amp;</span>
 
756
      HnzvalLocal,<span style="color: #a020f0;">&amp;</span>
 
757
      isSIdentity,<span style="color: #a020f0;">&amp;</span>
 
758
      SnzvalLocal,<span style="color: #a020f0;">&amp;</span>
 
759
      info) 
 
760
 
 
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>)
 
762
</pre>
 
763
</div>
 
764
</div>
 
765
</div>
 
766
 
 
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">
 
770
<p>
 
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.
 
774
</p>
 
775
 
 
776
<div class="org-src-container">
 
777
 
 
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;">&amp;</span>
 
779
       plan, <span style="color: #a020f0;">&amp;</span>
 
780
       options,<span style="color: #a020f0;">&amp;</span>
 
781
       info)
 
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>)
 
783
 
 
784
options%isSymbolicFactorize = 0 <span style="color: #b22222;">! </span><span style="color: #b22222;">We do not need it anymore</span>
 
785
</pre>
 
786
</div>
 
787
</div>
 
788
</div>
 
789
 
 
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">
 
794
 
 
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 =&gt; 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 =&gt; null()</span>
 
797
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> loc</span>
 
798
</pre>
 
799
</div>
 
800
 
 
801
<p>
 
802
Note that only the first-pole team does this.
 
803
</p>
 
804
 
 
805
<div class="org-src-container">
 
806
 
 
807
<pre class="src src-f90"><span style="color: #a020f0;">if</span> (PEXSI_worker) <span style="color: #a020f0;">then</span>
 
808
 
 
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;">&amp;</span>
 
811
           <span style="color: #8b2252;">'Calling PEXSI LDOS routine. Energy and broadening (eV) '</span>, <span style="color: #a020f0;">&amp;</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;">&amp;</span>
 
814
           <span style="color: #8b2252;">'Processors working on selected inversion: '</span>, npPerPole
 
815
   <span style="color: #a020f0;">endif</span>
 
816
 
 
817
   <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"pexsi-ldos-selinv"</span>, 1)
 
818
 
 
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>
 
821
 
 
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>)
 
824
 
 
825
   loc = 1
 
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)
 
829
      loc = loc + 2
 
830
   <span style="color: #a020f0;">enddo</span>
 
831
 
 
832
   <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">f_ppexsi_selinv_complex_symmetric_matrix</span>(<span style="color: #a020f0;">&amp;</span>
 
833
        plan,<span style="color: #a020f0;">&amp;</span>
 
834
        options,<span style="color: #a020f0;">&amp;</span>
 
835
        AnzvalLocal,<span style="color: #a020f0;">&amp;</span>
 
836
        AinvnzvalLocal,<span style="color: #a020f0;">&amp;</span>
 
837
        info) 
 
838
 
 
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>)
 
840
 
 
841
   <span style="color: #b22222;">! </span><span style="color: #b22222;">Get DMnzvalLocal as 1/pi * Imag(Ainv...)</span>
 
842
 
 
843
   loc = 1
 
844
   <span style="color: #a020f0;">do</span> i = 1, nnzLocal
 
845
      DMnzvalLocal(i) = (1.0_dp/pi) * AinvnzvalLocal(loc+1)
 
846
      loc = loc + 2
 
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>)
 
850
 
 
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>
 
854
</pre>
 
855
</div>
 
856
</div>
 
857
</div>
 
858
 
 
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">
 
863
 
 
864
<pre class="src src-f90"><span style="color: #a020f0;">do</span> ispin = 1, nspin
 
865
 
 
866
   m1 =&gt; m1_spin(ispin)
 
867
 
 
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>
 
870
 
 
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>)
 
872
 
 
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>)
 
875
 
 
876
     <span style="color: #a020f0;">deallocate</span>(m2%vals)
 
877
     <span style="color: #a020f0;">allocate</span>(m2%vals(1))
 
878
     m2%vals(1)%data =&gt; DMnzvalLocal(1:nnzLocal)
 
879
 
 
880
   <span style="color: #a020f0;">endif</span>
 
881
 
 
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>
 
890
 
 
891
   <span style="color: #a020f0;">call</span> <span style="color: #0000ff;">timer</span>(<span style="color: #8b2252;">"redist_orbs_bck"</span>, 1)
 
892
   dist2 =&gt; 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)
 
895
 
 
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>)
 
898
 
 
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>
 
905
 
 
906
   <span style="color: #a020f0;">if</span> (SIESTA_worker) <span style="color: #a020f0;">then</span>
 
907
 
 
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>
 
917
 
 
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>)
 
923
 
 
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)
 
927
</pre>
 
928
</div>
 
929
</div>
 
930
</div>
 
931
 
 
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">
 
936
 
 
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)
 
943
 
 
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)
 
947
 
 
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>
 
957
 
 
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)
 
961
</pre>
 
962
</div>
 
963
</div>
 
964
</div>
 
965
 
 
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">
 
969
<p>
 
970
A couple of routines
 
971
</p>
 
972
 
 
973
<div class="org-src-container">
 
974
 
 
975
<pre class="src src-f90">&lt;&lt;get-row-col&gt;&gt;
 
976
&lt;&lt;check-info&gt;&gt;
 
977
</pre>
 
978
</div>
 
979
</div>
 
980
 
 
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">
 
985
 
 
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&gt;=ncol.</span>
 
992
<span style="color: #b22222;">! </span><span style="color: #b22222;">For prime np, ncol=1, nrow=np.</span>
 
993
 
 
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>
 
996
  nrow = np/ncol
 
997
  <span style="color: #a020f0;">if</span> (nrow*ncol == np) <span style="color: #a020f0;">exit</span>
 
998
  ncol = ncol - 1
 
999
<span style="color: #a020f0;">enddo</span>
 
1000
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">get_row_col</span>
 
1001
</pre>
 
1002
</div>
 
1003
</div>
 
1004
</div>
 
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">
 
1009
 
 
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>
 
1013
 
 
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>
 
1022
</pre>
 
1023
</div>
 
1024
</div>
 
1025
</div>
 
1026
</div>
 
1027
</div>
 
1028
</div>
 
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>
 
1034
</div>
 
1035
</body>
 
1036
</html>