From 5c671c7fcffb689d66f67f8f3ac00b4f19523a65 Mon Sep 17 00:00:00 2001
From: carlocamilloni <carlo.camilloni@gmail.com>
Date: Wed, 17 Oct 2018 15:47:07 +0200
Subject: [PATCH] SAXSgpu: code cleaning and improvements but results are very
 different on cpu or opencl backends

---
 regtest/isdb/rt-saxs-gpu/colvar.reference  |   4 +-
 regtest/isdb/rt-saxs-gpu/colvarb.reference |   4 +-
 regtest/isdb/rt-saxs-gpu/config            |   2 +-
 regtest/isdb/rt-saxs-gpu/forcesb.reference |  84 ++++----
 regtest/isdb/rt-saxs-gpu/plumed.dat        |  69 ++++---
 src/isdb/SAXSgpu.cpp                       | 215 ++++++++-------------
 6 files changed, 162 insertions(+), 216 deletions(-)

diff --git a/regtest/isdb/rt-saxs-gpu/colvar.reference b/regtest/isdb/rt-saxs-gpu/colvar.reference
index 1f4b307bd..adde60419 100644
--- a/regtest/isdb/rt-saxs-gpu/colvar.reference
+++ b/regtest/isdb/rt-saxs-gpu/colvar.reference
@@ -1,2 +1,2 @@
-#! FIELDS time saxs.q_0 saxs.q_1 saxs.q_2 saxs.q_3 saxs.q_4 saxs.q_5 saxs.q_6 saxs.q_7 saxs.q_8 saxs.q_9 saxs.q_10 saxs.q_11 saxs.q_12 saxs.q_13 saxs.q_14 saxs.exp_0 saxs.exp_1 saxs.exp_2 saxs.exp_3 saxs.exp_4 saxs.exp_5 saxs.exp_6 saxs.exp_7 saxs.exp_8 saxs.exp_9 saxs.exp_10 saxs.exp_11 saxs.exp_12 saxs.exp_13 saxs.exp_14
- 0.000000 1.100661 0.863129 0.559587 0.317188 0.174275 0.100178 0.056937 0.028540 0.012530 0.006728 0.006786 0.008899 0.011032 0.012345 0.012590 1.090200 0.790632 0.453808 0.254737 0.154928 0.092150 0.052633 0.027656 0.012278 0.008806 0.013730 0.018004 0.019337 0.021013 0.022051
+#! FIELDS time saxs.q_0 saxs.q_1 saxs.q_2 saxs.q_3 saxs.q_4 saxs.q_5 saxs.q_6 saxs.q_7 saxs.q_8 saxs.q_9 saxs.q_10 saxs.q_11 saxs.q_12 saxs.q_13 saxs.q_14
+ 0.000000 1.100661 0.863129 0.559587 0.317188 0.174275 0.100178 0.056937 0.028540 0.012530 0.006728 0.006786 0.008899 0.011032 0.012345 0.012590
diff --git a/regtest/isdb/rt-saxs-gpu/colvarb.reference b/regtest/isdb/rt-saxs-gpu/colvarb.reference
index a05a42282..1bab43f0d 100644
--- a/regtest/isdb/rt-saxs-gpu/colvarb.reference
+++ b/regtest/isdb/rt-saxs-gpu/colvarb.reference
@@ -1,2 +1,2 @@
-#! FIELDS time saxsb.q_0 saxsb.q_1 saxsb.q_2 saxsb.q_3 saxsb.q_4 saxsb.q_5 saxsb.q_6 saxsb.q_7 saxsb.q_8 saxsb.q_9 saxsb.q_10 saxsb.q_11 saxsb.q_12 saxsb.q_13 saxsb.q_14 saxsb.exp_0 saxsb.exp_1 saxsb.exp_2 saxsb.exp_3 saxsb.exp_4 saxsb.exp_5 saxsb.exp_6 saxsb.exp_7 saxsb.exp_8 saxsb.exp_9 saxsb.exp_10 saxsb.exp_11 saxsb.exp_12 saxsb.exp_13 saxsb.exp_14
- 0.000000 1.100662 0.863129 0.559587 0.317188 0.174275 0.100178 0.056937 0.028540 0.012530 0.006728 0.006786 0.008899 0.011032 0.012345 0.012590 1.090200 0.790632 0.453808 0.254737 0.154928 0.092150 0.052633 0.027656 0.012278 0.008806 0.013730 0.018004 0.019337 0.021013 0.022051
+#! FIELDS time saxsb.q_0 saxsb.q_1 saxsb.q_2 saxsb.q_3 saxsb.q_4 saxsb.q_5 saxsb.q_6 saxsb.q_7 saxsb.q_8 saxsb.q_9 saxsb.q_10 saxsb.q_11 saxsb.q_12 saxsb.q_13 saxsb.q_14
+ 0.000000 1.100619 0.862867 0.558929 0.315979 0.172386 0.097516 0.053444 0.024199 0.007362 0.000791 0.000168 0.001715 0.003411 0.004427 0.004514
diff --git a/regtest/isdb/rt-saxs-gpu/config b/regtest/isdb/rt-saxs-gpu/config
index 7bf6e8db6..b7a61fc6b 100644
--- a/regtest/isdb/rt-saxs-gpu/config
+++ b/regtest/isdb/rt-saxs-gpu/config
@@ -1,4 +1,4 @@
-mpiprocs=4
+mpiprocs=1
 type=driver
 arg="--plumed plumed.dat --timestep 0.005 --mf_pdb template.pdb"
 plumed_needs="arrayfire"
diff --git a/regtest/isdb/rt-saxs-gpu/forcesb.reference b/regtest/isdb/rt-saxs-gpu/forcesb.reference
index fffca948e..ec909832d 100644
--- a/regtest/isdb/rt-saxs-gpu/forcesb.reference
+++ b/regtest/isdb/rt-saxs-gpu/forcesb.reference
@@ -9,7 +9,7 @@
  0.000000 7 -0.0003 -0.0013 -0.0016 -0.0010 -0.0004 -0.0004 -0.0005 -0.0004 -0.0003 -0.0003 -0.0001 0.0001 0.0001 -0.0001 -0.0002
  0.000000 8 -0.0001 -0.0006 -0.0009 -0.0008 -0.0006 -0.0004 -0.0003 -0.0002 -0.0002 -0.0003 -0.0003 -0.0002 -0.0002 -0.0003 -0.0003
  0.000000 9 -0.0002 -0.0009 -0.0008 -0.0001 0.0003 0.0000 -0.0001 0.0001 0.0003 0.0003 0.0002 0.0003 0.0003 0.0002 0.0001
- 0.000000 10 -0.0004 -0.0017 -0.0021 -0.0014 -0.0007 -0.0007 -0.0008 -0.0006 -0.0005 -0.0004 -0.0003 -0.0000 0.0000 -0.0001 -0.0003
+ 0.000000 10 -0.0004 -0.0017 -0.0021 -0.0014 -0.0007 -0.0007 -0.0008 -0.0006 -0.0005 -0.0004 -0.0003 -0.0000 0.0001 -0.0001 -0.0003
  0.000000 11 -0.0001 -0.0005 -0.0008 -0.0008 -0.0005 -0.0003 -0.0001 -0.0000 0.0000 -0.0000 0.0000 0.0001 0.0001 0.0001 0.0001
  0.000000 12 -0.0001 -0.0003 -0.0002 -0.0000 0.0001 -0.0000 -0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000
  0.000000 13 -0.0001 -0.0005 -0.0007 -0.0004 -0.0002 -0.0002 -0.0002 -0.0002 -0.0001 -0.0001 -0.0001 -0.0000 -0.0001 -0.0002 -0.0002
@@ -25,7 +25,7 @@
  0.000000 23 -0.0000 -0.0002 -0.0004 -0.0004 -0.0003 -0.0002 -0.0001 -0.0001 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
  0.000000 24 -0.0001 -0.0003 -0.0002 0.0002 0.0005 0.0005 0.0003 0.0002 0.0002 0.0002 0.0002 0.0001 0.0001 0.0000 0.0000
  0.000000 25 -0.0002 -0.0009 -0.0014 -0.0011 -0.0006 -0.0004 -0.0004 -0.0004 -0.0004 -0.0003 -0.0002 -0.0001 0.0000 0.0002 0.0001
- 0.000000 26 -0.0000 -0.0002 -0.0003 -0.0003 -0.0003 -0.0001 -0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001
+ 0.000000 26 -0.0000 -0.0001 -0.0003 -0.0003 -0.0003 -0.0001 -0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001
  0.000000 27 -0.0002 -0.0009 -0.0010 -0.0004 0.0002 0.0002 -0.0001 -0.0001 0.0002 0.0003 0.0003 0.0003 0.0004 0.0004 0.0003
  0.000000 28 -0.0003 -0.0014 -0.0021 -0.0017 -0.0009 -0.0006 -0.0006 -0.0006 -0.0004 -0.0003 -0.0003 -0.0002 0.0001 0.0003 0.0004
  0.000000 29 -0.0001 -0.0005 -0.0008 -0.0009 -0.0009 -0.0007 -0.0004 -0.0002 -0.0001 -0.0001 -0.0001 -0.0000 0.0000 0.0001 0.0002
@@ -93,7 +93,7 @@
  0.000000 91 -0.0002 -0.0007 -0.0011 -0.0008 -0.0004 -0.0002 -0.0002 -0.0001 0.0001 0.0002 0.0002 0.0002 0.0001 0.0000 -0.0001
  0.000000 92 0.0000 0.0000 0.0000 -0.0001 -0.0001 -0.0001 0.0000 0.0002 0.0003 0.0004 0.0004 0.0004 0.0002 0.0001 -0.0000
  0.000000 93 -0.0003 -0.0013 -0.0020 -0.0018 -0.0013 -0.0011 -0.0012 -0.0012 -0.0008 -0.0003 0.0000 0.0002 0.0004 0.0006 0.0006
