<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    On 7/04/2011 11:22 PM, Semen Esilevsky wrote:
    <blockquote cite="mid:750107.63805.qm@web113515.mail.gq1.yahoo.com"
      type="cite">
      <style type="text/css"><!-- DIV {margin:0px;} --></style>
      <div style="font-family: times new roman,new york,times,serif;
        font-size: 12pt;">
        <div><br>
        </div>
        <div style="font-family: times new roman,new york,times,serif;
          font-size: 12pt;"><br>
          <div style="font-family: arial,helvetica,sans-serif;
            font-size: 10pt;"><font face="Tahoma" size="2">
              <hr size="1"><b><span style="font-weight: bold;">From:</span></b>
              Mark Abraham <a class="moz-txt-link-rfc2396E" href="mailto:Mark.Abraham@anu.edu.au">&lt;Mark.Abraham@anu.edu.au&gt;</a><br>
              <b><span style="font-weight: bold;">To:</span></b>
              Discussion list for GROMACS development
              <a class="moz-txt-link-rfc2396E" href="mailto:gmx-developers@gromacs.org">&lt;gmx-developers@gromacs.org&gt;</a><br>
              <b><span style="font-weight: bold;">Sent:</span></b> Thu,
              April 7, 2011 3:16:05 PM<br>
              <b><span style="font-weight: bold;">Subject:</span></b>
              Re: [gmx-developers] Help needed with hacking mdrun<br>
            </font><br>
            On 7/04/2011 7:11 PM, Semen Esilevsky wrote:<br>
            &gt; Dear All,<br>
            &gt; I need to hack mdrun in rather complex way and need
            some help from people, who<br>
            &gt; understand Gromacs internals really well.<br>
            &gt; My&nbsp; problem is the following. Each N MD steps I want to
            pass current<br>
            &gt; coordinates and forces to custom function, which
            transforms them in a&nbsp; certain<br>
            &gt; way (doesn't matter how at this point). Then I want to
            pass&nbsp; modified forces and<br>
            &gt; <br>
            &gt; coordinates back and continue simulation. Currently I&nbsp;
            got stuck with domain<br>
            &gt; decomposition stuff. I figured out how to collect&nbsp; data
            on master node and pass<br>
            &gt; it to my function. However,&nbsp; I have no&nbsp; idea how to
            distribute it back to all<br>
            &gt; nodes correctly after&nbsp; modification.<br>
            &gt; Here is my additional code in md.c&nbsp; so far:<br>
            &gt; <br>
            &gt; ...<br>
            &gt; /* ########&nbsp; END FIRST UPDATE STEP&nbsp; ############## */<br>
            &gt; /* ########&nbsp; If doing VV, we now have v(dt)&nbsp; ###### */<br>
            &gt; <br>
            &gt;&nbsp; /* ################## START TRAJECTORY OUTPUT
            ################# */<br>
            &gt; <br>
            &gt; /* Some preparations goes here */<br>
            &gt; ...<br>
            &gt; /* Collecting data*/<br>
            &gt; if (DOMAINDECOMP(cr))<br>
            &gt;&nbsp; &nbsp; &nbsp; {<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /*We need to collect x and f only*/<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
dd_collect_vec(cr-&gt;dd,state_local,state_local-&gt;x,state_global-&gt;x);<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            dd_collect_vec(cr-&gt;dd,state_local,f_local,f_global);<br>
            &gt;&nbsp; &nbsp; &nbsp; }<br>
            &gt; <br>
            &gt; if (MASTER(cr))<br>
            &gt;&nbsp; &nbsp; &nbsp; {<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Collected %d atoms at step:
            %d\n",top_global-&gt;natoms,step);<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Actually pass data */<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass_to(top_global-&gt;natoms, t,
            state_global-&gt;x, f_global);<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Processing data here */<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; /*&nbsp; Get data back */<br>
            &gt;&nbsp; &nbsp; &nbsp; &nbsp; pass_from(state_global-&gt;x, f_global);<br>
            &gt;&nbsp; &nbsp; &nbsp; }<br>
            &gt; ...<br>
            &gt; if (DOMAINDECOMP(cr)){<br>
            &gt;&nbsp; &nbsp; &nbsp; /* Here I have to redistribute it back from
            state_global-&gt;x and I'm totally<br>
            &gt; stuck :(&nbsp; */<br>
            &gt; }<br>
            &gt; <br>
            &gt; The problem is that functions like
            dd_distribute_vector(...) are only used<br>
            &gt; deep inside domain decomposition code and they use some
            data structures, which<br>
            &gt; are not exposed in .h files.<br>
            <br>
            dd_collect_vec() calls dd_collect_cg() which fills
            dd-&gt;comm-&gt;cgs_gl if it is out of date.
            dd_partition_system() calls dd_distribute_state() which
            calls dd_distribute_vec(). However get_cg_distribution
            fills() dd-&gt;comm-&gt;cgs_gl immediately before
            dd_distribute state().<br>
            <br>
            So if your modifications to positions are small, then I
            suspect you can just call dd_distribute_vec() passing
            dd-&gt;comm-&gt;cgs_gl. The UI and documentation (ahem)
            could be better, I think.<br>
            <br>
            Otherwise, call dd_partition_system to re-do the DD
            partition.<br>
            <br>
            &gt; Is there any other more elegant way of plugging custom
            code to mdrun?<br>
            <br>
            No.<br>
            <br>
            Mark<br>
            <hr style="width: 100%; height: 2px;"><br>
            Dear Mark,<br>
            That was exactly what I tried to do. The problem is that the
            function dd_distribute_vec() is declared inside domdec.c as
            well as the structs, which it uses. It is not exposed in any
            of .h files! As a result the line in my additional code<br>
            <br>
dd_distribute_vec(cr-&gt;dd,&amp;cr-&gt;dd-&gt;comm-&gt;cgs_gl,state_global-&gt;x,state_local-&gt;x);<br>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    I think you can just declare this function in domdec.h and you'll be
    fine. None of those structures are internal to only domdec.c.<br>
    <br>
    Mark<br>
    <br>
    <blockquote cite="mid:750107.63805.qm@web113515.mail.gq1.yahoo.com"
      type="cite">
      <div style="font-family: times new roman,new york,times,serif;
        font-size: 12pt;">
        <div style="font-family: times new roman,new york,times,serif;
          font-size: 12pt;">
          <div style="font-family: arial,helvetica,sans-serif;
            font-size: 10pt;"><br>
            Produces this error:<br>
            error: dereferencing pointer to incomplete type. It doesn't
            see the type of comm.<br>
            <br>
            I have tried to copy-paste all struct definitions from
            domdec.h to md.c. This compiles, but then I get link error:<br>
            <br>
            md.c:(.text+0xece): undefined reference to
            `dd_distribute_vec'<br>
            <br>
            Adding md to the list of libraries mdrun links to does not
            help - it still dosn't see dd_distribute_vec.<br>
            How can overcome this? I'm sorry if this is something
            obvious - my experience with pure C is very limited (I'm
            writing on "high level" C++). I don't quite understand how
            to link with a function, which is not exposed in h-files...<br>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>