<div dir="ltr"><div>Hello Ole,</div><div><br></div><div>Thank you very much for your reply:</div><div>I changed the code as you suggested (below), but the problem is still present in the test.</div><div><br></div><div>Best</div><div><br></div><div>Geng<br></div><div><div style="background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-word;" class="prettyprint"><code class="prettyprint"><div class="subprettyprint"><span style="color: #000;" class="styled-by-prettify">    </span><span style="color: #008;" class="styled-by-prettify">def</span><span style="color: #000;" class="styled-by-prettify"> send</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #008;" class="styled-by-prettify">self</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> line</span><span style="color: #660;" class="styled-by-prettify">):</span><span style="color: #000;" class="styled-by-prettify"><br>        </span><span style="color: #080;" class="styled-by-prettify">"""Send a line to the cp2k_shell"""</span><span style="color: #000;" class="styled-by-prettify"><br>        </span><span style="color: #008;" class="styled-by-prettify">assert</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #008;" class="styled-by-prettify">self</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">_child</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">poll</span><span style="color: #660;" class="styled-by-prettify">()</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #008;" class="styled-by-prettify">is</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #008;" class="styled-by-prettify">None</span><span style="color: #000;" class="styled-by-prettify">  </span><span style="color: #800;" class="styled-by-prettify"># child process still alive?</span><span style="color: #000;" class="styled-by-prettify"><br>        </span><span style="color: #008;" class="styled-by-prettify">if</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #008;" class="styled-by-prettify">self</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">_debug</span><span style="color: #660;" class="styled-by-prettify">:</span><span style="color: #000;" class="styled-by-prettify"><br>            </span><span style="color: #800;" class="styled-by-prettify">#print('Sending: ' + line)</span><span style="color: #000;" class="styled-by-prettify"><br>            sys</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">stderr</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">write</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #080;" class="styled-by-prettify">"Sending: {}\n"</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">format</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">line</span><span style="color: #660;" class="styled-by-prettify">))</span><span style="color: #000;" class="styled-by-prettify"><br>            sys</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">stderr</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">flush</span><span style="color: #660;" class="styled-by-prettify">()</span><span style="color: #000;" class="styled-by-prettify"><br><br>        </span><span style="color: #008;" class="styled-by-prettify">if</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #008;" class="styled-by-prettify">self</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">version </span><span style="color: #660;" class="styled-by-prettify"><</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #066;" class="styled-by-prettify">2.1</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #008;" class="styled-by-prettify">and</span><span style="color: #000;" class="styled-by-prettify"> len</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">line</span><span style="color: #660;" class="styled-by-prettify">)</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #660;" class="styled-by-prettify">>=</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #066;" class="styled-by-prettify">80</span><span style="color: #660;" class="styled-by-prettify">:</span><span style="color: #000;" class="styled-by-prettify"><br>            </span><span style="color: #008;" class="styled-by-prettify">raise</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #606;" class="styled-by-prettify">Exception</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #080;" class="styled-by-prettify">'Buffer overflow, upgrade CP2K to r16779 or later'</span><span style="color: #660;" class="styled-by-prettify">)</span><span style="color: #000;" class="styled-by-prettify"><br>        </span><span style="color: #008;" class="styled-by-prettify">assert</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">len</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">line</span><span style="color: #660;" class="styled-by-prettify">)</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #660;" class="styled-by-prettify"><</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #066;" class="styled-by-prettify">800</span><span style="color: #660;" class="styled-by-prettify">)</span><span style="color: #000;" class="styled-by-prettify">  </span><span style="color: #800;" class="styled-by-prettify"># new input buffer size</span><span style="color: #000;" class="styled-by-prettify"><br>        </span><span style="color: #008;" class="styled-by-prettify">self</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">isready </span><span style="color: #660;" class="styled-by-prettify">=</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #008;" class="styled-by-prettify">False</span><span style="color: #000;" class="styled-by-prettify"><br>        </span><span style="color: #008;" class="styled-by-prettify">self</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">_child</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">stdin</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">write</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">line </span><span style="color: #660;" class="styled-by-prettify">+</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #080;" class="styled-by-prettify">'\n'</span><span style="color: #660;" class="styled-by-prettify">)</span><span style="color: #000;" class="styled-by-prettify"><br>        </span><span style="color: #008;" class="styled-by-prettify">self</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">_child</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">stdin</span><span style="color: #660;" class="styled-by-prettify">.</span><span style="color: #000;" class="styled-by-prettify">flush</span><span style="color: #660;" class="styled-by-prettify">()</span><span style="color: #000;" class="styled-by-prettify"><br><br></span></div></code></div></div><div><br><br></div><br>在 2018年12月4日星期二 UTC-8上午11:05:43,Ole Schütt写道:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Hi Geng,
<br>
<br>this sounds indeed like a buffering issue. Could you once try to add a 
<br>flush() on the python side.
<br>
<br>Basically add the following line after cp2k.py:498.
<br>
<br>         self._child.stdin.write(line + '\n')
<br>+       self._child.stdin.flush()
<br>
<br>This is probably quite inefficient. So, if it works I'll add some logic 
<br>to flush only when recv() follows a send().
<br>
<br>
<br>-Ole
<br>
<br>
<br>On 2018-12-04 18:08, Geng Sun wrote:
<br>> Dear CP2K users,
<br>> 
<br>>  In the past several weeks, I frequently faced a problem when I use
<br>> the CP2K -ASE interface.
<br>> 
<br>>  The calculations frequently got stuck during the calculations.
<br>> 
<br>> 1) Firstly I switched on the debug=True option in the ASE-CP2K
<br>> calculator and I found that the calculation always gets stuck at a
<br>> line with *END after sending the positions to the subroutine
<br>> cp2k_shell.popt  (I printed the information to the standard error, so
<br>> they are not buffered)
<br>> 
<br>> 2) Then, I modified the cp2k_shell.F to print a lot of "labels". Then
<br>> I found that the code may get stuck at the line of "READ
<br>> (*,*,iostat=iostat) pos" like below. I can always get "begin to read
<br>> pos" in the standard error, but I can not reach "LABEL-1".
<br>> 
<br>>            WRITE(0,*) "begin to read pos"
<br>>            CALL m_flush(0)
<br>>            READ (*,*,iostat=iostat) pos
<br>>            WRITE(0,*) "LABEL-1"
<br>>            CALL m_flush(0)
<br>> 
<br>> I attached the modified cp2k_shell.F and the standard out/error
<br>> generated by the slurm batch system with this post. You can see that
<br>> the program get stuck at the second optimization step just after
<br>> sending the positions.
<br>> 
<br>> I greatly appreciate your suggestions for fixing this confusing bugs.
<br>> 
<br>> Thanks in advance.
<br>> 
<br>> Geng
<br>> 
<br>>  --
<br>> You received this message because you are subscribed to the Google
<br>> Groups "cp2k" group.
<br>> To unsubscribe from this group and stop receiving emails from it, send
<br>> an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="qXF3Cbt5AAAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">cp2k+uns...@googlegroups.<wbr>com</a>.
<br>> To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="qXF3Cbt5AAAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">cp...@googlegroups.com</a>.
<br>> Visit this group at <a href="https://groups.google.com/group/cp2k" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/group/cp2k';return true;" onclick="this.href='https://groups.google.com/group/cp2k';return true;">https://groups.google.com/<wbr>group/cp2k</a>.
<br>> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/<wbr>optout</a>.
<br>
<br></blockquote></div>