- 0.000000 94 -0.0001 -0.0007 -0.0009 -0.0007 -0.0001 0.0002 0.0002 0.0002 0.0003 0.0003 0.0003 0.0002 0.0002 0.0002 0.0001
+ 0.000000 94 -0.0001 -0.0007 -0.0009 -0.0007 -0.0001 0.0002 0.0003 0.0002 0.0003 0.0003 0.0003 0.0002 0.0002 0.0002 0.0001
  0.000000 95 0.0000 -0.0000 -0.0001 -0.0003 -0.0004 -0.0005 -0.0004 -0.0002 0.0000 0.0002 0.0003 0.0004 0.0004 0.0003 0.0002
  0.000000 96 -0.0002 -0.0011 -0.0017 -0.0015 -0.0011 -0.0010 -0.0011 -0.0009 -0.0005 -0.0002 -0.0001 -0.0001 -0.0001 -0.0002 -0.0003
  0.000000 97 -0.0001 -0.0005 -0.0006 -0.0003 0.0001 0.0003 0.0003 0.0003 0.0003 0.0003 0.0002 0.0001 0.0000 0.0000 0.0000
@@ -139,7 +139,7 @@
  0.000000 137 0.0000 0.0001 0.0001 0.0001 0.0001 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001 -0.0000 0.0000 0.0001 0.0002 0.0003
  0.000000 138 -0.0002 -0.0010 -0.0018 -0.0020 -0.0015 -0.0008 -0.0003 -0.0000 0.0001 0.0003 0.0005 0.0007 0.0007 0.0006 0.0005
  0.000000 139 0.0001 0.0007 0.0014 0.0018 0.0019 0.0015 0.0009 0.0004 0.0001 -0.0000 0.0000 0.0002 0.0003 0.0005 0.0005
- 0.000000 140 0.0000 -0.0000 -0.0001 -0.0002 -0.0004 -0.0006 -0.0006 -0.0005 -0.0003 -0.0001 0.0000 0.0001 0.0001 0.0001 0.0001
+ 0.000000 140 0.0000 0.0000 -0.0001 -0.0002 -0.0004 -0.0006 -0.0006 -0.0005 -0.0003 -0.0001 0.0000 0.0001 0.0001 0.0001 0.0001
  0.000000 141 0.0001 0.0003 0.0006 0.0007 0.0005 0.0003 0.0001 0.0000 0.0000 -0.0000 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001
  0.000000 142 -0.0000 -0.0003 -0.0005 -0.0007 -0.0007 -0.0005 -0.0003 -0.0001 -0.0000 0.0000 0.0000 -0.0000 -0.0001 -0.0001 -0.0001
  0.000000 143 -0.0000 -0.0000 0.0000 0.0001 0.0001 0.0002 0.0002 0.0002 0.0001 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000
@@ -180,7 +180,7 @@
  0.000000 178 -0.0000 -0.0001 -0.0000 0.0000 0.0002 0.0002 0.0002 0.0001 0.0000 -0.0000 -0.0001 -0.0001 0.0000 0.0001 0.0001
  0.000000 179 0.0000 0.0000 0.0000 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001 -0.0000 -0.0000 0.0000 0.0001 0.0001 0.0001 0.0000
  0.000000 180 -0.0003 -0.0013 -0.0021 -0.0019 -0.0014 -0.0012 -0.0013 -0.0012 -0.0008 -0.0003 0.0001 0.0004 0.0006 0.0008 0.0007
- 0.000000 181 -0.0001 -0.0004 -0.0005 -0.0002 0.0002 0.0004 0.0003 0.0001 -0.0001 -0.0002 -0.0001 -0.0001 0.0001 0.0002 0.0003
+ 0.000000 181 -0.0001 -0.0004 -0.0005 -0.0002 0.0003 0.0004 0.0003 0.0001 -0.0001 -0.0002 -0.0001 -0.0001 0.0001 0.0002 0.0003
  0.000000 182 0.0001 0.0004 0.0006 0.0006 0.0004 0.0003 0.0003 0.0002 0.0001 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
  0.000000 183 0.0001 0.0005 0.0007 0.0007 0.0004 0.0003 0.0003 0.0003 0.0002 0.0001 -0.0000 -0.0001 -0.0002 -0.0002 -0.0002
  0.000000 184 0.0000 0.0001 0.0002 0.0001 -0.0001 -0.0002 -0.0002 -0.0001 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000
@@ -220,7 +220,7 @@
  0.000000 218 0.0001 0.0006 0.0010 0.0012 0.0011 0.0010 0.0010 0.0010 0.0008 0.0004 0.0001 -0.0002 -0.0004 -0.0005 -0.0006
  0.000000 219 -0.0002 -0.0008 -0.0010 -0.0006 -0.0000 0.0001 -0.0002 -0.0004 -0.0004 -0.0002 -0.0002 -0.0001 -0.0000 0.0000 -0.0000
  0.000000 220 -0.0002 -0.0010 -0.0015 -0.0014 -0.0010 -0.0008 -0.0009 -0.0008 -0.0006 -0.0003 -0.0001 -0.0000 0.0001 0.0001 0.0000
- 0.000000 221 0.0001 0.0006 0.0010 0.0012 0.0011 0.0011 0.0011 0.0010 0.0007 0.0003 -0.0001 -0.0003 -0.0004 -0.0003 -0.0002
+ 0.000000 221 0.0001 0.0006 0.0010 0.0012 0.0011 0.0011 0.0011 0.0010 0.0007 0.0003 -0.0001 -0.0003 -0.0003 -0.0003 -0.0002
  0.000000 222 -0.0001 -0.0005 -0.0006 -0.0002 0.0006 0.0011 0.0010 0.0006 0.0001 -0.0002 -0.0003 -0.0005 -0.0005 -0.0005 -0.0003
  0.000000 223 -0.0002 -0.0010 -0.0017 -0.0018 -0.0013 -0.0008 -0.0006 -0.0006 -0.0005 -0.0003 0.0000 0.0002 0.0002 0.0002 0.0003
  0.000000 224 0.0001 0.0006 0.0011 0.0014 0.0013 0.0011 0.0009 0.0008 0.0006 0.0003 0.0000 -0.0002 -0.0003 -0.0003 -0.0004
@@ -252,7 +252,7 @@
  0.000000 250 0.0000 0.0002 0.0003 0.0002 0.0001 0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001
  0.000000 251 -0.0000 -0.0002 -0.0003 -0.0003 -0.0003 -0.0002 -0.0002 -0.0001 -0.0001 -0.0000 0.0000 0.0001 0.0001 0.0001 0.0001
  0.000000 252 -0.0001 -0.0007 -0.0011 -0.0009 -0.0002 0.0003 0.0004 0.0002 -0.0000 -0.0001 -0.0000 -0.0001 -0.0002 -0.0003 -0.0002
- 0.000000 253 -0.0001 -0.0003 -0.0005 -0.0004 -0.0001 0.0002 0.0002 0.0001 -0.0001 -0.0001 -0.0000 -0.0000 -0.0001 -0.0001 -0.0001
+ 0.000000 253 -0.0001 -0.0003 -0.0005 -0.0004 -0.0001 0.0002 0.0002 0.0001 -0.0001 -0.0001 -0.0000 -0.0000 -0.0000 -0.0001 -0.0001
  0.000000 254 0.0002 0.0009 0.0017 0.0020 0.0019 0.0015 0.0011 0.0008 0.0005 0.0001 -0.0003 -0.0007 -0.0008 -0.0009 -0.0009
  0.000000 255 0.0000 0.0001 0.0002 0.0001 -0.0000 -0.0002 -0.0002 -0.0001 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000
  0.000000 256 0.0000 0.0001 0.0001 0.0001 0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000
@@ -343,9 +343,9 @@
  0.000000 341 0.0001 0.0006 0.0013 0.0017 0.0017 0.0012 0.0007 0.0002 -0.0001 -0.0002 -0.0004 -0.0005 -0.0005 -0.0005 -0.0004
  0.000000 342 -0.0001 -0.0003 -0.0005 -0.0003 0.0001 0.0006 0.0009 0.0008 0.0005 0.0001 -0.0001 -0.0003 -0.0004 -0.0005 -0.0005
  0.000000 343 -0.0000 -0.0002 -0.0003 -0.0003 -0.0001 0.0001 0.0002 0.0003 0.0002 0.0001 0.0000 0.0000 -0.0000 -0.0001 -0.0001
- 0.000000 344 0.0001 0.0005 0.0011 0.0014 0.0014 0.0011 0.0007 0.0003 0.0001 -0.0001 -0.0003 -0.0005 -0.0006 -0.0007 -0.0006
+ 0.000000 344 0.0001 0.0006 0.0011 0.0014 0.0014 0.0011 0.0007 0.0003 0.0001 -0.0001 -0.0003 -0.0005 -0.0006 -0.0007 -0.0006
  0.000000 345 -0.0001 -0.0003 -0.0006 -0.0006 -0.0002 0.0003 0.0007 0.0008 0.0005 0.0001 -0.0003 -0.0006 -0.0007 -0.0006 -0.0004
- 0.000000 346 -0.0000 -0.0000 0.0000 0.0001 0.0003 0.0004 0.0004 0.0004 0.0003 0.0001 -0.0001 -0.0003 -0.0004 -0.0003 -0.0002
+ 0.000000 346 -0.0000 0.0000 0.0000 0.0001 0.0003 0.0004 0.0004 0.0004 0.0003 0.0001 -0.0001 -0.0003 -0.0004 -0.0003 -0.0002
  0.000000 347 0.0001 0.0004 0.0008 0.0010 0.0009 0.0006 0.0002 -0.0001 -0.0003 -0.0003 -0.0003 -0.0003 -0.0003 -0.0003 -0.0002
  0.000000 348 0.0000 0.0000 0.0000 0.0000 -0.0001 -0.0002 -0.0002 -0.0002 -0.0001 -0.0000 0.0000 0.0001 0.0001 0.0000 -0.0000
  0.000000 349 0.0000 0.0000 0.0001 0.0001 0.0001 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000
