Skip to content
Snippets Groups Projects
Commit bff20f75 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Changed tolerance in lattice reduction

Lattice reduction is used in plumed to convert box to its
"least skewed" form. I changed a bit the threashold since it
was giving problems with high optimization flags.
Additionally, I added some warning when too many iterations
are performed (which indicates a numerical issue)
parent e02816d5
No related branches found
No related tags found
No related merge requests found
...@@ -21,10 +21,11 @@ ...@@ -21,10 +21,11 @@
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#include "Exception.h" #include "Exception.h"
#include "LatticeReduction.h" #include "LatticeReduction.h"
#include <stdio.h>
namespace PLMD{ namespace PLMD{
const double epsilon=1e-28; const double epsilon=1e-14;
void LatticeReduction::sort(Vector v[3]){ void LatticeReduction::sort(Vector v[3]){
for(int i=0;i<3;i++) for(int j=i+1;j<3;j++) if(modulo2(v[i])>modulo2(v[j])){ for(int i=0;i<3;i++) for(int j=i+1;j<3;j++) if(modulo2(v[i])>modulo2(v[j])){
...@@ -36,6 +37,7 @@ void LatticeReduction::sort(Vector v[3]){ ...@@ -36,6 +37,7 @@ void LatticeReduction::sort(Vector v[3]){
void LatticeReduction::reduce(Vector&a,Vector&b){ void LatticeReduction::reduce(Vector&a,Vector&b){
double ma=modulo2(a); double ma=modulo2(a);
double mb=modulo2(b); double mb=modulo2(b);
unsigned counter=0;
while(true){ while(true){
if(mb>ma){ if(mb>ma){
Vector t(a); a=b; b=t; Vector t(a); a=b; b=t;
...@@ -44,6 +46,8 @@ void LatticeReduction::reduce(Vector&a,Vector&b){ ...@@ -44,6 +46,8 @@ void LatticeReduction::reduce(Vector&a,Vector&b){
a-=b*floor(dotProduct(a,b)/modulo2(b)+0.5); a-=b*floor(dotProduct(a,b)/modulo2(b)+0.5);
ma=modulo2(a); ma=modulo2(a);
if(mb<=ma+epsilon) break; if(mb<=ma+epsilon) break;
counter++;
if(counter%10000==0) fprintf(stderr,"WARNING: LatticeReduction::reduce stuck after %u iterations\n",counter);
} }
Vector t(a); a=b; b=t; Vector t(a); a=b; b=t;
...@@ -100,6 +104,7 @@ void LatticeReduction::reduceFast(Tensor&t){ ...@@ -100,6 +104,7 @@ void LatticeReduction::reduceFast(Tensor&t){
v[0]=t.getRow(0); v[0]=t.getRow(0);
v[1]=t.getRow(1); v[1]=t.getRow(1);
v[2]=t.getRow(2); v[2]=t.getRow(2);
unsigned counter=0;
while(true){ while(true){
sort(v); sort(v);
reduce(v[0],v[1]); reduce(v[0],v[1]);
...@@ -129,6 +134,8 @@ void LatticeReduction::reduceFast(Tensor&t){ ...@@ -129,6 +134,8 @@ void LatticeReduction::reduceFast(Tensor&t){
} }
} }
if(modulo2(best)+epsilon>=modulo2(v[2])) break; if(modulo2(best)+epsilon>=modulo2(v[2])) break;
counter++;
if(counter%10000==0) fprintf(stderr,"WARNING: LatticeReduction::reduceFast stuck after %u iterations\n",counter);
v[2]=best; v[2]=best;
} }
sort(v); sort(v);
......
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