From 92dd60e7a309c9ce46e03cd3e5c06f177fdd39a2 Mon Sep 17 00:00:00 2001 From: David Kaufmann Date: Tue, 17 Jan 2012 22:02:28 +0100 Subject: [PATCH] fixed hillis algorithm --- openmp/prefix/hillis.c | 10 +++++----- openmp/prefix/prefix.c | 21 +++++++++++---------- openmp/prefix/prefix.h | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/openmp/prefix/hillis.c b/openmp/prefix/hillis.c index a9ba133..6b9b4f0 100644 --- a/openmp/prefix/hillis.c +++ b/openmp/prefix/hillis.c @@ -9,12 +9,12 @@ void algorithm (numtype x[], unsigned long size, unsigned int ops[]) { unsigned long i; printf ("hillis.\n"); - for(k=1; k < size; k <<=1){ -printf ("hier.%li\n", k); - for(i = k; i < size; i++){ -printf (" da.%li\n",i); - x[i] = x[i-k] + x[i]; + for(k=2; k <= size; k <<=1){ + for(i = (k-1); i < size; i+=k){ + //printf ("x[%2li] = x[%2li] + x[%2li]; // {i:%li, k:%li}\n", i, i-k, i, i, k); + x[i] = x[i-(k/2)] + x[i]; } + //arrayState(x, size); //barrier; } diff --git a/openmp/prefix/prefix.c b/openmp/prefix/prefix.c index 076e8f3..bc4790a 100644 --- a/openmp/prefix/prefix.c +++ b/openmp/prefix/prefix.c @@ -5,6 +5,15 @@ /* TODO: Replace with file read. */ #define NUMBERS 16 +void array_contents(numtype array[], unsigned long size) { + printf ("[%li", array[0]); + for (unsigned long i = 1; i < size; i++) { + printf (", %li", array[i]); + } + printf ("]\n"); +} + + int main (int argc, char* argv[]) { numtype numarray[NUMBERS]; unsigned long size; @@ -18,11 +27,7 @@ int main (int argc, char* argv[]) { } /* might want to comment this out, if numarray is big */ - printf ("array details\n[%li", numarray[0]); - for (unsigned long i = 1; i < size; i++) { - printf (", %li", numarray[i]); - } - printf ("]\n"); + array_contents(numarray, size); printf("init done starting algorithm. size: %li\n", size); startTime = omp_get_wtime(); @@ -31,11 +36,7 @@ int main (int argc, char* argv[]) { printf ("result: %li\n", numarray[(size-1)]); /* might want to comment this out, if numarray is big */ - printf ("array details\n[%li", numarray[0]); - for (unsigned long i = 1; i < size; i++) { - printf (", %li", numarray[i]); - } - printf ("]\n"); + array_contents(numarray, size); return 0; } diff --git a/openmp/prefix/prefix.h b/openmp/prefix/prefix.h index 27cb99d..fd1b5a8 100644 --- a/openmp/prefix/prefix.h +++ b/openmp/prefix/prefix.h @@ -6,6 +6,7 @@ #define _prefix_h_ typedef unsigned long numtype; +void array_contents(numtype array[], unsigned long size); void algorithm (numtype in[], unsigned long size, unsigned int ops[]); #endif -- 2.43.0