@@ -355,7 +355,7 @@
  0.000000 353 0.0002 0.0009 0.0019 0.0026 0.0026 0.0020 0.0011 0.0003 -0.0001 -0.0002 -0.0001 -0.0000 -0.0000 -0.0001 -0.0002
  0.000000 354 -0.0001 -0.0005 -0.0008 -0.0007 -0.0002 0.0004 0.0008 0.0009 0.0005 0.0001 -0.0003 -0.0006 -0.0008 -0.0009 -0.0009
  0.000000 355 -0.0000 -0.0002 -0.0004 -0.0003 -0.0001 0.0002 0.0004 0.0005 0.0005 0.0003 0.0002 0.0001 -0.0001 -0.0002 -0.0003
- 0.000000 356 0.0000 0.0002 0.0004 0.0005 0.0004 0.0001 -0.0002 -0.0004 -0.0005 -0.0004 -0.0002 -0.0001 -0.0000 0.0001 0.0002
+ 0.000000 356 0.0000 0.0002 0.0004 0.0005 0.0004 0.0001 -0.0002 -0.0004 -0.0005 -0.0004 -0.0002 -0.0001 0.0000 0.0001 0.0002
  0.000000 357 0.0001 0.0003 0.0004 0.0004 0.0002 -0.0001 -0.0002 -0.0002 -0.0001 -0.0000 0.0000 0.0001 0.0001 0.0001 0.0001
  0.000000 358 0.0000 0.0001 0.0002 0.0001 0.0000 -0.0001 -0.0002 -0.0002 -0.0001 -0.0001 -0.0000 -0.0000 0.0000 0.0001 0.0001
  0.000000 359 -0.0000 -0.0002 -0.0003 -0.0003 -0.0003 -0.0002 -0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000
@@ -392,22 +392,22 @@
  0.000000 390 -0.0000 -0.0001 -0.0001 -0.0001 0.0000 0.0002 0.0002 0.0001 0.0000 -0.0001 -0.0001 -0.0001 0.0000 0.0001 0.0002
  0.000000 391 -0.0000 -0.0001 -0.0002 -0.0003 -0.0002 -0.0001 0.0000 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000 0.0001 0.0001
  0.000000 392 -0.0000 -0.0002 -0.0004 -0.0006 -0.0006 -0.0006 -0.0004 -0.0002 -0.0001 0.0000 0.0000 -0.0000 -0.0001 -0.0002 -0.0002
- 0.000000 393 -0.0000 -0.0001 -0.0000 0.0002 0.0006 0.0010 0.0011 0.0010 0.0006 0.0001 -0.0003 -0.0005 -0.0005 -0.0002 0.0001
+ 0.000000 393 -0.0000 -0.0000 -0.0000 0.0002 0.0006 0.0010 0.0011 0.0010 0.0006 0.0001 -0.0003 -0.0005 -0.0005 -0.0002 0.0001
  0.000000 394 -0.0001 -0.0004 -0.0008 -0.0010 -0.0010 -0.0008 -0.0004 -0.0000 0.0003 0.0004 0.0004 0.0003 0.0002 0.0001 0.0001
  0.000000 395 0.0000 0.0000 0.0000 -0.0000 -0.0001 -0.0003 -0.0004 -0.0004 -0.0003 -0.0002 -0.0000 0.0001 0.0001 0.0000 -0.0001
  0.000000 396 0.0000 0.0000 0.0001 0.0001 0.0002 0.0003 0.0003 0.0003 0.0001 -0.0000 -0.0002 -0.0003 -0.0003 -0.0001 0.0000
  0.000000 397 -0.0000 -0.0001 -0.0001 -0.0002 -0.0004 -0.0004 -0.0004 -0.0003 -0.0001 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
  0.000000 398 -0.0000 -0.0000 -0.0001 -0.0001 -0.0002 -0.0003 -0.0003 -0.0002 -0.0001 -0.0000 0.0001 0.0001 0.0001 0.0001 0.0001
  0.000000 399 -0.0000 -0.0002 -0.0002 0.0001 0.0006 0.0012 0.0015 0.0013 0.0008 0.0002 -0.0003 -0.0006 -0.0006 -0.0005 -0.0003
- 0.000000 400 -0.0001 -0.0005 -0.0010 -0.0012 -0.0011 -0.0007 -0.0002 0.0002 0.0004 0.0005 0.0005 0.0005 0.0004 0.0004 0.0003
+ 0.000000 400 -0.0001 -0.0005 -0.0010 -0.0012 -0.0011 -0.0007 -0.0002 0.0002 0.0004 0.0005 0.0005 0.0005 0.0005 0.0004 0.0003
  0.000000 401 0.0000 0.0002 0.0004 0.0005 0.0004 0.0001 -0.0001 -0.0003 -0.0003 -0.0002 -0.0001 0.0000 0.0000 -0.0000 -0.0000
  0.000000 402 0.0000 0.0002 0.0002 0.0001 -0.0001 -0.0004 -0.0005 -0.0004 -0.0002 -0.0000 0.0001 0.0002 0.0002 0.0002 0.0002
  0.000000 403 0.0000 0.0002 0.0004 0.0005 0.0004 0.0002 -0.0000 -0.0001 -0.0001 -0.0001 -0.0002 -0.0002 -0.0001 -0.0001 -0.0001
  0.000000 404 -0.0000 -0.0000 -0.0001 -0.0001 0.0000 0.0001 0.0001 0.0002 0.0001 0.0001 0.0000 -0.0000 -0.0000 -0.0001 -0.0001
  0.000000 405 -0.0000 0.0000 0.0002 0.0006 0.0011 0.0015 0.0016 0.0013 0.0008 0.0002 -0.0001 -0.0001 0.0001 0.0003 0.0004
  0.000000 406 -0.0001 -0.0006 -0.0013 -0.0016 -0.0015 -0.0010 -0.0004 0.0001 0.0003 0.0004 0.0003 0.0003 0.0003 0.0003 0.0002
- 0.000000 407 0.0001 0.0004 0.0008 0.0010 0.0010 0.0006 0.0003 -0.0000 -0.0001 -0.0001 0.0000 0.0001 0.0001 -0.0000 -0.0000
- 0.000000 408 0.0000 0.0001 0.0004 0.0007 0.0011 0.0012 0.0012 0.0009 0.0005 0.0002 0.0001 0.0002 0.0004 0.0006 0.0007
+ 0.000000 407 0.0001 0.0004 0.0008 0.0010 0.0010 0.0007 0.0003 -0.0000 -0.0001 -0.0001 0.0000 0.0001 0.0001 -0.0000 -0.0000
+ 0.000000 408 0.0000 0.0001 0.0004 0.0007 0.0011 0.0013 0.0012 0.0009 0.0005 0.0002 0.0001 0.0002 0.0004 0.0006 0.0007
  0.000000 409 -0.0001 -0.0006 -0.0012 -0.0015 -0.0015 -0.0011 -0.0005 0.0000 0.0003 0.0004 0.0002 0.0001 -0.0000 -0.0000 0.0001
  0.000000 410 0.0000 0.0001 0.0002 0.0002 0.0001 -0.0000 -0.0001 -0.0002 -0.0002 -0.0001 0.0000 0.0000 0.0000 -0.0000 -0.0001
  0.000000 411 -0.0000 -0.0000 0.0001 0.0006 0.0012 0.0016 0.0016 0.0012 0.0006 0.0001 0.0000 0.0001 0.0003 0.0004 0.0004
@@ -417,9 +417,9 @@
  0.000000 415 -0.0001 -0.0005 -0.0010 -0.0011 -0.0009 -0.0005 -0.0002 0.0000 0.0001 0.0001 0.0002 0.0003 0.0003 0.0001 -0.0000
  0.000000 416 0.0001 0.0007 0.0014 0.0018 0.0017 0.0013 0.0007 0.0003 0.0002 0.0001 0.0001 -0.0000 -0.0001 -0.0000 0.0001
  0.000000 417 -0.0000 -0.0001 0.0000 0.0005 0.0011 0.0016 0.0015 0.0011 0.0005 0.0001 -0.0000 0.0000 0.0002 0.0002 0.0002
- 0.000000 418 -0.0002 -0.0009 -0.0017 -0.0019 -0.0016 -0.0009 -0.0003 -0.0001 -0.0001 -0.0001 0.0000 0.0001 -0.0000 -0.0002 -0.0004
+ 0.000000 418 -0.0002 -0.0009 -0.0017 -0.0019 -0.0016 -0.0009 -0.0003 -0.0001 -0.0001 -0.0001 0.0000 0.0001 0.0000 -0.0002 -0.0004
  0.000000 419 0.0001 0.0005 0.0010 0.0012 0.0011 0.0008 0.0004 0.0003 0.0002 0.0002 0.0001 0.0001 0.0000 0.0001 0.0002
- 0.000000 420 -0.0001 -0.0003 -0.0002 0.0002 0.0010 0.0016 0.0017 0.0013 0.0006 0.0001 -0.0002 -0.0004 -0.0004 -0.0005 -0.0005
+ 0.000000 420 -0.0001 -0.0002 -0.0002 0.0002 0.0010 0.0016 0.0017 0.0013 0.0006 0.0001 -0.0002 -0.0004 -0.0004 -0.0005 -0.0005
  0.000000 421 -0.0002 -0.0009 -0.0017 -0.0019 -0.0016 -0.0009 -0.0004 -0.0001 -0.0000 0.0001 0.0002 0.0004 0.0004 0.0002 0.0001
  0.000000 422 0.0001 0.0003 0.0006 0.0008 0.0007 0.0004 0.0002 0.0001 0.0001 0.0001 0.0001 -0.0000 -0.0001 -0.0001 -0.0000
  0.000000 423 0.0000 0.0000 -0.0000 -0.0001 -0.0003 -0.0004 -0.0004 -0.0003 -0.0001 -0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000
