Skip to content
Snippets Groups Projects
Commit 63e3f2ab authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Updated the test of a pair of cells and remaned it

parent e0a31e5b
Branches
Tags
2 merge requests!136Master,!133Updated vectorisation tests
......@@ -25,7 +25,7 @@ examples/swift_mindt
examples/swift_mindt_mpi
examples/swift_mpi
tests/testVectorize
tests/testPair
tests/brute_force.dat
tests/swift_dopair.dat
tests/testGreetings
......
......@@ -21,10 +21,10 @@ AM_CFLAGS = -I../src $(HDF5_CPPFLAGS) -DTIMER
AM_LDFLAGS = ../src/.libs/libswiftsim.a $(HDF5_LDFLAGS) $(HDF5_LIBS)
# List of programs and scripts to run in the test suite
TESTS = testGreetings testReading.sh testSingle testTimeIntegration
TESTS = testGreetings testReading.sh testSingle testPair.sh
# List of test programs to compile
check_PROGRAMS = testGreetings testReading testSingle testTimeIntegration testSPHStep testVectorize
check_PROGRAMS = testGreetings testReading testSingle testTimeIntegration testSPHStep testPair
# Sources for the individual programs
testGreetings_SOURCES = testGreetings.c
......@@ -37,7 +37,7 @@ testSPHStep_SOURCES = testSPHStep.c
testSingle_SOURCES = testSingle.c
testVectorize_SOURCES = testVectorize.c
testPair_SOURCES = testPair.c
# Files necessary for distribution
EXTRA_DIST = testReading.sh makeInput.py
###############################################################################
# This file is part of SWIFT.
# Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from numpy import *
import sys
abs_tol = 1e-7
rel_tol = 1e-7
# Compares the content of two ASCII tables of floats line by line and
# reports all differences beyond the given tolerances
# Comparisons are done both in absolute and relative values
file1 = sys.argv[1]
file2 = sys.argv[2]
if len(sys.argv) >= 5:
abs_tol = sys.argv[3]
rel_tol = sys.argv[4]
print "Absolute difference tolerance:", abs_tol
print "Relative difference tolerance:", rel_tol
data1 = loadtxt(file1)
data2 = loadtxt(file2)
if shape(data1) != shape(data2):
print "Non-matching array sizes in the files", file1, "and", file2, "."
sys.exit(1)
n_lines = shape(data1)[0]
n_columns = shape(data1)[1]
error = False
for i in range(n_lines):
for j in range(n_columns):
abs_diff = abs(data1[i,j] - data2[i,j])
sum = abs(data1[i,j] + data2[i,j])
if sum > 0:
rel_diff = abs(data1[i,j] - data2[i,j]) / sum
else:
rel_diff = 0. #
if( abs_diff > abs_tol):
print "Absolute difference larger than tolerance (%e) on line %d, column %d:"%(abs_tol, i,j)
print "%18s: a = %e"%(file1, data1[i,j])
print "%18s: b = %e"%(file2, data2[i,j])
print "%18s: |a-b| = %e"%("Difference", abs_diff)
print ""
error = True
if( rel_diff > rel_tol):
print "Relative difference larger than tolerance (%e) on line %d, column %d:"%(rel_tol, i,j)
print "%18s: a = %e"%(file1, data1[i,j])
print "%18s: b = %e"%(file2, data2[i,j])
print "%18s: |a-b|/|a+b| = %e"%("Difference", rel_diff)
print ""
error = True
if error:
sys.exit(1)
else:
print "No differences found"
sys.exit(0)
......@@ -125,6 +125,10 @@ int main(int argc, char *argv[]) {
static unsigned long long partId = 0;
ticks tic, toc, time;
/* Initialize CPU frequency, this also starts time. */
unsigned long long cpufreq = 0;
clocks_set_cpufreq(cpufreq);
while ((c = getopt(argc, argv, "h:p:r:t:")) != -1) {
switch (c) {
case 'h':
......
#!/bin/bash
./testPair -p 6 -r 1
python difffloat.py brute_force.dat swift_dopair.dat 1e-5 2e-6
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment