Skip to content

Commit

Permalink
Fix: Segmentation fault whenever more than 2 CVs are used for METAD w…
Browse files Browse the repository at this point in the history
…ith REWEIGHTING_NGRID #328

I tried to interpret and fix the code and for me it works nicely with 1 to 3 CVs.
Here a brief description: the index i spans through the whole reweghting-grid (according to the mpi rank in case of mpi).
rewf_grid_ contains the size on each dimension of the reweghting-grid. t_index is the array containing the coordinates of i in each dimension of the grid. The indexes had to be changed from i to j in line 1967, which indeed spans correctly the dimensions of the grid. In 1968 in order to get the correct index, we need to subtract the former index (ncv-2 -- instead of "ncv-1" which is yet not assigned -- from what is left of kk).

I didn't attempt any further test.

Please let me know if I had misinterpreted the code.

Fixes #399
  • Loading branch information
fiskissimo authored and GiovanniBussi committed Dec 17, 2018
1 parent 8483822 commit 4f70905
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bias/MetaD.cpp
Expand Up @@ -1542,8 +1542,8 @@ void MetaD::computeReweightingFactor()
for(unsigned i=rank; i<ntotgrid; i+=stride) {
t_index[0]=(i%rewf_grid_[0]);
unsigned kk=i;
for(unsigned j=1; j<ncv-1; ++j) { kk=(kk-t_index[j-1])/rewf_grid_[i-1]; t_index[j]=(kk%rewf_grid_[i]); }
if( ncv>=2 ) t_index[ncv-1]=((kk-t_index[ncv-1])/rewf_grid_[ncv-2]);
for(unsigned j=1; j<ncv-1; ++j) { kk=(kk-t_index[j-1])/rewf_grid_[j-1]; t_index[j]=(kk%rewf_grid_[j]); }
if( ncv>=2 ) t_index[ncv-1]=((kk-t_index[ncv-2])/rewf_grid_[ncv-2]);

for(unsigned j=0; j<ncv; ++j) vals[j]=dmin[j] + t_index[j]*grid_spacing[j];

Expand Down

0 comments on commit 4f70905

Please sign in to comment.