@@ -491,7 +491,7 @@
  0.000000 489 -0.0001 -0.0004 -0.0006 -0.0004 -0.0003 -0.0002 -0.0003 -0.0003 -0.0002 -0.0001 -0.0001 -0.0001 -0.0001 -0.0001 -0.0000
  0.000000 490 -0.0001 -0.0002 -0.0003 -0.0002 -0.0000 0.0001 0.0001 0.0001 0.0002 0.0002 0.0001 0.0000 -0.0000 -0.0000 -0.0000
  0.000000 491 -0.0000 -0.0001 -0.0003 -0.0004 -0.0004 -0.0003 -0.0003 -0.0002 -0.0001 -0.0000 -0.0001 -0.0001 -0.0002 -0.0002 -0.0002
- 0.000000 492 -0.0002 -0.0012 -0.0019 -0.0017 -0.0011 -0.0007 -0.0006 -0.0006 -0.0004 -0.0000 0.0002 0.0002 0.0001 -0.0000 -0.0000
+ 0.000000 492 -0.0002 -0.0012 -0.0019 -0.0017 -0.0011 -0.0006 -0.0006 -0.0006 -0.0004 -0.0000 0.0002 0.0002 0.0001 -0.0000 -0.0000
  0.000000 493 -0.0001 -0.0005 -0.0007 -0.0005 0.0001 0.0006 0.0008 0.0007 0.0006 0.0005 0.0003 0.0001 -0.0001 -0.0002 -0.0002
  0.000000 494 -0.0001 -0.0004 -0.0008 -0.0012 -0.0014 -0.0014 -0.0013 -0.0010 -0.0006 -0.0002 0.0001 0.0002 0.0002 0.0001 -0.0001
  0.000000 495 -0.0002 -0.0009 -0.0014 -0.0012 -0.0006 -0.0002 -0.0002 -0.0002 -0.0001 0.0001 0.0001 -0.0000 -0.0002 -0.0003 -0.0002
@@ -503,7 +503,7 @@
  0.000000 501 -0.0001 -0.0003 -0.0004 -0.0004 -0.0002 0.0000 0.0001 0.0001 0.0000 0.0000 0.0001 0.0001 0.0001 0.0000 0.0000
  0.000000 502 -0.0000 -0.0002 -0.0003 -0.0002 -0.0001 0.0001 0.0002 0.0003 0.0003 0.0002 0.0002 0.0001 0.0001 -0.0000 -0.0001
  0.000000 503 -0.0000 -0.0001 -0.0003 -0.0004 -0.0005 -0.0005 -0.0005 -0.0004 -0.0003 -0.0001 0.0000 0.0001 0.0002 0.0002 0.0001
- 0.000000 504 -0.0002 -0.0010 -0.0017 -0.0017 -0.0012 -0.0005 -0.0001 -0.0001 0.0000 0.0002 0.0004 0.0005 0.0005 0.0003 0.0000
+ 0.000000 504 -0.0002 -0.0010 -0.0017 -0.0017 -0.0011 -0.0005 -0.0001 -0.0001 0.0000 0.0002 0.0004 0.0005 0.0005 0.0003 0.0000
  0.000000 505 -0.0000 -0.0002 -0.0002 0.0001 0.0005 0.0009 0.0010 0.0008 0.0005 0.0002 -0.0000 -0.0002 -0.0002 -0.0002 -0.0002
  0.000000 506 -0.0001 -0.0004 -0.0008 -0.0013 -0.0016 -0.0016 -0.0015 -0.0012 -0.0007 -0.0002 0.0002 0.0005 0.0005 0.0003 0.0000
  0.000000 507 -0.0000 -0.0002 -0.0004 -0.0004 -0.0003 -0.0001 -0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 -0.0001
@@ -566,13 +566,13 @@
  0.000000 564 -0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
  0.000000 565 -0.0000 -0.0002 -0.0003 -0.0004 -0.0003 -0.0002 -0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
  0.000000 566 -0.0000 -0.0002 -0.0004 -0.0005 -0.0005 -0.0004 -0.0002 -0.0001 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
- 0.000000 567 0.0001 0.0002 0.0004 0.0003 0.0001 0.0000 0.0001 0.0002 0.0002 0.0002 0.0003 0.0004 0.0005 0.0007 0.0006
+ 0.000000 567 0.0001 0.0002 0.0004 0.0003 0.0001 0.0000 0.0001 0.0002 0.0002 0.0002 0.0003 0.0004 0.0006 0.0007 0.0006
  0.000000 568 0.0002 0.0009 0.0017 0.0018 0.0013 0.0006 0.0001 -0.0002 -0.0003 -0.0002 -0.0001 -0.0001 -0.0001 -0.0003 -0.0003
  0.000000 569 0.0003 0.0015 0.0029 0.0036 0.0034 0.0024 0.0012 0.0003 -0.0001 0.0000 0.0004 0.0006 0.0005 0.0002 -0.0000
  0.000000 570 0.0000 -0.0000 -0.0002 -0.0004 -0.0006 -0.0006 -0.0004 -0.0002 -0.0001 -0.0001 -0.0002 -0.0003 -0.0004 -0.0003 -0.0002
  0.000000 571 0.0002 0.0010 0.0018 0.0021 0.0017 0.0011 0.0005 0.0001 -0.0001 -0.0001 0.0001 0.0002 0.0002 0.0002 0.0003
  0.000000 572 0.0001 0.0005 0.0010 0.0013 0.0013 0.0010 0.0007 0.0004 0.0002 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000
- 0.000000 573 0.0000 0.0001 0.0001 -0.0001 -0.0005 -0.0007 -0.0007 -0.0004 -0.0001 0.0001 0.0002 0.0001 -0.0000 -0.0002 -0.0002
+ 0.000000 573 0.0000 0.0002 0.0001 -0.0001 -0.0005 -0.0007 -0.0007 -0.0004 -0.0001 0.0001 0.0002 0.0001 -0.0000 -0.0002 -0.0002
  0.000000 574 0.0002 0.0010 0.0017 0.0020 0.0017 0.0011 0.0006 0.0002 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001 -0.0001 0.0001
  0.000000 575 0.0001 0.0004 0.0007 0.0010 0.0011 0.0010 0.0008 0.0006 0.0003 0.0001 -0.0000 0.0000 0.0001 0.0001 0.0002
  0.000000 576 0.0001 0.0002 0.0002 -0.0002 -0.0007 -0.0009 -0.0009 -0.0005 -0.0001 0.0002 0.0003 0.0001 -0.0001 -0.0003 -0.0004
@@ -580,9 +580,9 @@
  0.000000 578 0.0000 0.0002 0.0004 0.0006 0.0007 0.0007 0.0007 0.0005 0.0002 0.0000 -0.0001 -0.0001 -0.0001 0.0000 0.0001
  0.000000 579 0.0000 -0.0000 -0.0001 -0.0003 -0.0006 -0.0006 -0.0006 -0.0004 -0.0002 -0.0001 -0.0002 -0.0003 -0.0005 -0.0006 -0.0006
  0.000000 580 0.0001 0.0006 0.0012 0.0014 0.0012 0.0008 0.0004 0.0002 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0001
- 0.000000 581 0.0000 0.0000 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0001 -0.0000 -0.0001 -0.0001 -0.0002 -0.0001 -0.0001
+ 0.000000 581 0.0000 0.0000 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0001 -0.0000 -0.0001 -0.0001 -0.0002 -0.0001 -0.0001
  0.000000 582 0.0001 0.0004 0.0006 0.0002 -0.0004 -0.0008 -0.0008 -0.0004 0.0001 0.0005 0.0007 0.0006 0.0003 0.0001 -0.0000
- 0.000000 583 0.0002 0.0011 0.0020 0.0022 0.0018 0.0013 0.0009 0.0006 0.0003 0.0000 -0.0003 -0.0005 -0.0006 -0.0004 -0.0000
+ 0.000000 583 0.0002 0.0012 0.0020 0.0022 0.0018 0.0013 0.0009 0.0006 0.0003 0.0000 -0.0003 -0.0005 -0.0006 -0.0004 -0.0000
  0.000000 584 0.0000 0.0002 0.0004 0.0006 0.0007 0.0008 0.0008 0.0006 0.0003 0.0000 -0.0001 -0.0002 -0.0001 0.0000 0.0001
  0.000000 585 0.0001 0.0004 0.0004 0.0001 -0.0004 -0.0006 -0.0004 -0.0001 0.0002 0.0004 0.0004 0.0002 0.0001 -0.0000 -0.0002
  0.000000 586 0.0002 0.0011 0.0018 0.0018 0.0015 0.0011 0.0008 0.0005 0.0002 0.0000 -0.0001 -0.0000 0.0002 0.0006 0.0007
@@ -688,11 +688,11 @@
  0.000000 686 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0001 -0.0001 -0.0001 -0.0000 0.0000 0.0001 0.0001 0.0001 0.0001
  0.000000 687 0.0000 0.0002 0.0003 0.0001 -0.0002 -0.0006 -0.0007 -0.0006 -0.0003 0.0000 0.0004 0.0006 0.0006 0.0004 0.0002
  0.000000 688 0.0001 0.0006 0.0011 0.0013 0.0010 0.0005 0.0001 -0.0003 -0.0004 -0.0004 -0.0003 -0.0002 -0.0001 -0.0002 -0.0003
- 0.000000 689 0.0000 0.0001 0.0002 0.0003 0.0004 0.0004 0.0004 0.0004 0.0003 0.0001 -0.0001 -0.0002 -0.0003 -0.0003 -0.0002
+ 0.000000 689 0.0000 0.0001 0.0002 0.0003 0.0004 0.0004 0.0005 0.0004 0.0003 0.0001 -0.0001 -0.0002 -0.0003 -0.0003 -0.0002
  0.000000 690 0.0000 0.0001 0.0002 0.0001 -0.0001 -0.0003 -0.0003 -0.0002 -0.0001 0.0001 0.0003 0.0004 0.0004 0.0003 0.0003
  0.000000 691 0.0001 0.0005 0.0009 0.0011 0.0009 0.0005 0.0002 -0.0001 -0.0003 -0.0003 -0.0003 -0.0002 -0.0002 -0.0004 -0.0005
  0.000000 692 0.0001 0.0003 0.0007 0.0010 0.0011 0.0010 0.0008 0.0006 0.0003 0.0000 -0.0001 -0.0002 -0.0001 -0.0001 -0.0001
