Commit 32506ab4 authored by Ivo Roghair's avatar Ivo Roghair
Browse files

Added quad-precision computation as a reference

parent 6efa0695
all:
g++ -o summation -O3 -fopenmp -std=c++14 main.cpp
g++ -o summation -O3 -fopenmp -std=c++14 main.cpp -lquadmath
# Summations
# Neighborlists
## Intro
It has been found that a parallel implementation of the DPM did not provide
......@@ -16,6 +16,8 @@ yield slightly different results due to different scheduling.
* Python script `generateBinaryPositions.py`: Generates a binary file that
contains the number of particles (1 integer) and consequently their (x,y,z)
positions.
* Binary file `example.bin`: file containing the integer 10 000 000, followed
by 30 000 000 binary doubles (i.e. 10M (x y z) positions).
* A main file `main.cpp` that loads the binary file into an N x 3 array, and
proceeds to sum all the positions to a single summation:
```math
......@@ -25,18 +27,23 @@ It accounts for a summation using OpenMP parallelization, a serial summation
(counting from 0 up to npart), another serial (counting down from npart to 0)
and finally a sum that accounts for minimizing the numerical error using the
[Kahan summation algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm)
The program also performs a quad-precision summation which is printed first,
and the differences between the 4 double-precision summation techniques are
provided behind the results.
## Sample output
The program loads an input file given as argument to the program:
```
$ ./summation example.bin
$ ./summation example.bin
Trying to open file example.bin ...
Trying to read 10000000 positions from file...
Four different summations:
OpenMP: 1.4999288710279465e+07
Serial 0->nparts: 1.4999288710278464e+07
Serial nparts-->0: 1.4999288710281001e+07
Kahan: 1.4999288710279370e+07
The truth, and nothing but the truth (i.e. quad precision):
1.499928871027937014807207560807e+07
Four different summations with double:
OpenMP: 1.4999288710279474e+07 (delta: -1.0430812835693359e-07)
Serial 0->nparts: 1.4999288710278464e+07 (delta: +9.0524554252624512e-07)
Serial nparts-->0: 1.4999288710281001e+07 (delta: -1.6316771507263184e-06)
Kahan: 1.4999288710279370e+07 (delta: +0.0000000000000000e+00)
Exiting normally...
```
......
......@@ -4,6 +4,7 @@
#include <limits>
#include <chrono>
#include <omp.h>
#include <quadmath.h>
typedef std::chrono::high_resolution_clock Clock;
......@@ -39,6 +40,7 @@ int main(int argc, char* argv[])
double sum1 = 0.0, sum2 = 0.0;
double sum3 = 0.0, sum4 = 0.0;
__float128 sum5 = 0.0;
// Parallel with OpenMP (dynamic scheduler may yield different
// results each time the program is run!)
......@@ -67,8 +69,19 @@ int main(int argc, char* argv[])
c = (t - sum4) - y;
sum4 = t;
}
printf("Four different summations:\n");
printf(" OpenMP: \t\t%1.16e\n Serial 0->nparts: \t%1.16e\n Serial nparts-->0: \t%1.16e\n Kahan: \t\t%1.16e\n", sum1,sum2,sum3,sum4);
// Now for the quad-precision answer
for (int i=0;i<npart;i++) {
sum5 +=pos[i][0]+pos[i][1]+pos[i][2];
}
int width = 46;
char buf[128];
int n = quadmath_snprintf (buf, sizeof(buf), "%1.30Qe", width, sum5);
printf ("The truth, and nothing but the truth (i.e. quad precision):\n\t\t\t %s\n", buf);
printf("Four different summations with double:\n");
printf(" OpenMP: \t\t%1.16e (delta: %+-#1.16e)\n Serial 0->nparts: \t%1.16e (delta: %+-#1.16e)\n Serial nparts-->0: \t%1.16e (delta: %+-#1.16e)\n Kahan: \t\t%1.16e (delta: %+-#1.16e)\n", sum1,(double) sum5-sum1,sum2,(double) sum5-sum2,sum3,(double) sum5-sum3,sum4,(double) sum5-sum4);
}
else cout << "Error opening file " << argv[1] << ".\n\n" << endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment