From df50ab7e4437ef3294cbad6fdd82a6ca884e71fe Mon Sep 17 00:00:00 2001 From: David Kaufmann Date: Thu, 26 Jan 2012 19:55:13 +0100 Subject: [PATCH] split hillis to hillis_sum and hillis_partial --- openmp/prefix/Makefile | 7 ++++-- openmp/prefix/{hillis.c => hillis_partial.c} | 23 +------------------ openmp/prefix/{hillis.h => hillis_partial.h} | 0 openmp/prefix/hillis_sum.c | 24 ++++++++++++++++++++ openmp/prefix/hillis_sum.h | 8 +++++++ openmp/prefix/parseDat.py | 3 ++- openmp/prefix/runAll.sh | 4 ++-- 7 files changed, 42 insertions(+), 27 deletions(-) rename openmp/prefix/{hillis.c => hillis_partial.c} (58%) rename openmp/prefix/{hillis.h => hillis_partial.h} (100%) create mode 100644 openmp/prefix/hillis_sum.c create mode 100644 openmp/prefix/hillis_sum.h diff --git a/openmp/prefix/Makefile b/openmp/prefix/Makefile index 95ebbec..df51465 100644 --- a/openmp/prefix/Makefile +++ b/openmp/prefix/Makefile @@ -4,7 +4,7 @@ CC = gcc CFLAGS = -pedantic -Wall -ggdb -fopenmp --std=c99 -O3 ${MYFLAGS} LDFLAGS = -fopenmp -all: build/seq build/recurse build/datapar build/hillis +all: build/seq build/recurse build/datapar build/hillis_partial build/hillis_sum build/seq: build/prefix.o build/seq.o $(CC) -o $@ $? $(LDFLAGS) @@ -15,7 +15,10 @@ build/recurse: build/prefix.o build/recurse.o build/datapar: build/prefix.o build/datapar.o $(CC) -o $@ $? $(LDFLAGS) -build/hillis: build/prefix.o build/hillis.o +build/hillis_partial: build/prefix.o build/hillis_partial.o + $(CC) -o $@ $? $(LDFLAGS) + +build/hillis_sum: build/prefix.o build/hillis_sum.o $(CC) -o $@ $? $(LDFLAGS) build/%.o: %.c mkdir diff --git a/openmp/prefix/hillis.c b/openmp/prefix/hillis_partial.c similarity index 58% rename from openmp/prefix/hillis.c rename to openmp/prefix/hillis_partial.c index 6343724..09595af 100644 --- a/openmp/prefix/hillis.c +++ b/openmp/prefix/hillis_partial.c @@ -1,28 +1,7 @@ /* * O(nlog n) work algorithm (Hillis-Steele) */ -#include "hillis.h" - -/* - * Hillis/Steele, prefix sum version - */ -/* -void algorithm (numtype x[], unsigned long size, unsigned int ops[]) { - numtype tmp[size]; - unsigned long k; - unsigned long i; - - for(k=2; k <= size; k <<=1){ - #pragma omp parallel for shared(x, size, ops, k) private(i) - for(i = (k-1); i < size; i+=k){ -#ifdef DEBUG - printf ("x[%2li] = x[%2li] + x[%2li]; // {i:%li, k:%li}\n", i, i-k, i, i, k); -#endif - x[i] = x[i-(k/2)] + x[i]; - } - } -} -*/ +#include "hillis_partial.h" /* * Hillis/Steele, partial prefix sum version diff --git a/openmp/prefix/hillis.h b/openmp/prefix/hillis_partial.h similarity index 100% rename from openmp/prefix/hillis.h rename to openmp/prefix/hillis_partial.h diff --git a/openmp/prefix/hillis_sum.c b/openmp/prefix/hillis_sum.c new file mode 100644 index 0000000..6f8b2ca --- /dev/null +++ b/openmp/prefix/hillis_sum.c @@ -0,0 +1,24 @@ +/* + * O(nlog n) work algorithm (Hillis-Steele) + */ +#include "hillis_partial.h" + +/* + * Hillis/Steele, prefix sum version + */ +void algorithm (numtype x[], unsigned long size, unsigned int ops[]) { + numtype tmp[size]; + unsigned long k; + unsigned long i; + + for(k=2; k <= size; k <<=1){ + #pragma omp parallel for shared(x, size, ops, k) private(i) + for(i = (k-1); i < size; i+=k){ +#ifdef DEBUG + printf ("x[%2li] = x[%2li] + x[%2li]; // {i:%li, k:%li}\n", i, i-k, i, i, k); +#endif + x[i] = x[i-(k/2)] + x[i]; + } + } +} + diff --git a/openmp/prefix/hillis_sum.h b/openmp/prefix/hillis_sum.h new file mode 100644 index 0000000..fd78349 --- /dev/null +++ b/openmp/prefix/hillis_sum.h @@ -0,0 +1,8 @@ +/* + * O(nlog n) work algorithm (Hillis-Steele) + */ +#include +#include +#include +#include "prefix.h" + diff --git a/openmp/prefix/parseDat.py b/openmp/prefix/parseDat.py index 7d0d7b1..cef4899 100755 --- a/openmp/prefix/parseDat.py +++ b/openmp/prefix/parseDat.py @@ -12,7 +12,8 @@ in_file = open(options.infilename, "r") algos = { 'datapar': [], - 'hillis': [], + 'hillis_sum': [], + 'hillis_partial': [], 'seq': [], 'recurse': [] } diff --git a/openmp/prefix/runAll.sh b/openmp/prefix/runAll.sh index 2d504db..a61dfdf 100755 --- a/openmp/prefix/runAll.sh +++ b/openmp/prefix/runAll.sh @@ -4,10 +4,10 @@ if [ ! -f numlist.bin ]; then dd if=/dev/urandom of=numlist.bin bs=1000 count=100000 fi -ALGORITHMS="seq datapar recurse hillis" +ALGORITHMS="seq datapar recurse hillis_sum hillis_partial" RUNLIST="$(seq 100000 100000 1000000) $(seq 1000000 1000000 10000000) $(seq 10000000 10000000 100000000)" -rm -f prefix.pre.dat prefix.seq.dat prefix.recurse.dat prefix.datapar.dat prefix.hillis.dat +rm -f prefix.pre.dat prefix.seq.dat prefix.recurse.dat prefix.datapar.dat prefix.hillis_sum.dat prefix.hillis_partial.dat touch prefix.pre.dat ulimit -s unlimited -- 2.43.0