- 0.000000 693 0.0000 -0.0000 -0.0001 -0.0004 -0.0007 -0.0010 -0.0010 -0.0008 -0.0005 -0.0003 -0.0000 0.0001 0.0001 0.0000 -0.0001
+ 0.000000 693 0.0000 -0.0000 -0.0001 -0.0004 -0.0007 -0.0009 -0.0010 -0.0008 -0.0005 -0.0003 -0.0000 0.0001 0.0001 0.0000 -0.0001
  0.000000 694 0.0001 0.0007 0.0013 0.0015 0.0013 0.0008 0.0002 -0.0002 -0.0004 -0.0004 -0.0003 -0.0001 0.0001 0.0001 0.0000
  0.000000 695 -0.0000 -0.0002 -0.0003 -0.0005 -0.0005 -0.0004 -0.0002 -0.0000 0.0001 0.0001 0.0000 -0.0001 -0.0001 -0.0000 0.0001
  0.000000 696 -0.0000 -0.0000 0.0000 0.0001 0.0002 0.0003 0.0002 0.0002 0.0001 0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000
@@ -718,7 +718,7 @@
  0.000000 716 -0.0000 -0.0001 -0.0001 -0.0002 -0.0002 -0.0002 -0.0001 -0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 0.0000
  0.000000 717 0.0001 0.0006 0.0011 0.0012 0.0007 -0.0001 -0.0006 -0.0007 -0.0004 0.0001 0.0003 0.0004 0.0003 0.0002 0.0001
  0.000000 718 0.0000 0.0001 0.0000 -0.0003 -0.0008 -0.0013 -0.0015 -0.0013 -0.0008 -0.0002 0.0002 0.0006 0.0008 0.0009 0.0008
- 0.000000 719 -0.0001 -0.0004 -0.0008 -0.0011 -0.0011 -0.0008 -0.0004 -0.0000 0.0002 0.0003 0.0004 0.0005 0.0004 0.0003 0.0001
+ 0.000000 719 -0.0001 -0.0004 -0.0008 -0.0011 -0.0011 -0.0008 -0.0004 -0.0000 0.0002 0.0003 0.0004 0.0005 0.0005 0.0003 0.0001
  0.000000 720 -0.0001 -0.0003 -0.0004 -0.0004 -0.0001 0.0002 0.0003 0.0002 0.0001 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001 -0.0001
  0.000000 721 -0.0000 -0.0001 -0.0002 -0.0001 0.0001 0.0003 0.0004 0.0003 0.0002 0.0000 -0.0001 -0.0001 -0.0002 -0.0002 -0.0002
  0.000000 722 0.0000 0.0002 0.0004 0.0005 0.0005 0.0004 0.0002 0.0001 -0.0000 -0.0001 -0.0001 -0.0002 -0.0002 -0.0001 -0.0001
@@ -742,7 +742,7 @@
  0.000000 740 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0001 -0.0001 -0.0002 -0.0001 -0.0001 -0.0000 0.0000 0.0000 0.0000 0.0001
  0.000000 741 0.0002 0.0010 0.0017 0.0018 0.0011 0.0003 -0.0003 -0.0004 -0.0003 -0.0002 -0.0003 -0.0004 -0.0004 -0.0002 0.0002
  0.000000 742 0.0000 0.0001 0.0000 -0.0004 -0.0010 -0.0015 -0.0015 -0.0012 -0.0007 -0.0002 0.0003 0.0008 0.0010 0.0011 0.0010
- 0.000000 743 -0.0000 -0.0000 -0.0000 0.0001 0.0002 0.0004 0.0006 0.0006 0.0005 0.0002 0.0000 -0.0002 -0.0003 -0.0005 -0.0006
+ 0.000000 743 -0.0000 -0.0000 -0.0000 0.0001 0.0002 0.0005 0.0006 0.0006 0.0005 0.0002 0.0000 -0.0002 -0.0003 -0.0005 -0.0006
  0.000000 744 -0.0001 -0.0003 -0.0005 -0.0004 -0.0003 -0.0000 0.0001 0.0001 0.0000 0.0000 0.0001 0.0001 0.0000 0.0000 -0.0000
  0.000000 745 -0.0000 -0.0000 0.0000 0.0001 0.0003 0.0004 0.0004 0.0003 0.0001 0.0000 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001
  0.000000 746 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000
@@ -788,14 +788,14 @@
  0.000000 786 0.0001 0.0003 0.0005 0.0004 0.0002 -0.0000 -0.0001 -0.0001 -0.0000 -0.0000 -0.0001 -0.0001 -0.0002 -0.0002 -0.0001
  0.000000 787 0.0000 0.0001 0.0001 0.0000 -0.0001 -0.0002 -0.0001 -0.0001 0.0000 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000
  0.000000 788 0.0001 0.0003 0.0006 0.0007 0.0007 0.0005 0.0003 0.0001 -0.0001 -0.0001 -0.0001 0.0000 0.0001 0.0002 0.0002
- 0.000000 789 0.0003 0.0014 0.0021 0.0018 0.0009 0.0003 0.0001 0.0000 -0.0001 -0.0003 -0.0003 0.0000 0.0005 0.0008 0.0008
+ 0.000000 789 0.0003 0.0014 0.0021 0.0018 0.0010 0.0003 0.0001 0.0000 -0.0001 -0.0003 -0.0003 0.0000 0.0005 0.0008 0.0008
  0.000000 790 0.0001 0.0003 0.0003 -0.0001 -0.0006 -0.0007 -0.0005 -0.0003 -0.0000 0.0002 0.0003 0.0003 0.0003 0.0003 0.0003
  0.000000 791 0.0001 0.0006 0.0012 0.0015 0.0017 0.0016 0.0014 0.0009 0.0005 0.0001 -0.0001 -0.0001 -0.0001 -0.0000 -0.0000
  0.000000 792 0.0002 0.0011 0.0016 0.0012 0.0005 0.0001 0.0000 0.0000 -0.0001 -0.0002 -0.0001 0.0001 0.0004 0.0005 0.0003
  0.000000 793 0.0001 0.0004 0.0005 0.0002 -0.0001 -0.0002 -0.0001 0.0000 0.0001 0.0002 0.0002 0.0003 0.0003 0.0003 0.0003
  0.000000 794 0.0001 0.0006 0.0012 0.0014 0.0015 0.0013 0.0010 0.0006 0.0002 0.0000 -0.0000 0.0000 0.0001 0.0001 0.0000
  0.000000 795 0.0003 0.0014 0.0021 0.0018 0.0010 0.0005 0.0003 0.0003 0.0000 -0.0002 -0.0002 0.0001 0.0006 0.0008 0.0006
- 0.000000 796 0.0001 0.0002 0.0002 -0.0003 -0.0007 -0.0008 -0.0006 -0.0004 -0.0002 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001
+ 0.000000 796 0.0001 0.0002 0.0002 -0.0003 -0.0007 -0.0008 -0.0006 -0.0004 -0.0002 0.0000 0.0001 0.0001 0.0002 0.0001 0.0001
  0.000000 797 0.0001 0.0004 0.0007 0.0010 0.0012 0.0012 0.0011 0.0008 0.0005 0.0003 0.0001 -0.0000 -0.0001 -0.0001 -0.0002
  0.000000 798 0.0003 0.0014 0.0022 0.0020 0.0012 0.0006 0.0005 0.0004 0.0001 -0.0004 -0.0006 -0.0004 -0.0001 0.0002 0.0002
  0.000000 799 0.0001 0.0003 0.0003 -0.0002 -0.0007 -0.0008 -0.0007 -0.0004 -0.0002 -0.0001 0.0001 0.0002 0.0002 0.0003 0.0002
@@ -823,7 +823,7 @@
  0.000000 821 -0.0001 -0.0003 -0.0006 -0.0005 -0.0003 -0.0001 -0.0001 -0.0001 -0.0002 -0.0001 -0.0001 -0.0001 -0.0000 0.0001 0.0001
  0.000000 822 0.0003 0.0016 0.0024 0.0020 0.0011 0.0007 0.0008 0.0008 0.0003 -0.0001 -0.0001 0.0000 -0.0000 -0.0003 -0.0005
  0.000000 823 0.0000 0.0001 -0.0001 -0.0006 -0.0011 -0.0011 -0.0009 -0.0006 -0.0004 -0.0002 -0.0001 -0.0001 -0.0001 -0.0001 -0.0000
- 0.000000 824 -0.0001 -0.0003 -0.0005 -0.0005 -0.0003 -0.0002 -0.0003 -0.0003 -0.0003 -0.0002 -0.0002 -0.0001 -0.0000 0.0001 0.0002
+ 0.000000 824 -0.0001 -0.0003 -0.0005 -0.0005 -0.0003 -0.0002 -0.0002 -0.0003 -0.0003 -0.0002 -0.0002 -0.0001 -0.0000 0.0001 0.0002
  0.000000 825 0.0003 0.0012 0.0018 0.0015 0.0009 0.0008 0.0009 0.0007 0.0003 -0.0001 -0.0002 -0.0002 -0.0002 -0.0003 -0.0005
  0.000000 826 0.0001 0.0003 0.0003 -0.0001 -0.0004 -0.0005 -0.0003 -0.0001 -0.0001 -0.0001 -0.0000 -0.0000 -0.0000 -0.0000 0.0000
  0.000000 827 -0.0000 -0.0002 -0.0002 -0.0002 -0.0000 0.0000 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001 -0.0001 0.0000 0.0002 0.0003
