<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><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 <Mark.Abraham@anu.edu.au><br><b><span style="font-weight: bold;">To:</span></b> Discussion list for GROMACS development <gmx-developers@gromacs.org><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>> Dear All,<br>> I need to hack mdrun in rather complex way and need some help from people, who<br>> understand Gromacs internals really well.<br>> My problem is the following. Each N MD steps I want to pass current<br>> coordinates and forces to custom function, which transforms them in a certain<br>> way (doesn't matter how at this point). Then I want to pass modified forces and<br>> <br>> coordinates back and continue simulation. Currently I got stuck with domain<br>> decomposition stuff. I figured out how to collect data on master node and pass<br>> it to my function. However, I have no idea how to distribute it back to all<br>> nodes correctly after modification.<br>> Here is my additional code in md.c so far:<br>> <br>> ...<br>> /* ######## END FIRST UPDATE STEP ############## */<br>> /*
######## If doing VV, we now have v(dt) ###### */<br>> <br>> /* ################## START TRAJECTORY OUTPUT ################# */<br>> <br>> /* Some preparations goes here */<br>> ...<br>> /* Collecting data*/<br>> if (DOMAINDECOMP(cr))<br>> {<br>> /*We need to collect x and f only*/<br>> dd_collect_vec(cr->dd,state_local,state_local->x,state_global->x);<br>> dd_collect_vec(cr->dd,state_local,f_local,f_global);<br>> }<br>> <br>> if (MASTER(cr))<br>> {<br>> printf("Collected %d atoms at step: %d\n",top_global->natoms,step);<br>> /* Actually pass data */<br>> pass_to(top_global->natoms, t, state_global->x,
f_global);<br>> ...<br>> /* Processing data here */<br>> ...<br>> /* Get data back */<br>> pass_from(state_global->x, f_global);<br>> }<br>> ...<br>> if (DOMAINDECOMP(cr)){<br>> /* Here I have to redistribute it back from state_global->x and I'm totally<br>> stuck :( */<br>> }<br>> <br>> The problem is that functions like dd_distribute_vector(...) are only used<br>> deep inside domain decomposition code and they use some data structures, which<br>> are not exposed in .h files.<br><br>dd_collect_vec() calls dd_collect_cg() which fills dd->comm->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->comm->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->comm->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>> 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->dd,&cr->dd->comm->cgs_gl,state_global->x,state_local->x);<br><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></body></html>