From ebe26117b27061accfdeca2e03503cc010361a24 Mon Sep 17 00:00:00 2001
From: David Kaufmann <astra@ionic.at>
Date: Sun, 29 Jan 2012 23:51:32 +0100
Subject: [PATCH] add warning to hillis_sum

---
 prefix/hillis_sum.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/prefix/hillis_sum.c b/prefix/hillis_sum.c
index 04c8ae3..d575fba 100644
--- a/prefix/hillis_sum.c
+++ b/prefix/hillis_sum.c
@@ -1,15 +1,32 @@
 /*
  * O(nlog n) work algorithm (Hillis-Steele)
  */
-#include "hillis_partial.h"
+#include "hillis_sum.h"
 
 /*
  * Hillis/Steele, prefix sum version
  */
+unsigned long is_power_of_two(unsigned long var) {
+	if (var == 1) {
+		return 1;
+	}
+	while (var > 2) {
+		if ((var & 0x1) == 0x1) {
+			return 0;
+		}
+		var >>= 1;
+	}
+	return 1;
+}
+
 void algorithm (numtype x[], unsigned long size, unsigned int ops[]) {
 	unsigned long k;
 	unsigned long i;
 
+	if (is_power_of_two(size) != 1) {
+		fprintf(stderr, "Hillis-Sum algorithm only works on arrays on size 2^n\n");
+	}
+
 	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){
-- 
2.43.0