@@ -882,7 +882,7 @@
  0.000000 880 0.0000 0.0002 0.0003 0.0002 0.0000 -0.0001 -0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000
  0.000000 881 -0.0001 -0.0004 -0.0007 -0.0008 -0.0006 -0.0004 -0.0002 -0.0002 -0.0001 -0.0000 -0.0000 -0.0001 -0.0002 -0.0002 -0.0001
  0.000000 882 0.0002 0.0009 0.0014 0.0010 0.0002 -0.0004 -0.0003 0.0001 0.0004 0.0003 0.0001 0.0000 0.0000 -0.0001 -0.0003
- 0.000000 883 0.0001 0.0005 0.0006 0.0003 -0.0003 -0.0006 -0.0004 -0.0000 0.0002 0.0003 0.0003 0.0003 0.0002 0.0001 -0.0001
+ 0.000000 883 0.0001 0.0005 0.0006 0.0003 -0.0003 -0.0005 -0.0004 -0.0000 0.0002 0.0003 0.0003 0.0003 0.0002 0.0001 -0.0001
  0.000000 884 -0.0002 -0.0010 -0.0018 -0.0021 -0.0019 -0.0016 -0.0013 -0.0010 -0.0007 -0.0001 0.0003 0.0005 0.0005 0.0004 0.0003
  0.000000 885 0.0002 0.0007 0.0011 0.0007 0.0001 -0.0003 -0.0001 0.0002 0.0004 0.0002 0.0001 0.0001 0.0001 0.0001 -0.0000
  0.000000 886 0.0001 0.0002 0.0002 -0.0001 -0.0005 -0.0006 -0.0004 -0.0000 0.0001 0.0001 0.0001 0.0000 -0.0001 -0.0002 -0.0003
@@ -918,7 +918,7 @@
  0.000000 916 0.0001 0.0003 0.0004 0.0003 -0.0002 -0.0007 -0.0010 -0.0008 -0.0005 -0.0002 -0.0001 -0.0003 -0.0005 -0.0005 -0.0004
  0.000000 917 -0.0003 -0.0016 -0.0033 -0.0041 -0.0038 -0.0024 -0.0008 0.0002 0.0004 0.0000 -0.0004 -0.0006 -0.0005 -0.0003 -0.0002
  0.000000 918 0.0000 0.0002 0.0002 0.0001 -0.0003 -0.0008 -0.0010 -0.0009 -0.0006 -0.0002 0.0001 0.0002 0.0001 0.0000 -0.0000
- 0.000000 919 0.0001 0.0003 0.0006 0.0006 0.0002 -0.0002 -0.0006 -0.0007 -0.0005 -0.0003 -0.0000 0.0001 0.0002 0.0002 0.0001
+ 0.000000 919 0.0001 0.0003 0.0006 0.0006 0.0003 -0.0002 -0.0006 -0.0007 -0.0005 -0.0003 -0.0000 0.0001 0.0002 0.0002 0.0001
  0.000000 920 -0.0001 -0.0006 -0.0013 -0.0018 -0.0019 -0.0016 -0.0010 -0.0003 0.0001 0.0003 0.0003 0.0002 0.0002 0.0002 0.0002
  0.000000 921 0.0000 -0.0000 -0.0000 -0.0001 -0.0001 -0.0002 -0.0002 -0.0002 -0.0002 -0.0001 -0.0001 -0.0001 -0.0001 -0.0001 -0.0001
  0.000000 922 0.0000 0.0001 0.0001 0.0001 0.0001 -0.0000 -0.0001 -0.0002 -0.0001 -0.0001 -0.0000 -0.0000 -0.0000 -0.0001 -0.0001
@@ -1010,7 +1010,7 @@
  0.000000 1008 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000
  0.000000 1009 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000
  0.000000 1010 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
- 0.000000 1011 0.0001 0.0006 0.0007 0.0004 0.0001 0.0001 0.0003 0.0002 -0.0000 -0.0001 -0.0001 -0.0000 0.0001 0.0002 0.0003
+ 0.000000 1011 0.0001 0.0006 0.0007 0.0004 0.0001 0.0002 0.0003 0.0002 -0.0000 -0.0001 -0.0001 -0.0000 0.0001 0.0002 0.0003
  0.000000 1012 0.0001 0.0005 0.0007 0.0006 0.0005 0.0005 0.0006 0.0004 0.0002 -0.0000 -0.0001 -0.0000 0.0000 0.0001 0.0002
  0.000000 1013 -0.0001 -0.0004 -0.0007 -0.0007 -0.0006 -0.0006 -0.0006 -0.0004 -0.0002 -0.0000 0.0001 0.0001 0.0001 0.0000 -0.0000
  0.000000 1014 0.0002 0.0007 0.0009 0.0006 0.0003 0.0003 0.0004 0.0003 -0.0000 -0.0002 -0.0002 -0.0000 0.0001 0.0003 0.0004
@@ -1023,7 +1023,7 @@
  0.000000 1021 -0.0001 -0.0003 -0.0003 -0.0002 -0.0000 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001 -0.0000 0.0000 0.0000 0.0001 0.0001
  0.000000 1022 0.0000 0.0001 0.0002 0.0002 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000 -0.0000 -0.0000 -0.0001
  0.000000 1023 0.0003 0.0015 0.0021 0.0016 0.0009 0.0009 0.0010 0.0008 0.0002 -0.0002 -0.0003 -0.0002 -0.0001 -0.0000 0.0001
- 0.000000 1024 0.0001 0.0006 0.0006 0.0002 -0.0001 -0.0000 0.0002 0.0003 0.0002 0.0002 0.0001 0.0001 0.0000 0.0000 0.0001
+ 0.000000 1024 0.0001 0.0006 0.0006 0.0002 -0.0001 -0.0000 0.0003 0.0003 0.0002 0.0002 0.0001 0.0001 0.0000 0.0000 0.0001
  0.000000 1025 -0.0001 -0.0006 -0.0010 -0.0010 -0.0008 -0.0008 -0.0009 -0.0009 -0.0007 -0.0005 -0.0003 -0.0003 -0.0002 -0.0001 -0.0002
  0.000000 1026 -0.0001 -0.0005 -0.0006 -0.0004 -0.0002 -0.0002 -0.0003 -0.0002 -0.0000 0.0001 0.0000 -0.0000 -0.0000 -0.0001 -0.0001
  0.000000 1027 -0.0000 -0.0002 -0.0002 -0.0001 -0.0000 -0.0001 -0.0001 -0.0001 -0.0001 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000
@@ -1064,12 +1064,12 @@
  0.000000 1062 0.0003 0.0016 0.0022 0.0017 0.0011 0.0009 0.0010 0.0007 0.0003 0.0001 0.0003 0.0004 0.0003 0.0001 -0.0001
  0.000000 1063 0.0001 0.0004 0.0003 -0.0001 -0.0004 -0.0003 -0.0001 -0.0000 -0.0001 -0.0001 -0.0002 -0.0002 -0.0002 -0.0002 -0.0001
  0.000000 1064 0.0000 0.0001 0.0003 0.0004 0.0006 0.0006 0.0005 0.0004 0.0003 0.0003 0.0003 0.0003 0.0004 0.0005 0.0005
- 0.000000 1065 0.0553 0.2601 0.3752 0.3004 0.1589 0.0826 0.0721 0.0589 0.0278 -0.0005 -0.0102 -0.0077 -0.0009 -0.0004 0.0034
- 0.000000 1066 0.0281 0.1269 0.1574 0.0830 -0.0069 -0.0387 -0.0225 -0.0055 0.0026 0.0051 0.0055 0.0035 0.0030 -0.0020 -0.0034
- 0.000000 1067 -0.0064 -0.0288 -0.0481 -0.0356 -0.0013 0.0210 0.0203 0.0054 -0.0028 -0.0043 -0.0043 -0.0039 0.0017 0.0036 0.0061
- 0.000000 1068 0.0281 0.1268 0.1574 0.0830 -0.0069 -0.0387 -0.0226 -0.0055 0.0026 0.0051 0.0055 0.0035 0.0030 -0.0020 -0.0034
- 0.000000 1069 0.0357 0.1730 0.2639 0.2426 0.1687 0.1113 0.0815 0.0549 0.0304 0.0105 -0.0029 -0.0094 -0.0057 -0.0018 0.0045
- 0.000000 1070 -0.0005 -0.0000 -0.0022 0.0049 0.0184 0.0229 0.0153 0.0002 -0.0073 -0.0076 -0.0045 -0.0011 0.0048 0.0052 0.0065
- 0.000000 1071 -0.0064 -0.0302 -0.0481 -0.0356 -0.0028 0.0196 0.0189 0.0054 -0.0028 -0.0043 -0.0043 -0.0039 0.0002 0.0036 0.0061
- 0.000000 1072 -0.0005 -0.0014 -0.0022 0.0049 0.0171 0.0215 0.0139 0.0002 -0.0073 -0.0076 -0.0045 -0.0011 0.0034 0.0052 0.0065
- 0.000000 1073 0.0145 0.0775 0.1428 0.1729 0.1624 0.1291 0.0935 0.0609 0.0335 0.0111 -0.0035 -0.0099 -0.0093 -0.0078 -0.0034
+ 0.000000 1065 0.0553 0.2576 0.3752 0.3004 0.1564 0.0801 0.0695 0.0589 0.0278 -0.0005 -0.0102 -0.0077 -0.0035 -0.0004 0.0034
+ 0.000000 1066 0.0281 0.1243 0.1574 0.0830 -0.0094 -0.0412 -0.0251 -0.0055 0.0026 0.0051 0.0055 0.0035 0.0004 -0.0020 -0.0034
+ 0.000000 1067 -0.0064 -0.0313 -0.0481 -0.0356 -0.0039 0.0185 0.0177 0.0054 -0.0028 -0.0043 -0.0043 -0.0039 -0.0009 0.0036 0.0061
+ 0.000000 1068 0.0281 0.1243 0.1574 0.0830 -0.0094 -0.0412 -0.0251 -0.0055 0.0026 0.0051 0.0055 0.0035 0.0004 -0.0020 -0.0034
+ 0.000000 1069 0.0357 0.1705 0.2639 0.2426 0.1662 0.1088 0.0790 0.0549 0.0304 0.0105 -0.0029 -0.0094 -0.0083 -0.0018 0.0045
+ 0.000000 1070 -0.0005 -0.0025 -0.0022 0.0049 0.0159 0.0204 0.0128 0.0002 -0.0073 -0.0076 -0.0045 -0.0011 0.0022 0.0052 0.0065
+ 0.000000 1071 -0.0064 -0.0313 -0.0481 -0.0356 -0.0039 0.0185 0.0177 0.0054 -0.0028 -0.0043 -0.0043 -0.0039 -0.0009 0.0036 0.0061
+ 0.000000 1072 -0.0005 -0.0025 -0.0022 0.0049 0.0159 0.0204 0.0128 0.0002 -0.0073 -0.0076 -0.0045 -0.0011 0.0022 0.0052 0.0065
+ 0.000000 1073 0.0145 0.0764 0.1428 0.1730 0.1613 0.1280 0.0923 0.0609 0.0335 0.0111 -0.0035 -0.0099 -0.0104 -0.0078 -0.0034
diff --git a/regtest/isdb/rt-saxs-gpu/plumed.dat b/regtest/isdb/rt-saxs-gpu/plumed.dat
index da11af845..9138ce08d 100644
--- a/regtest/isdb/rt-saxs-gpu/plumed.dat
+++ b/regtest/isdb/rt-saxs-gpu/plumed.dat
@@ -1,54 +1,53 @@
 MOLINFO STRUCTURE=template.pdb
