Skip to content
Snippets Groups Projects
Commit 4f709055 authored by fiskissimo's avatar fiskissimo Committed by Giovanni Bussi
Browse files

Fix: Segmentation fault whenever more than 2 CVs are used for METAD with 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
parent 8483822e
No related branches found
No related tags found
No related merge requests found
......@@ -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];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment