Dear Users,
I am trying to modify the ‘post_force’ method of fix_pimd.cpp in USER-MISC (only for the case method=PIMD).
What I need is to store the forces that are acting on the atoms of the two adjacent replicas in such a way that they will be available within method ‘spring_force’, exactly as already implemented for the positions using “buf_beads”.
What is the best way of doing it?
I tried following what is already implemented for the positions, and did the two following main attempts.
(1)
I defined a new method ‘void mycomm_exec(double **, double **)’, which receives as second argument a pointer to the stored quantity.
I implemented it as ‘void FixMYPIMD::mycomm_exec(double **ptr, double **buffer)’, just a copy and paste of the original method ‘comm_exec’, changing everywhere “buf_beads” with “buffer”.
I defined a new public pointer “double **buf_force” and initialized following exactly what is done for “buf_beads”, both in the constructor and in method ‘comm_init’.
Finally, in method ‘post_force’ I call twice:
mycomm_exec(atom->x,buf_beads); //Store pos
mycomm_exec(atom->f,buf_force); //Store forces
Doing a single call, either for ‘f’ or ‘x’ gives the correct result, but when calling twice as above I get segmentation fault with “Signal code: Address not mapped”.
(2)
I also tried using the original ‘comm_exec’ twice and memcpy:
comm_exec(atom->f); //Store forces in buf_beads
memcpy(buf_force,buf_beads,sizeof(double)atom->nlocal3*size_plan); //Copy to buf_force
comm_exec(atom->x); //Store pos in buf_beads
In this case I noticed that “buf_beads” and “buf_force” end up pointing to the same block of memory.
I thought it would have been a straightforward modification following what already implemented, but at this point I think I am missing something fundamental, most probably about pointers.
I’m quite new to MPI and c++, any hint or suggestions will be of great help.
Thanks!
Best,
Davide