+DEBUG DETAILED_TIMERS
 
 SAXS ...
 LABEL=saxs
 ATOMS=1-355
-ADDEXP
 SCEXP=3920000
 MARTINI
-QVALUE1=0.02 EXPINT1=1.0902
-QVALUE2=0.05 EXPINT2=0.790632
-QVALUE3=0.08 EXPINT3=0.453808
-QVALUE4=0.11 EXPINT4=0.254737
-QVALUE5=0.14 EXPINT5=0.154928
-QVALUE6=0.17 EXPINT6=0.0921503
-QVALUE7=0.2 EXPINT7=0.052633
-QVALUE8=0.23 EXPINT8=0.0276557
-QVALUE9=0.26 EXPINT9=0.0122775
-QVALUE10=0.29 EXPINT10=0.00880634
-QVALUE11=0.32 EXPINT11=0.0137301
-QVALUE12=0.35 EXPINT12=0.0180036
-QVALUE13=0.38 EXPINT13=0.0193374
-QVALUE14=0.41 EXPINT14=0.0210131
-QVALUE15=0.44 EXPINT15=0.0220506
+QVALUE1=0.02
+QVALUE2=0.05
+QVALUE3=0.08
+QVALUE4=0.11
+QVALUE5=0.14
+QVALUE6=0.17
+QVALUE7=0.2
+QVALUE8=0.23
+QVALUE9=0.26
+QVALUE10=0.29
+QVALUE11=0.32
+QVALUE12=0.35
+QVALUE13=0.38
+QVALUE14=0.41
+QVALUE15=0.44
 ... SAXS
 
 SAXSGPU ...
+DEVICEID=0
 LABEL=saxsb
 ATOMS=1-355
-ADDEXP
 SCEXP=3920000
 MARTINI
-SPLITB=355
-QVALUE1=0.02 EXPINT1=1.0902
-QVALUE2=0.05 EXPINT2=0.790632
-QVALUE3=0.08 EXPINT3=0.453808
-QVALUE4=0.11 EXPINT4=0.254737
-QVALUE5=0.14 EXPINT5=0.154928
-QVALUE6=0.17 EXPINT6=0.0921503
-QVALUE7=0.2 EXPINT7=0.052633
-QVALUE8=0.23 EXPINT8=0.0276557
-QVALUE9=0.26 EXPINT9=0.0122775
-QVALUE10=0.29 EXPINT10=0.00880634
-QVALUE11=0.32 EXPINT11=0.0137301
-QVALUE12=0.35 EXPINT12=0.0180036
-QVALUE13=0.38 EXPINT13=0.0193374
-QVALUE14=0.41 EXPINT14=0.0210131
-QVALUE15=0.44 EXPINT15=0.0220506
+QVALUE1=0.02
+QVALUE2=0.05
+QVALUE3=0.08
+QVALUE4=0.11
+QVALUE5=0.14
+QVALUE6=0.17
+QVALUE7=0.2
+QVALUE8=0.23
+QVALUE9=0.26
+QVALUE10=0.29
+QVALUE11=0.32
+QVALUE12=0.35
+QVALUE13=0.38
+QVALUE14=0.41
+QVALUE15=0.44
 ...
 
-PRINT ARG=(saxs\.q_.*),(saxs\.exp_.*) FILE=colvar STRIDE=1
-PRINT ARG=(saxsb\.q_.*),(saxsb\.exp_.*) FILE=colvarb STRIDE=1
+PRINT ARG=(saxs\.q_.*) FILE=colvar STRIDE=1
+PRINT ARG=(saxsb\.q_.*) FILE=colvarb STRIDE=1
 
 DUMPDERIVATIVES ARG=(saxs\.q_.*) FILE=forces FMT=%.4f
 DUMPDERIVATIVES ARG=(saxsb\.q_.*) FILE=forcesb FMT=%.4f
diff --git a/src/isdb/SAXSgpu.cpp b/src/isdb/SAXSgpu.cpp
index 948d7eb17..4961c5307 100644
--- a/src/isdb/SAXSgpu.cpp
+++ b/src/isdb/SAXSgpu.cpp
@@ -57,7 +57,6 @@ automatically assigned to atoms using the ATOMISTIC flag reading a PDB file, a c
 automatically assigned to Martini pseudoatoms usign the MARTINI flag.
 The calculated intensities can be scaled using the SCEXP keywords. This is applied by rescaling the structure factors.
 Experimental reference intensities can be added using the ADDEXP and EXPINT flag and keywords.
-\ref METAINFERENCE can be activated using DOSCORE and the other relevant keywords.
 
 \par Examples
 in the following example the saxs intensities for a martini model are calculated. structure factors
@@ -66,7 +65,7 @@ are obtained from the pdb file indicated in the MOLINFO.
 \plumedfile
 MOLINFO STRUCTURE=template.pdb
 
-SAXS ...
+SAXSGPU ...
 LABEL=saxs
 ATOMS=1-355
 ADDEXP
@@ -87,7 +86,7 @@ QVALUE12=0.35 EXPINT12=0.0180036
 QVALUE13=0.38 EXPINT13=0.0193374
 QVALUE14=0.41 EXPINT14=0.0210131
 QVALUE15=0.44 EXPINT15=0.0220506
-... SAXS
+...
 
 PRINT ARG=(saxs\.q_.*),(saxs\.exp_.*) FILE=colvar STRIDE=1
 
@@ -100,21 +99,15 @@ class SAXSGPU : public Colvar {
 private:
   bool                pbc;
   bool                serial;
-  unsigned            splitb;
-  unsigned            total_device;
+  int                 deviceid;
   vector<double>      q_list;
-#ifdef __PLUMED_HAS_ARRAYFIRE
-  af::array          *allFFa;
-  af::array          *sum_device;
-  af::array          *deriv_device;
-#endif
+  af::array           FF_value;
   void getMartiniSFparam(const vector<AtomNumber> &atoms, vector<vector<long double> > &parameter);
   void calculateASF(const vector<AtomNumber> &atoms, vector<vector<long double> > &FF_tmp, const double rho);
 
 public:
   static void registerKeywords( Keywords& keys );
   explicit SAXSGPU(const ActionOptions&);
-  ~SAXSGPU();
   virtual void calculate();
 };
 
@@ -125,8 +118,7 @@ void SAXSGPU::registerKeywords(Keywords& keys) {
   componentsAreNotOptional(keys);
   useCustomisableComponents(keys);
   keys.addFlag("SERIAL",false,"Perform the calculation in serial - for debug purpose");
-  keys.add("compulsory","SPLITB","Spliting the length of the atom array, default is equal to the number of used atoms");
-  keys.addFlag("MULTIGPU",false,"Set to TRUE if you want to use multiple GPU");
+  keys.add("compulsory","DEVICEID","0","Identifier of the GPU to be used");
   keys.addFlag("ATOMISTIC",false,"calculate SAXS for an atomistic model");
   keys.addFlag("MARTINI",false,"calculate SAXS for a Martini model");
   keys.add("atoms","ATOMS","The atoms to be included in the calculation, e.g. the whole protein.");
@@ -144,8 +136,7 @@ SAXSGPU::SAXSGPU(const ActionOptions&ao):
   PLUMED_COLVAR_INIT(ao),
   pbc(true),
   serial(false),
-  splitb(0),
-  total_device(1)
+  deviceid(0)
 {
 #ifndef __PLUMED_HAS_ARRAYFIRE
   error("SAXSGPU can only be used if ARRAYFIRE is installed");
@@ -160,19 +151,11 @@ SAXSGPU::SAXSGPU(const ActionOptions&ao):
   parseFlag("NOPBC",nopbc);
   pbc=!nopbc;
 
-  splitb = 0;
-  parse("SPLITB",splitb);
-  if(splitb==0) splitb=size;
+  parse("DEVICEID",deviceid);
+  af::setDevice(deviceid);
+  af::info();
 
-  bool multi=false;
-  parseFlag("MULTIGPU",multi);
-  if(multi) {
-    total_device = af::getDeviceCount();
-  } else {
-    total_device = 1;
-  }
-
-  double scexp = 0;
+  long double scexp = 0;
   parse("SCEXP",scexp);
   if(scexp==0) scexp=1.0;
 
@@ -241,7 +224,7 @@ SAXSGPU::SAXSGPU(const ActionOptions&ao):
     ntarget++;
   }
   if( ntarget!=numq && exp==true) error("found wrong number of EXPINT values");
-
+ 
   if(pbc)      log.printf("  using periodic boundary conditions\n");
   else         log.printf("  without periodic boundary conditions\n");
   for(unsigned i=0; i<numq; i++) {
@@ -267,6 +250,7 @@ SAXSGPU::SAXSGPU(const ActionOptions&ao):
   for(unsigned i=0; i<numq; ++i) {
     q_list[i]=q_list[i]*10.0;    //factor 10 to convert from A^-1 to nm^-1
   }
+
   log<<"  Bibliography ";
   log<<plumed.cite("Jussupow, et al. (in preparation)");
   if(martini)   log<<plumed.cite("Niebling, Björling, Westenhoff, J Appl Crystallogr 47, 1190–1198 (2014).");
@@ -280,30 +264,16 @@ SAXSGPU::SAXSGPU(const ActionOptions&ao):
   requestAtoms(atoms);
   checkRead();
 
-  // move form factors on the gpu
-  sum_device    = new af::array[total_device*numq];
-  deriv_device  = new af::array[total_device*numq];
-  allFFa        = new af::array[total_device];
+  // move structure factor to the GPU
   float *FF_new = new float[numq*size];
   for(unsigned k=0; k<numq; ++k) {
     for(unsigned i=0; i<size; i++) {
-      FF_new[k+i*numq] = static_cast<float>(static_cast<double>(FF_tmp[k][i])/sqrt(scexp));
+      FF_new[k+i*numq] = static_cast<float>(FF_tmp[k][i]/sqrt(scexp));
     }
   }
-  for(unsigned i=0; i<total_device; i++) {
-    af::setDevice(i);
-    allFFa[i] = af::array(numq, size, FF_new);
-  }
+  af::array allFFa = af::array(numq, size, FF_new);
   delete[] FF_new;
-
-#endif
-}
-
-SAXSGPU::~SAXSGPU() {
-#ifdef __PLUMED_HAS_ARRAYFIRE
-  delete[] sum_device;
-  delete[] deriv_device;
-  delete[] allFFa;
+  FF_value = allFFa;
 #endif
 }
 
@@ -311,7 +281,7 @@ void SAXSGPU::calculate() {
 #ifdef __PLUMED_HAS_ARRAYFIRE
   if(pbc) makeWhole();
 
-  const unsigned size=getNumberOfAtoms();
+  const unsigned size = getNumberOfAtoms();
   const unsigned numq = q_list.size();
 
   float* posi;
@@ -319,102 +289,79 @@ void SAXSGPU::calculate() {
   #pragma omp parallel for num_threads(OpenMP::getNumThreads())
   for (unsigned i=0; i<size; i++) {
     const Vector tmp = getPosition(i);
-    posi[i]        = tmp[0];
-    posi[i+size]   = tmp[1];
-    posi[i+2*size] = tmp[2];
+    posi[i]        = static_cast<float>(tmp[0]);
+    posi[i+size]   = static_cast<float>(tmp[1]);
+    posi[i+2*size] = static_cast<float>(tmp[2]);
   }
 
-  for(unsigned i=0; i<total_device; i++) {
-    af::setDevice(i);
-    sum_device[i]   = af::constant(0, numq, f32);
-    deriv_device[i] = af::constant(0, numq, size, 3, f32);
-  }
+  // create array a and b containing atomic coordinates
+  af::setDevice(deviceid);
+  // size,3,1,1
+  af::array pos_a = af::array(size, 3, posi);
+  // size,3,1,1
+  af::array pos_b = pos_a(af::span, af::span);
+  // size,1,3,1
+  pos_a = af::moddims(pos_a, size, 1, 3);
+  // 1,size,3,1
+  pos_b = af::moddims(pos_b, 1, size, 3);
+  // remove position vector
+  delete[] posi;
 
-  for (unsigned i=0; i<size; i=i+splitb) {
-    //multiple device
-    const int dnumber=(i/splitb) % total_device;
-    af::setDevice(dnumber);
-
-    //first step calculate the short size of the matrix
-    unsigned sizeb = size - i;
-    if(sizeb > splitb) sizeb = splitb;
-    af::seq seqb(i, i+sizeb-1);
-
-    // create array a and b containing atomic coordinates
-    af::array a = af::array(size, 3, posi);
-    af::array b = a(seqb, af::span);
-    a += 0.000001; // crapy solution
-
-    a = af::moddims(a, size, 1, 3);
-    b = af::moddims(b, 1, sizeb, 3);
-    af::array xyz_dist = af::moddims((af::tile(a, 1, sizeb, 1) - af::tile(b, size, 1, 1)), size, sizeb, 3);
-
-    // square size,sizeb,1
-    af::array square = af::moddims(af::sum(xyz_dist*xyz_dist,2), size, sizeb);
-    // dist_sqrt is size,sizeb,1
-    af::array dist_sqrt = af::sqrt(square);
-
-    // allFA numq,size
-    // allFB numq,sizeb
-    af::array allFFb = allFFa[dnumber](af::span, seqb);
-
-    for (unsigned k=0; k<numq; k++) {
-      // calculate FF matrix
-      // FFdist_mod size,sizeb,1
-      af::array FFdist_mod = (af::tile(af::moddims(allFFa[dnumber].row(k), size, 1), 1, sizeb)*
-                              af::tile(af::moddims(allFFb.row(k), 1, sizeb), size, 1));
-
-      // get q*dist and sin
-      const float qvalue = q_list[k];
-      // distq size,sizeb,1
-      af::array dist_q = qvalue*dist_sqrt;
-      // dist_sin size,sizeb,1
-      af::array dist_sin = af::sin(dist_q)/dist_q;
-      // flat it and get the intensity
-      sum_device[dnumber](k) += af::sum(af::flat(dist_sin)*af::flat(FFdist_mod));
-
-      // array get cos and tmp
-      // tmp is size,sizeb
-      af::array tmp = af::moddims(FFdist_mod*(dist_sin - af::cos(dist_q))/square, size, sizeb);
-
-      // increase the tmp size and calculate dd
-      // now is size, sizeb, 3
-      af::array dd_all = af::tile(tmp, 1, 1, 3)*xyz_dist;
-      deriv_device[dnumber](k, seqb, af::span) = af::sum(dd_all);
-    }
+  // size,size,3,1
+  af::array xyz_dist = (af::tile(pos_a, 1, size, 1) - af::tile(pos_b, size, 1, 1));
+  // size,size,1,1
+  af::array square = af::sum(xyz_dist*xyz_dist,2);
+  // size,size,1,1
+  af::array dist_sqrt = af::sqrt(square);
+  // replace the zero of square with one to avoid nan in the derivatives (the number does not matter becasue this are multiplied by zero)
+  af::replace(square,!(af::iszero(square)),1.);
+  // numq,1,1,1
+  af::array sum_device   = af::constant(0, numq, f32);
+  // numq,size,3,1
+  af::array deriv_device = af::constant(0, numq, size, 3, f32);
+
+  for (unsigned k=0; k<numq; k++) {
+    // calculate FF matrix
+    // size,size,1,1
+    af::array FFdist_mod = af::tile(af::moddims(FF_value.row(k), size, 1), 1, size)*af::tile(FF_value.row(k), size, 1);
+
+    // get q
+    const float qvalue = static_cast<float>(q_list[k]);
+    // size,size,1,1
+    af::array dist_q = qvalue*dist_sqrt;
+    // size,size,1
+    af::array dist_sin = af::sin(dist_q)/dist_q;
+    af::replace(dist_sin,!(af::isNaN(dist_sin)),1.);
+    // 1,1,1,1 
+    sum_device(k) += af::sum(af::flat(dist_sin)*af::flat(FFdist_mod));
+
+    // size,size,1,1
+    af::array tmp = FFdist_mod*(dist_sin - af::cos(dist_q))/square;
+    // size,size,3,1
+    af::array dd_all = af::tile(tmp, 1, 1, 3)*xyz_dist;
+    // it should become 1,size,3
+    deriv_device(k, af::span, af::span) = af::sum(dd_all,0);
   }
-  delete[] posi;
+
+  // read out results
+  float* tmp_inten;
+  tmp_inten = new float[numq];
+  sum_device.host(tmp_inten);
+
+  float* tmp_deriv;
+  tmp_deriv = new float[size*3*numq];
+  deriv_device = af::reorder(deriv_device, 2, 1, 0);
+  deriv_device = af::flat(deriv_device);
+  deriv_device.host(tmp_deriv);
 
   // accumulate the results
   std::vector<double> inten; inten.resize(numq,0);
   std::vector<double> deriv; deriv.resize(numq*size*3,0);
+  for(unsigned i=0; i<numq; i++) inten[i] = tmp_inten[i];
+  for(unsigned i=0; i<size*3*numq; i++) deriv[i] = tmp_deriv[i];
+  delete[] tmp_inten;
+  delete[] tmp_deriv;
 
-  // read out results
-  for (unsigned i=0; i<total_device; i++) {
-    af::setDevice(i);
-    float* tmp_inten;
-    tmp_inten = new float[numq];
-    sum_device[i].host(tmp_inten);
-
-    float* tmp_deriv;
-    tmp_deriv = new float[size*3*numq];
-    deriv_device[i] = af::reorder(deriv_device[i], 2, 1, 0);
-    deriv_device[i] = af::flat(deriv_device[i]);
-    deriv_device[i].host(tmp_deriv);
-
-    #pragma omp parallel num_threads(OpenMP::getNumThreads())
-    {
-      #pragma omp for nowait
-      for(unsigned i=0; i<numq; i++) inten[i] += tmp_inten[i];
-      #pragma omp for nowait
-      for(unsigned i=0; i<size*3*numq; i++) deriv[i] += tmp_deriv[i];
-    }
-
-    delete[] tmp_inten;
-    delete[] tmp_deriv;
-  }
-
-  #pragma omp parallel for num_threads(OpenMP::getNumThreads())
   for(unsigned k=0; k<numq; k++) {
     Value* val=getPntrToComponent(k);
     val->set(inten[k]);
-- 
GitLab