Parcourir la source

Removed heartwall sources and other

Since heartwall was not compatible with the run on the CPU removed also
the sources of it.

In addition removed also the sources of other old benchmarks (b+trre,
myocite and hotspot3D that were not enabled in the original archive of
the benchmark suite)
Andrea Gussoni il y a 9 ans
Parent
commit
48eeb76763
70 fichiers modifiés avec 1 ajouts et 17690 suppressions
  1. 1 1
      Makefile
  2. 0 135
      opencl/b+tree/Makefile
  3. 0 7
      opencl/b+tree/README
  4. 0 469
      opencl/b+tree/common.h
  5. 0 109
      opencl/b+tree/kernel/kernel_gpu_opencl.cl
  6. 0 111
      opencl/b+tree/kernel/kernel_gpu_opencl_2.cl
  7. 0 657
      opencl/b+tree/kernel/kernel_gpu_opencl_wrapper.c
  8. 0 31
      opencl/b+tree/kernel/kernel_gpu_opencl_wrapper.h
  9. 0 772
      opencl/b+tree/kernel/kernel_gpu_opencl_wrapper_2.c
  10. 0 33
      opencl/b+tree/kernel/kernel_gpu_opencl_wrapper_2.h
  11. 0 2413
      opencl/b+tree/main.c
  12. 0 19
      opencl/b+tree/main.h
  13. BIN
      opencl/b+tree/penmp
  14. 0 1
      opencl/b+tree/run
  15. 0 53
      opencl/b+tree/util/num/num.c
  16. 0 21
      opencl/b+tree/util/num/num.h
  17. 0 138
      opencl/b+tree/util/opencl/opencl.c
  18. 0 40
      opencl/b+tree/util/opencl/opencl.h
  19. 0 36
      opencl/b+tree/util/timer/timer.c
  20. 0 22
      opencl/b+tree/util/timer/timer.h
  21. 0 9
      opencl/heartwall/README
  22. 0 82
      opencl/heartwall/info/README
  23. 0 2235
      opencl/heartwall/kernel/kernel_gpu_opencl.cl
  24. 0 1467
      opencl/heartwall/kernel/kernel_gpu_opencl_wrapper.c
  25. 0 30
      opencl/heartwall/kernel/kernel_gpu_opencl_wrapper.h
  26. 0 296
      opencl/heartwall/main.c
  27. 0 271
      opencl/heartwall/main.h
  28. 0 100
      opencl/heartwall/makefile
  29. 0 144
      opencl/heartwall/result.txt
  30. 0 1
      opencl/heartwall/run
  31. 0 1
      opencl/heartwall/run-cpu
  32. 0 1
      opencl/heartwall/run-gpu
  33. 0 1839
      opencl/heartwall/util/avi/avilib.c
  34. 0 325
      opencl/heartwall/util/avi/avilib.h
  35. 0 144
      opencl/heartwall/util/avi/avimod.c
  36. 0 36
      opencl/heartwall/util/avi/avimod.h
  37. 0 264
      opencl/heartwall/util/file/file.c
  38. 0 58
      opencl/heartwall/util/file/file.h
  39. 0 146
      opencl/heartwall/util/opencl/opencl.c
  40. 0 32
      opencl/heartwall/util/opencl/opencl.h
  41. 0 34
      opencl/heartwall/util/timer/timer.c
  42. 0 18
      opencl/heartwall/util/timer/timer.h
  43. BIN
      opencl/hotspot3D/3D
  44. 0 284
      opencl/hotspot3D/3D.c
  45. 0 342
      opencl/hotspot3D/CL_helper.c
  46. 0 18
      opencl/hotspot3D/CL_helper.h
  47. 0 17
      opencl/hotspot3D/Makefile
  48. 0 50
      opencl/hotspot3D/hotspotKernel.cl
  49. 0 1
      opencl/hotspot3D/run
  50. 0 121
      opencl/myocyte/Makefile
  51. 0 78
      opencl/myocyte/README
  52. 0 22
      opencl/myocyte/common.h
  53. 0 612
      opencl/myocyte/kernel/embedded_fehlberg_7_8.c
  54. 0 136
      opencl/myocyte/kernel/kernel_fin.c
  55. 0 1445
      opencl/myocyte/kernel/kernel_gpu_opencl.cl
  56. 0 429
      opencl/myocyte/kernel/kernel_gpu_opencl_wrapper.c
  57. 0 24
      opencl/myocyte/kernel/kernel_gpu_opencl_wrapper.h
  58. 0 293
      opencl/myocyte/kernel/master.c
  59. 0 358
      opencl/myocyte/kernel/solver.c
  60. 0 354
      opencl/myocyte/main.c
  61. 0 19
      opencl/myocyte/main.h
  62. 0 1
      opencl/myocyte/run
  63. 0 145
      opencl/myocyte/util/file/file.c
  64. 0 40
      opencl/myocyte/util/file/file.h
  65. 0 50
      opencl/myocyte/util/num/num.c
  66. 0 18
      opencl/myocyte/util/num/num.h
  67. 0 139
      opencl/myocyte/util/opencl/opencl.c
  68. 0 40
      opencl/myocyte/util/opencl/opencl.h
  69. 0 34
      opencl/myocyte/util/timer/timer.c
  70. 0 19
      opencl/myocyte/util/timer/timer.h

+ 1 - 1
Makefile

@@ -5,7 +5,7 @@ RODINIA_BASE_DIR := $(shell pwd)
 
 OPENCL_BIN_DIR := $(RODINIA_BASE_DIR)/bin/linux/opencl
 
-OCL_DIRS  := backprop bfs cfd dwt2d gaussian heartwall hybridsort hotspot kmeans lavaMD leukocyte lud nn nw srad streamcluster particlefilter pathfinder
+OCL_DIRS  := backprop bfs cfd dwt2d gaussian hybridsort hotspot kmeans lavaMD leukocyte lud nn nw srad streamcluster particlefilter pathfinder
 
 BENCH_DIRS  := backprop bfs cfd dwt2d gaussian hotspot hybridsort kmeans lavaMD leukocyte/OpenCL lud/ocl nn nw particlefilter pathfinder srad streamcluster
 

+ 0 - 135
opencl/b+tree/Makefile

@@ -1,135 +0,0 @@
-include ../../common/make.config
-
-C_C = gcc
-OCL_LIB = -lOpenCL
-
-# ====================================================================================================100
-#	NVCC
-# ====================================================================================================100
-
-# CUD_C = nvcc
-# OMP_FLAG = 	-Xcompiler paste_one_here
-
-# ====================================================================================================100
-#	PGCC
-# ====================================================================================================100
-
-# C_C = pgcc
-# OMP_FLAG = -mp
-# ACC_FLAG = 	-ta=nvidia \
-			# -Minfo \
-			# -Mbounds
-
-# ====================================================================================================100
-#	END
-# ====================================================================================================100
-
-# ======================================================================================================================================================150
-#	END
-# ======================================================================================================================================================150
-
-# ========================================================================================================================================================================================================200
-#	EXECUTABLES (LINK OBJECTS TOGETHER INTO BINARY)
-# ========================================================================================================================================================================================================200
-
-b+tree.out:	./main.o \
-		./kernel/kernel_gpu_opencl_wrapper.o \
-		./kernel/kernel_gpu_opencl_wrapper_2.o \
-		./util/timer/timer.o \
-		./util/num/num.o \
-		./util/opencl/opencl.o
-	$(C_C)	./main.o \
-			./kernel/kernel_gpu_opencl_wrapper.o \
-			./kernel/kernel_gpu_opencl_wrapper_2.o \
-			./util/timer/timer.o \
-			./util/num/num.o \
-			./util/opencl/opencl.o \
-			-lm \
-			-L$(OPENCL_LIB) \
-			-lOpenCL \
-	                -o b+tree.out
-# ========================================================================================================================================================================================================200
-#	OBJECTS (COMPILE SOURCE FILES INTO OBJECTS)
-# ========================================================================================================================================================================================================200
-
-# ======================================================================================================================================================150
-#	MAIN FUNCTION
-# ======================================================================================================================================================150
-
-main.o:	./common.h \
-		./main.h \
-		./main.c
-	$(C_C)	$(KERNEL_DIM) ./main.c \
-			-c \
-			-o ./main.o \
-			-O3
-
-# ======================================================================================================================================================150
-#	KERNELS
-# ======================================================================================================================================================150
-
-./kernel/kernel_gpu_opencl_wrapper.o:	./common.h \
-										./kernel/kernel_gpu_opencl_wrapper.h \
-										./kernel/kernel_gpu_opencl_wrapper.c
-	$(C_C)	$(KERNEL_DIM) ./kernel/kernel_gpu_opencl_wrapper.c \
-			-c \
-			-o ./kernel/kernel_gpu_opencl_wrapper.o \
-			-O3 \
-			-I$(OPENCL_INC)
-
-./kernel/kernel_gpu_opencl_wrapper_2.o:	./common.h \
-										./kernel/kernel_gpu_opencl_wrapper_2.h \
-										./kernel/kernel_gpu_opencl_wrapper_2.c
-	$(C_C)	$(KERNEL_DIM) ./kernel/kernel_gpu_opencl_wrapper_2.c \
-			-c \
-			-o ./kernel/kernel_gpu_opencl_wrapper_2.o \
-			-O3 \
-			-I$(OPENCL_INC)
-
-# ======================================================================================================================================================150
-#	UTILITIES
-# ======================================================================================================================================================150
-
-./util/timer/timer.o:	./common.h \
-						./util/timer/timer.h \
-						./util/timer/timer.c
-	$(C_C)	./util/timer/timer.c \
-			-c \
-			-o ./util/timer/timer.o \
-			-O3
-
-./util/num/num.o:	./common.h \
-					./util/num/num.h \
-					./util/num/num.c
-	$(C_C)	./util/num/num.c \
-			-c \
-			-o ./util/num/num.o \
-			-O3
-
-./util/opencl/opencl.o:	./common.h \
-						./util/opencl/opencl.h \
-						./util/opencl/opencl.c
-	$(C_C)	./util/opencl/opencl.c \
-			-c \
-			-o ./util/opencl/opencl.o \
-			-O3 \
-			-I$(OPENCL_INC)
-
-# ======================================================================================================================================================150
-#	END
-# ======================================================================================================================================================150
-
-# ========================================================================================================================================================================================================200
-#	DELETE
-# ========================================================================================================================================================================================================200
-
-clean:
-	rm	*.o *.out \
-		./kernel/*.o \
-		./util/timer/*.o \
-		./util/num/*.o \
-		./util/opencl/*.o \
-                output.txt
-# ========================================================================================================================================================================================================200
-#	END
-# ========================================================================================================================================================================================================200

+ 0 - 7
opencl/b+tree/README

@@ -1,7 +0,0 @@
-******Adjustable work group size*****
-The kernel 1: RD_WG_SIZE_0_0 RD_WG_SIZE_0
-The kernel 2: RD_WG_SIZE_1_0 RD_WG_SIZE_1
-
-USAGE:
-make clean
-make KERNEL_DIM="-DRD_WG_SIZE_0=256 -DRD_WG_SIZE_1=256"

+ 0 - 469
opencl/b+tree/common.h

@@ -1,469 +0,0 @@
-// # ifdef __cplusplus
-// extern "C" {
-// # endif
-
-// #ifndef LIST_H
-// # define LIST_H
-
-//===============================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//===============================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	INCLUDE (for some reason these are not recognized when defined in main file before this one is included)
-//======================================================================================================================================================150
-
-#include <stdint.h>					// (in path known to compiler)			needed by uint32_t
-#include <stdbool.h>				// (in path known to compiler)			needed by true/false, bool
-#include <stdlib.h>					// (in path known to compiler)			needed by malloc
-
-//======================================================================================================================================================150
-//	DEFINE
-//======================================================================================================================================================150
-
-#define fp float
-
-#define Version "1.5"
-
-#ifdef WINDOWS
-	#define bool char
-	#define false 0
-	#define true 1
-#endif
-
-/* #define DEFAULT_ORDER 256 */
-
-#ifdef RD_WG_SIZE_0_0
-        #define  DEFAULT_ORDER RD_WG_SIZE_0_0
-#elif defined(RD_WG_SIZE_0)
-        #define  DEFAULT_ORDER RD_WG_SIZE_0
-#elif defined(RD_WG_SIZE)
-        #define  DEFAULT_ORDER RD_WG_SIZE
-#else
-        #define  DEFAULT_ORDER 256
-#endif
-
-#ifdef RD_WG_SIZE_1_0
-        #define  DEFAULT_ORDER_2 RD_WG_SIZE_1_0
-#elif defined(RD_WG_SIZE_1)
-        #define  DEFAULT_ORDER_2 RD_WG_SIZE_1
-#elif defined(RD_WG_SIZE)
-        #define  DEFAULT_ORDER_2 RD_WG_SIZE
-#else
-        #define  DEFAULT_ORDER_2 256
-#endif
-
-
-#define malloc(size) ({                                                   \
-  void *_tmp;                                                             \
-                                                                          \
-  if (!(_tmp = malloc(size))) {                                           \
-    fprintf(stderr, "Allocation failed at %s:%d!\n", __FILE__, __LINE__); \
-    exit(-1);                                                             \
-  }                                                                       \
-                                                                          \
-  _tmp;                                                                   \
-})
-
-//======================================================================================================================================================150
-//	STRUCTURES
-//======================================================================================================================================================150
-
-// struct list_item;
-typedef struct list_item list_item_t;
-
-typedef struct list_t {
-  list_item_t *head, *tail;
-  uint32_t length;
-  int32_t (*compare)(const void *key, const void *with);
-  void (*datum_delete)(void *);
-} list_t;
-
-typedef list_item_t *list_iterator_t;
-typedef list_item_t *list_reverse_iterator_t;
-
-/* Type representing the record
-* to which a given key refers.
-* In a real B+ tree system, the
-* record would hold data (in a database)
-* or a file (in an operating system)
-* or some other information.
-* Users can rewrite this part of the code
-* to change the type and content
-* of the value field.
-*/
-typedef struct record {
-	int value;
-} record;
-
-/* Type representing a node in the B+ tree.
-* This type is general enough to serve for both
-* the leaf and the internal node.
-* The heart of the node is the array
-* of keys and the array of corresponding
-* pointers.  The relation between keys
-* and pointers differs between leaves and
-* internal nodes.  In a leaf, the index
-* of each key equals the index of its corresponding
-* pointer, with a maximum of order - 1 key-pointer
-* pairs.  The last pointer points to the
-* leaf to the right (or NULL in the case
-* of the rightmost leaf).
-* In an internal node, the first pointer
-* refers to lower nodes with keys less than
-* the smallest key in the keys array.  Then,
-* with indices i starting at 0, the pointer
-* at i + 1 points to the subtree with keys
-* greater than or equal to the key in this
-* node at index i.
-* The num_keys field is used to keep
-* track of the number of valid keys.
-* In an internal node, the number of valid
-* pointers is always num_keys + 1.
-* In a leaf, the number of valid pointers
-* to data is always num_keys.  The
-* last leaf pointer points to the next leaf.
-*/
-typedef struct node {
-	void ** pointers;
-	int * keys;
-	struct node * parent;
-	bool is_leaf;
-	int num_keys;
-	struct node * next; // Used for queue.
-} node;
-
-// 
-typedef struct knode {
-	int location;
-	int indices [DEFAULT_ORDER + 1];
-	int  keys [DEFAULT_ORDER + 1];
-	bool is_leaf;
-	int num_keys;
-} knode; 
-
-struct list_item {
-  struct list_item *pred, *next;
-  void *datum;
-};
-
-//===============================================================================================================================================================================================================200
-//	PROTOTYPES
-//===============================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-// Other
-//======================================================================================================================================================150
-
-void 
-list_item_init(	list_item_t *li, 
-				void *datum);
-
-void 
-list_item_delete(	list_item_t *li, 
-					void (*datum_delete)(void *datum));
-
-void 
-list_insert_item_tail(	list_t *l, 
-						list_item_t *i);
-
-void 
-list_insert_item_before(list_t *l, 
-						list_item_t *next, 
-						list_item_t *i);
-
-void 
-list_insert_item_after(	list_t *l, 
-						list_item_t *pred, 
-						list_item_t *i);
-
-void 
-list_insert_item_sorted(list_t *l, 
-						list_item_t *i);
-
-//======================================================================================================================================================150
-// ???
-//======================================================================================================================================================150
-
-void 
-list_init(	list_t *l,
-			int32_t (*compare)(const void *key, const void *with),
-			void (*datum_delete)(void *datum));
-
-void 
-list_delete(list_t *l);
-
-void 
-list_reset(list_t *l);
-
-void 
-list_insert_head(	list_t *l, 
-					void *v);
-
-void 
-list_insert_tail(	list_t *l, 
-					void *v);
-
-void 
-list_insert_before(list_t *l, 
-					list_item_t *next, 
-					void *v);
-
-void 
-list_insert_after(	list_t *l, 
-					list_item_t *pred, 
-					void *v);
-
-void 
-list_insert_sorted(	list_t *l, 
-					void *v);
-
-void 
-list_insert_item_head(	list_t *l, 
-						list_item_t *i);
-
-void 
-list_remove_item(	list_t *l, 
-					list_item_t *i);
-
-void 
-list_remove_head(list_t *l);
-
-void 
-list_remove_tail(list_t *l);
-
-list_item_t *
-list_find_item(	list_t *l, 
-				void *datum);
-
-list_item_t *
-list_get_head_item(list_t *l);
-
-list_item_t *
-list_get_tail_item(list_t *l);
-
-void *
-list_find(	list_t *l, 
-			void *datum);
-
-void *
-list_get_head(list_t *l);
-
-void *
-list_get_tail(list_t *l);
-
-uint32_t 
-list_get_length(list_t *l);
-
-bool 
-list_is_empty(list_t *l);
-
-bool 
-list_not_empty(list_t *l);
-
-void 
-list_visit_items(	list_t *l, 
-					void (*visitor)(void *v));
-
-void *
-list_item_get_datum(list_item_t *li);
-
-void 
-list_iterator_init(	list_t *l, 
-					list_iterator_t *li);
-
-void 
-list_iterator_delete(list_iterator_t *li);
-
-void 
-list_iterator_next(list_iterator_t *li);
-
-void 
-list_iterator_prev(list_iterator_t *li);
-
-void *
-list_iterator_get_datum(list_iterator_t *li);
-
-bool 
-list_iterator_is_valid(list_iterator_t *li);
-
-void 
-list_reverse_iterator_init(	list_t *l, 
-							list_iterator_t *li);
-
-void 
-list_reverse_iterator_delete(list_iterator_t *li);
-
-void 
-list_reverse_iterator_next(list_iterator_t *li);
-
-void 
-list_reverse_iterator_prev(list_iterator_t *li);
-
-void *
-list_reverse_iterator_get_datum(list_iterator_t *li);
-
-bool 
-list_reverse_iterator_is_valid(list_reverse_iterator_t *li);
-
-//======================================================================================================================================================150
-// Output and utility
-//======================================================================================================================================================150
-
-void *
-kmalloc(int size);
-
-long 
-transform_to_cuda(	node *n, 
-					bool verbose); //returns actual mem used in a long
-
-void 
-usage_1( void );
-
-void 
-usage_2( void );
-
-void 
-enqueue( node * new_node );
-
-node * 
-dequeue( void );
-
-int 
-height( node * root );
-
-int 
-path_to_root(	node * root, 
-				node * child );
-
-void 
-print_leaves( node * root );
-
-void 
-print_tree( node * root );
-
-node * 
-find_leaf(	node * root, 
-			int key, 
-			bool verbose );
-
-record * 
-find(	node * root, 
-		int key, 
-		bool verbose );
-
-int 
-cut( int length );
-
-//======================================================================================================================================================150
-// Insertion
-//======================================================================================================================================================150
-
-record * 
-make_record(int value);
-
-node * 
-make_node( void );
-
-node * 
-make_leaf( void );
-
-int 
-get_left_index(	node * parent, 
-				node * left);
-
-node * 
-insert_into_leaf(	node * leaf, 
-					int key, record * pointer );
-
-node * 
-insert_into_leaf_after_splitting(	node * root, 
-									node * leaf, 
-									int key, 
-									record * pointer);
-
-node * 
-insert_into_node(	node * root, 
-					node * parent, 
-					int left_index, 
-					int key, 
-					node * right);
-
-node * 
-insert_into_node_after_splitting(	node * root, 
-									node * parent, 
-									int left_index, 
-									int key, 
-									node * right);
-
-node * 
-insert_into_parent(	node * root, 
-					node * left, 
-					int key, 
-					node * right);
-
-node * 
-insert_into_new_root(	node * left, 
-						int key, 
-						node * right);
-
-node * 
-start_new_tree(	int key, 
-				record * pointer);
-
-node * 
-insert(	node * root, 
-		int key, 
-		int value );
-
-//======================================================================================================================================================150
-// Deletion
-//======================================================================================================================================================150
-
-int 
-get_neighbor_index(node * n );
-
-node * 
-adjust_root(node * root);
-
-node * 
-coalesce_nodes(	node * root, 
-				node * n, 
-				node * neighbor, 
-				int neighbor_index, 
-				int k_prime);
-
-node * 
-redistribute_nodes(	node * root, 
-					node * n, 
-					node * neighbor, 
-					int neighbor_index, 
-					int k_prime_index, 
-					int k_prime);
-
-node * 
-delete_entry(	node * root, 
-				node * n, 
-				int key, 
-				void * pointer );
-
-node * 
-deleteVal(	node * root, 
-			int key );
-
-//===============================================================================================================================================================================================================200
-//	HEADER
-//===============================================================================================================================================================================================================200
-
-// int main(	int argc, 
-			// char *argv []);
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-// #endif
-
-// # ifdef __cplusplus
-// }
-// # endif

+ 0 - 109
opencl/b+tree/kernel/kernel_gpu_opencl.cl

@@ -1,109 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	DEFINE
-//======================================================================================================================================================150
-
-// double precision support (switch between as needed for NVIDIA/AMD)
-#ifdef AMDAPP
-#pragma OPENCL EXTENSION cl_amd_fp64 : enable
-#else
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-#endif
-
-// clBuildProgram compiler cannot link this file for some reason, so had to redefine constants and structures below
-// #include ../common.h						// (in directory specified to compiler)			main function header
-
-//======================================================================================================================================================150
-//	DEFINE (had to bring from ../common.h here because feature of including headers in clBuildProgram does not work for some reason)
-//======================================================================================================================================================150
-
-// change to double if double precision needed
-#define fp float
-
-//#define DEFAULT_ORDER 256
-
-//======================================================================================================================================================150
-//	STRUCTURES (had to bring from ../common.h here because feature of including headers in clBuildProgram does not work for some reason)
-//======================================================================================================================================================150
-
-// Type representing the record to which a given key refers. In a real B+ tree system, the record would hold data (in a database) or a file (in an operating system) or some other information.
-// Users can rewrite this part of the code to change the type and content of the value field.
-typedef struct record {
-	int value;
-} record;
-
-// ???
-typedef struct knode {
-	int location;
-	int indices [DEFAULT_ORDER + 1];
-	int  keys [DEFAULT_ORDER + 1];
-	bool is_leaf;
-	int num_keys;
-} knode; 
-
-//========================================================================================================================================================================================================200
-//	findK function
-//========================================================================================================================================================================================================200
-
-__kernel void 
-findK(	long height,
-		__global knode *knodesD,
-		long knodes_elem,
-		__global record *recordsD,
-
-		__global long *currKnodeD,
-		__global long *offsetD,
-		__global int *keysD, 
-		__global record *ansD)
-{
-
-	// private thread IDs
-	int thid = get_local_id(0);
-	int bid = get_group_id(0);
-
-	// processtree levels
-	int i;
-	for(i = 0; i < height; i++){
-
-		// if value is between the two keys
-		if((knodesD[currKnodeD[bid]].keys[thid]) <= keysD[bid] && (knodesD[currKnodeD[bid]].keys[thid+1] > keysD[bid])){
-			// this conditional statement is inserted to avoid crush due to but in original code
-			// "offset[bid]" calculated below that addresses knodes[] in the next iteration goes outside of its bounds cause segmentation fault
-			// more specifically, values saved into knodes->indices in the main function are out of bounds of knodes that they address
-			if(knodesD[offsetD[bid]].indices[thid] < knodes_elem){
-				offsetD[bid] = knodesD[offsetD[bid]].indices[thid];
-			}
-		}
-		//__syncthreads();
-		barrier(CLK_LOCAL_MEM_FENCE);
-		// set for next tree level
-		if(thid==0){
-			currKnodeD[bid] = offsetD[bid];
-		}
-		//__syncthreads();
-		barrier(CLK_LOCAL_MEM_FENCE);
-
-	}
-
-	//At this point, we have a candidate leaf node which may contain
-	//the target record.  Check each key to hopefully find the record
-	if(knodesD[currKnodeD[bid]].keys[thid] == keysD[bid]){
-		ansD[bid].value = recordsD[knodesD[currKnodeD[bid]].indices[thid]].value;
-	}
-
-}
-
-//========================================================================================================================================================================================================200
-//	End
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 111
opencl/b+tree/kernel/kernel_gpu_opencl_2.cl

@@ -1,111 +0,0 @@
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	DEFINE
-//======================================================================================================================================================150
-
-// double precision support (switch between as needed for NVIDIA/AMD)
-#ifdef AMDAPP
-#pragma OPENCL EXTENSION cl_amd_fp64 : enable
-#else
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-#endif
-
-// clBuildProgram compiler cannot link this file for some reason, so had to redefine constants and structures below
-// #include ../common.h						// (in directory specified to compiler)			main function header
-
-//======================================================================================================================================================150
-//	DEFINE (had to bring from ../common.h here because feature of including headers in clBuildProgram does not work for some reason)
-//======================================================================================================================================================150
-
-// change to double if double precision needed
-#define fp float
-
-//#define DEFAULT_ORDER_2 256
-
-//======================================================================================================================================================150
-//	STRUCTURES (had to bring from ../common.h here because feature of including headers in clBuildProgram does not work for some reason)
-//======================================================================================================================================================150
-
-// ???
-typedef struct knode {
-	int location;
-	int indices [DEFAULT_ORDER_2 + 1];
-	int  keys [DEFAULT_ORDER_2 + 1];
-	bool is_leaf;
-	int num_keys;
-} knode; 
-
-//========================================================================================================================================================================================================200
-//	findRangeK function
-//========================================================================================================================================================================================================200
-
-__kernel void 
-findRangeK(	long height,
-			__global knode *knodesD,
-			long knodes_elem,
-
-			__global long *currKnodeD,
-			__global long *offsetD,
-			__global long *lastKnodeD,
-			__global long *offset_2D,
-			__global int *startD,
-			__global int *endD,
-			__global int *RecstartD, 
-			__global int *ReclenD)
-{
-
-	// private thread IDs
-	int thid = get_local_id(0);
-	int bid = get_group_id(0);
-
-	// ???
-	int i;
-	for(i = 0; i < height; i++){
-
-		if((knodesD[currKnodeD[bid]].keys[thid] <= startD[bid]) && (knodesD[currKnodeD[bid]].keys[thid+1] > startD[bid])){
-			// this conditional statement is inserted to avoid crush due to but in original code
-			// "offset[bid]" calculated below that later addresses part of knodes goes outside of its bounds cause segmentation fault
-			// more specifically, values saved into knodes->indices in the main function are out of bounds of knodes that they address
-			if(knodesD[currKnodeD[bid]].indices[thid] < knodes_elem){
-				offsetD[bid] = knodesD[currKnodeD[bid]].indices[thid];
-			}
-		}
-		if((knodesD[lastKnodeD[bid]].keys[thid] <= endD[bid]) && (knodesD[lastKnodeD[bid]].keys[thid+1] > endD[bid])){
-			// this conditional statement is inserted to avoid crush due to but in original code
-			// "offset_2[bid]" calculated below that later addresses part of knodes goes outside of its bounds cause segmentation fault
-			// more specifically, values saved into knodes->indices in the main function are out of bounds of knodes that they address
-			if(knodesD[lastKnodeD[bid]].indices[thid] < knodes_elem){
-				offset_2D[bid] = knodesD[lastKnodeD[bid]].indices[thid];
-			}
-		}
-		//__syncthreads();
-		barrier(CLK_LOCAL_MEM_FENCE);
-		// set for next tree level
-		if(thid==0){
-			currKnodeD[bid] = offsetD[bid];
-			lastKnodeD[bid] = offset_2D[bid];
-		}
-		//	__syncthreads();
-		barrier(CLK_LOCAL_MEM_FENCE);
-	}
-
-	// Find the index of the starting record
-	if(knodesD[currKnodeD[bid]].keys[thid] == startD[bid]){
-		RecstartD[bid] = knodesD[currKnodeD[bid]].indices[thid];
-	}
-	//	__syncthreads();
-	barrier(CLK_LOCAL_MEM_FENCE);
-
-	// Find the index of the ending record
-	if(knodesD[lastKnodeD[bid]].keys[thid] == endD[bid]){
-		ReclenD[bid] = knodesD[lastKnodeD[bid]].indices[thid] - RecstartD[bid]+1;
-	}
-
-}
-
-//========================================================================================================================================================================================================200
-//	End
-//========================================================================================================================================================================================================200

+ 0 - 657
opencl/b+tree/kernel/kernel_gpu_opencl_wrapper.c

@@ -1,657 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <CL/cl.h>									// (in directory provided to compiler)		needed by OpenCL types and functions
-#include <string.h>									// (in directory known to compiler)			needed by memset
-
-//======================================================================================================================================================150
-//	COMMON
-//======================================================================================================================================================150
-
-#include "../common.h"								// (in directory provided here)
-
-//======================================================================================================================================================150
-//	UTILITIES
-//======================================================================================================================================================150
-
-#include "../util/opencl/opencl.h"					// (in directory provided here)
-#include "../util/timer/timer.h"					// (in directory provided here)
-
-//======================================================================================================================================================150
-//	HEADER
-//======================================================================================================================================================150
-
-#include "./kernel_gpu_opencl_wrapper.h"			// (in directory provided here)
-
-//========================================================================================================================================================================================================200
-//	KERNEL_GPU_CUDA_WRAPPER FUNCTION
-//========================================================================================================================================================================================================200
-
-void 
-kernel_gpu_opencl_wrapper(	record *records,
-							long records_mem,
-							knode *knodes,
-							long knodes_elem,
-							long knodes_mem,
-
-							int order,
-							long maxheight,
-							int count,
-
-							long *currKnode,
-							long *offset,
-							int *keys,
-							record *ans)
-{
-
-	//======================================================================================================================================================150
-	//	CPU VARIABLES
-	//======================================================================================================================================================150
-
-	// timer
-	long long time0;
-	long long time1;
-	long long time2;
-	long long time3;
-	long long time4;
-	long long time5;
-	long long time6;
-
-	time0 = get_time();
-
-	//======================================================================================================================================================150
-	//	GPU SETUP
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	INITIAL DRIVER OVERHEAD
-	//====================================================================================================100
-
-	// cudaThreadSynchronize();
-
-	//====================================================================================================100
-	//	COMMON VARIABLES
-	//====================================================================================================100
-
-	// common variables
-	cl_int error;
-
-	//====================================================================================================100
-	//	GET PLATFORMS (Intel, AMD, NVIDIA, based on provided library), SELECT ONE
-	//====================================================================================================100
-
-	// Get the number of available platforms
-	cl_uint num_platforms;
-	error = clGetPlatformIDs(	0, 
-								NULL, 
-								&num_platforms);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Get the list of available platforms
-	cl_platform_id *platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id) * num_platforms);
-	error = clGetPlatformIDs(	num_platforms, 
-								platforms, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Select the 1st platform
-	cl_platform_id platform = platforms[0];
-
-	// Get the name of the selected platform and print it (if there are multiple platforms, choose the first one)
-	char pbuf[100];
-	error = clGetPlatformInfo(	platform, 
-								CL_PLATFORM_VENDOR, 
-								sizeof(pbuf), 
-								pbuf, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	printf("Platform: %s\n", pbuf);
-
-	//====================================================================================================100
-	//	CREATE CONTEXT FOR THE PLATFORM
-	//====================================================================================================100
-
-	// Create context properties for selected platform
-	cl_context_properties context_properties[3] = {	CL_CONTEXT_PLATFORM, 
-													(cl_context_properties) platform, 
-													0};
-
-	// Create context for selected platform being GPU
-	cl_context context;
-	context = clCreateContextFromType(	context_properties, 
-										CL_DEVICE_TYPE_GPU, 
-										NULL, 
-										NULL, 
-										&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	GET DEVICES AVAILABLE FOR THE CONTEXT, SELECT ONE
-	//====================================================================================================100
-
-	// Get the number of devices (previousely selected for the context)
-	size_t devices_size;
-	error = clGetContextInfo(	context, 
-								CL_CONTEXT_DEVICES, 
-								0, 
-								NULL, 
-								&devices_size);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Get the list of devices (previousely selected for the context)
-	cl_device_id *devices = (cl_device_id *) malloc(devices_size);
-	error = clGetContextInfo(	context, 
-								CL_CONTEXT_DEVICES, 
-								devices_size, 
-								devices, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Select the first device (previousely selected for the context) (if there are multiple devices, choose the first one)
-	cl_device_id device;
-	device = devices[0];
-
-	// Get the name of the selected device (previousely selected for the context) and print it
-	error = clGetDeviceInfo(device, 
-							CL_DEVICE_NAME, 
-							sizeof(pbuf), 
-							pbuf, 
-							NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	printf("Device: %s\n", pbuf);
-
-	//====================================================================================================100
-	//	CREATE COMMAND QUEUE FOR THE DEVICE
-	//====================================================================================================100
-
-	// Create a command queue
-	cl_command_queue command_queue;
-	command_queue = clCreateCommandQueue(	context, 
-											device, 
-											0, 
-											&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	CREATE PROGRAM, COMPILE IT
-	//====================================================================================================100
-
-	// Load kernel source code from file
-	const char *source = load_kernel_source("./kernel/kernel_gpu_opencl.cl");
-	size_t sourceSize = strlen(source);
-
-	// Create the program
-	cl_program program = clCreateProgramWithSource(	context, 
-													1, 
-													&source, 
-													&sourceSize, 
-													&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	char clOptions[110];
-	//  sprintf(clOptions,"-I../../src");                                                                                 
-	sprintf(clOptions,"-I./../");
-
-#ifdef DEFAULT_ORDER
-	sprintf(clOptions + strlen(clOptions), " -DDEFAULT_ORDER=%d", DEFAULT_ORDER);
-#endif
-
-
-	// Compile the program
-	error = clBuildProgram(	program, 
-							1, 
-							&device, 
-							clOptions, 
-							NULL, 
-							NULL);
-	// Print warnings and errors from compilation
-	static char log[65536]; 
-	memset(log, 0, sizeof(log));
-	clGetProgramBuildInfo(	program, 
-							device, 
-							CL_PROGRAM_BUILD_LOG, 
-							sizeof(log)-1, 
-							log, 
-							NULL);
-	printf("-----OpenCL Compiler Output-----\n");
-	if (strstr(log,"warning:") || strstr(log, "error:")) 
-		printf("<<<<\n%s\n>>>>\n", log);
-	printf("--------------------------------\n");
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Create kernel
-	cl_kernel kernel;
-	kernel = clCreateKernel(program, 
-							"findK", 
-							&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time1 = get_time();
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY				(MALLOC)
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	DEVICE IN
-	//====================================================================================================100
-
-	//==================================================50
-	//	recordsD
-	//==================================================50
-
-	cl_mem recordsD;
-	recordsD = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								records_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	knodesD
-	//==================================================50
-
-	cl_mem knodesD;
-	knodesD = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								knodes_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	currKnodeD
-	//==================================================50
-
-	cl_mem currKnodeD;
-	currKnodeD = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								count*sizeof(long), 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	offsetD
-	//==================================================50
-
-	cl_mem offsetD;
-	offsetD = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								count*sizeof(long), 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	keysD
-	//==================================================50
-
-	cl_mem keysD;
-	keysD = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								count*sizeof(long), 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	DEVICE IN/OUT
-	//====================================================================================================100
-
-	//==================================================50
-	//	ansD
-	//==================================================50
-
-	cl_mem ansD;
-	ansD = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								count*sizeof(record), 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time2 = get_time();
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY			COPY
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	GPU MEMORY				(MALLOC) COPY IN
-	//====================================================================================================100
-
-	//==================================================50
-	//	recordsD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									recordsD,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									records_mem,			// size to be copied
-									records,				// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	knodesD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									knodesD,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									knodes_mem,				// size to be copied
-									knodes,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	currKnodeD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									currKnodeD,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(long),		// size to be copied
-									currKnode,				// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	offsetD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									offsetD,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(long),		// size to be copied
-									offset,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	keysD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									keysD,					// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(int),		// size to be copied
-									keys,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	DEVICE IN/OUT
-	//====================================================================================================100
-
-	//==================================================50
-	//	ansD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									ansD,					// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(record),	// size to be copied
-									ans,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time3 = get_time();
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	// findK kernel
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	Execution Parameters
-	//====================================================================================================100
-
-	size_t local_work_size[1];
-	local_work_size[0] = order < 1024 ? order : 1024;
-	size_t global_work_size[1];
-	global_work_size[0] = count * local_work_size[0];
-
-	printf("# of blocks = %d, # of threads/block = %d (ensure that device can handle)\n", (int)(global_work_size[0]/local_work_size[0]), (int)local_work_size[0]);
-
-	//====================================================================================================100
-	//	Kernel Arguments
-	//====================================================================================================100
-
-	clSetKernelArg(	kernel, 
-					0, 
-					sizeof(long), 
-					(void *) &maxheight);
-	clSetKernelArg(	kernel, 
-					1, 
-					sizeof(cl_mem), 
-					(void *) &knodesD);
-	clSetKernelArg(	kernel, 
-					2, 
-					sizeof(long), 
-					(void *) &knodes_elem);
-	clSetKernelArg(	kernel, 
-					3, 
-					sizeof(cl_mem), 
-					(void *) &recordsD);
-
-	clSetKernelArg(	kernel, 
-					4, 
-					sizeof(cl_mem), 
-					(void *) &currKnodeD);
-	clSetKernelArg(	kernel, 
-					5, 
-					sizeof(cl_mem), 
-					(void *) &offsetD);
-	clSetKernelArg(	kernel, 
-					6, 
-					sizeof(cl_mem), 
-					(void *) &keysD);
-	clSetKernelArg(	kernel, 
-					7, 
-					sizeof(cl_mem), 
-					(void *) &ansD);
-
-	//====================================================================================================100
-	//	Kernel
-	//====================================================================================================100
-
-	error = clEnqueueNDRangeKernel(	command_queue, 
-									kernel, 
-									1, 
-									NULL, 
-									global_work_size, 
-									local_work_size, 
-									0, 
-									NULL, 
-									NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Wait for all operations to finish NOT SURE WHERE THIS SHOULD GO
-	error = clFinish(command_queue);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time4 = get_time();
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY			COPY (CONTD.)
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	DEVICE IN/OUT
-	//====================================================================================================100
-
-	//==================================================50
-	//	ansD
-	//==================================================50
-
-	error = clEnqueueReadBuffer(command_queue,				// The command queue.
-								ansD,						// The image on the device.
-								CL_TRUE,					// Blocking? (ie. Wait at this line until read has finished?)
-								0,							// Offset. None in this case.
-								count*sizeof(record),		// Size to copy.
-								ans,						// The pointer to the image on the host.
-								0,							// Number of events in wait list. Not used.
-								NULL,						// Event wait list. Not used.
-								NULL);						// Event object for determining status. Not used.
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time5 = get_time();
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY DEALLOCATION
-	//======================================================================================================================================================150
-
-	// Release kernels...
-	clReleaseKernel(kernel);
-
-	// Now the program...
-	clReleaseProgram(program);
-
-	// Clean up the device memory...
-	clReleaseMemObject(recordsD);
-	clReleaseMemObject(knodesD);
-
-	clReleaseMemObject(currKnodeD);
-	clReleaseMemObject(offsetD);
-	clReleaseMemObject(keysD);
-	clReleaseMemObject(ansD);
-
-	// Flush the queue
-	error = clFlush(command_queue);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// ...and finally, the queue and context.
-	clReleaseCommandQueue(command_queue);
-
-	// ???
-	clReleaseContext(context);
-
-	time6 = get_time();
-
-	//======================================================================================================================================================150
-	//	DISPLAY TIMING
-	//======================================================================================================================================================150
-
-	printf("Time spent in different stages of GPU_CUDA KERNEL:\n");
-
-	printf("%15.12f s, %15.12f % : GPU: SET DEVICE / DRIVER INIT\n",	(float) (time1-time0) / 1000000, (float) (time1-time0) / (float) (time6-time0) * 100);
-	printf("%15.12f s, %15.12f % : GPU MEM: ALO\n", 					(float) (time2-time1) / 1000000, (float) (time2-time1) / (float) (time6-time0) * 100);
-	printf("%15.12f s, %15.12f % : GPU MEM: COPY IN\n",					(float) (time3-time2) / 1000000, (float) (time3-time2) / (float) (time6-time0) * 100);
-
-	printf("%15.12f s, %15.12f % : GPU: KERNEL\n",						(float) (time4-time3) / 1000000, (float) (time4-time3) / (float) (time6-time0) * 100);
-
-	printf("%15.12f s, %15.12f % : GPU MEM: COPY OUT\n",				(float) (time5-time4) / 1000000, (float) (time5-time4) / (float) (time6-time0) * 100);
-	printf("%15.12f s, %15.12f % : GPU MEM: FRE\n", 					(float) (time6-time5) / 1000000, (float) (time6-time5) / (float) (time6-time0) * 100);
-
-	printf("Total time:\n");
-	printf("%.12f s\n", 												(float) (time6-time0) / 1000000);
-
-	//======================================================================================================================================================150
-	//	END
-	//======================================================================================================================================================150
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 31
opencl/b+tree/kernel/kernel_gpu_opencl_wrapper.h

@@ -1,31 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	KERNEL_GPU_OPENCL_WRAPPER HEADER
-//========================================================================================================================================================================================================200
-
-void 
-kernel_gpu_opencl_wrapper(	record *records,
-							long records_mem,
-							knode *knodes,
-							long knodes_elem,
-							long knodes_mem,
-
-							int order,
-							long maxheight,
-							int count,
-
-							long *currKnode,
-							long *offset,
-							int *keys,
-							record *ans);
-
-//========================================================================================================================================================================================================200
-//	End
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 772
opencl/b+tree/kernel/kernel_gpu_opencl_wrapper_2.c

@@ -1,772 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <CL/cl.h>									// (in directory provided to compiler)		needed by OpenCL types and functions
-#include <string.h>									// (in directory known to compiler)			needed by memset
-#include <stdio.h>									// (in directory known to compiler)			needed by printf, stderr
-
-//======================================================================================================================================================150
-//	COMMON
-//======================================================================================================================================================150
-
-#include "../common.h"									// (in directory provided here)
-
-//======================================================================================================================================================150
-//	UTILITIES
-//======================================================================================================================================================150
-
-#include "../util/timer/timer.h"						// (in directory provided here)
-
-//======================================================================================================================================================150
-//	HEADER
-//======================================================================================================================================================150
-
-#include "./kernel_gpu_opencl_wrapper_2.h"				// (in directory provided here)
-
-//========================================================================================================================================================================================================200
-//	FUNCTION
-//========================================================================================================================================================================================================200
-
-void 
-kernel_gpu_opencl_wrapper_2(knode *knodes,
-							long knodes_elem,
-							long knodes_mem,
-
-							int order,
-							long maxheight,
-							int count,
-
-							long *currKnode,
-							long *offset,
-							long *lastKnode,
-							long *offset_2,
-							int *start,
-							int *end,
-							int *recstart,
-							int *reclength)
-{
-
-	//======================================================================================================================================================150
-	//	CPU VARIABLES
-	//======================================================================================================================================================150
-
-	// timer
-	long long time0;
-	long long time1;
-	long long time2;
-	long long time3;
-	long long time4;
-	long long time5;
-	long long time6;
-
-	time0 = get_time();
-
-	//======================================================================================================================================================150
-	//	GPU SETUP
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	INITIAL DRIVER OVERHEAD
-	//====================================================================================================100
-
-	// cudaThreadSynchronize();
-
-	//====================================================================================================100
-	//	COMMON VARIABLES
-	//====================================================================================================100
-
-	// common variables
-	cl_int error;
-
-	//====================================================================================================100
-	//	GET PLATFORMS (Intel, AMD, NVIDIA, based on provided library), SELECT ONE
-	//====================================================================================================100
-
-	// Get the number of available platforms
-	cl_uint num_platforms;
-	error = clGetPlatformIDs(	0, 
-								NULL, 
-								&num_platforms);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Get the list of available platforms
-	cl_platform_id *platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id) * num_platforms);
-	error = clGetPlatformIDs(	num_platforms, 
-								platforms, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Select the 1st platform
-	cl_platform_id platform = platforms[0];
-
-	// Get the name of the selected platform and print it (if there are multiple platforms, choose the first one)
-	char pbuf[100];
-	error = clGetPlatformInfo(	platform, 
-								CL_PLATFORM_VENDOR, 
-								sizeof(pbuf), 
-								pbuf, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	printf("Platform: %s\n", pbuf);
-
-	//====================================================================================================100
-	//	CREATE CONTEXT FOR THE PLATFORM
-	//====================================================================================================100
-
-	// Create context properties for selected platform
-	cl_context_properties context_properties[3] = {	CL_CONTEXT_PLATFORM, 
-													(cl_context_properties) platform, 
-													0};
-
-	// Create context for selected platform being GPU
-	cl_context context;
-	context = clCreateContextFromType(	context_properties, 
-										CL_DEVICE_TYPE_GPU, 
-										NULL, 
-										NULL, 
-										&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	GET DEVICES AVAILABLE FOR THE CONTEXT, SELECT ONE
-	//====================================================================================================100
-
-	// Get the number of devices (previousely selected for the context)
-	size_t devices_size;
-	error = clGetContextInfo(	context, 
-								CL_CONTEXT_DEVICES, 
-								0, 
-								NULL, 
-								&devices_size);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Get the list of devices (previousely selected for the context)
-	cl_device_id *devices = (cl_device_id *) malloc(devices_size);
-	error = clGetContextInfo(	context, 
-								CL_CONTEXT_DEVICES, 
-								devices_size, 
-								devices, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Select the first device (previousely selected for the context) (if there are multiple devices, choose the first one)
-	cl_device_id device;
-	device = devices[0];
-
-	// Get the name of the selected device (previousely selected for the context) and print it
-	error = clGetDeviceInfo(device, 
-							CL_DEVICE_NAME, 
-							sizeof(pbuf), 
-							pbuf, 
-							NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	printf("Device: %s\n", pbuf);
-
-	//====================================================================================================100
-	//	CREATE COMMAND QUEUE FOR THE DEVICE
-	//====================================================================================================100
-
-	// Create a command queue
-	cl_command_queue command_queue;
-	command_queue = clCreateCommandQueue(	context, 
-											device, 
-											0, 
-											&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	CREATE PROGRAM, COMPILE IT
-	//====================================================================================================100
-
-	// Load kernel source code from file
-	const char *source = load_kernel_source("./kernel/kernel_gpu_opencl_2.cl");
-	size_t sourceSize = strlen(source);
-
-	// Create the program
-	cl_program program = clCreateProgramWithSource(	context, 
-													1, 
-													&source, 
-													&sourceSize, 
-													&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	char clOptions[110];
-	//  sprintf(clOptions,"-I../../src");                                                                                 
-	sprintf(clOptions,"-I./../");
-
-#ifdef DEFAULT_ORDER_2
-	sprintf(clOptions + strlen(clOptions), " -DDEFAULT_ORDER_2=%d", DEFAULT_ORDER_2);
-#endif
-
-	// Compile the program
-	error = clBuildProgram(	program, 
-							1, 
-							&device, 
-							clOptions, 
-							NULL, 
-							NULL);
-	// Print warnings and errors from compilation
-	static char log[65536]; 
-	memset(log, 0, sizeof(log));
-	clGetProgramBuildInfo(	program, 
-							device, 
-							CL_PROGRAM_BUILD_LOG, 
-							sizeof(log)-1, 
-							log, 
-							NULL);
-	printf("-----OpenCL Compiler Output-----\n");
-	if (strstr(log,"warning:") || strstr(log, "error:")) 
-		printf("<<<<\n%s\n>>>>\n", log);
-	printf("--------------------------------\n");
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Create kernel
-	cl_kernel kernel;
-	kernel = clCreateKernel(program, 
-							"findRangeK", 
-							&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time1 = get_time();
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY				MALLOC
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	DEVICE IN
-	//====================================================================================================100
-
-	//==================================================50
-	//	knodesD
-	//==================================================50
-
-	cl_mem knodesD;
-	knodesD = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								knodes_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	currKnodeD
-	//==================================================50
-
-	cl_mem currKnodeD;
-	currKnodeD = clCreateBuffer(context, 
-								CL_MEM_READ_WRITE, 
-								count*sizeof(long), 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	offsetD
-	//==================================================50
-
-	cl_mem offsetD;
-	offsetD = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								count*sizeof(long), 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	lastKnodeD
-	//==================================================50
-
-	cl_mem lastKnodeD;
-	lastKnodeD = clCreateBuffer(context, 
-								CL_MEM_READ_WRITE, 
-								count*sizeof(long), 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	offset_2D
-	//==================================================50
-
-	cl_mem offset_2D;
-	offset_2D = clCreateBuffer(context, 
-								CL_MEM_READ_WRITE, 
-								count*sizeof(long), 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	startD
-	//==================================================50
-
-	cl_mem startD;
-	startD = clCreateBuffer(context, 
-								CL_MEM_READ_WRITE, 
-								count*sizeof(int), 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	endD
-	//==================================================50
-
-	cl_mem endD;
-	endD = clCreateBuffer(	context, 
-							CL_MEM_READ_WRITE, 
-							count*sizeof(int), 
-							NULL, 
-							&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	DEVICE IN/OUT
-	//====================================================================================================100
-
-	//==================================================50
-	//	ansDStart
-	//==================================================50
-
-	cl_mem ansDStart;
-	ansDStart = clCreateBuffer(	context, 
-							CL_MEM_READ_WRITE, 
-							count*sizeof(int), 
-							NULL, 
-							&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	ansDLength
-	//==================================================50
-
-	cl_mem ansDLength;
-	ansDLength = clCreateBuffer(	context, 
-							CL_MEM_READ_WRITE, 
-							count*sizeof(int), 
-							NULL, 
-							&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time2 = get_time();
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY			COPY
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	DEVICE IN
-	//====================================================================================================100
-
-	//==================================================50
-	//	knodesD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									knodesD,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									knodes_mem,				// size to be copied
-									knodes,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	currKnodeD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									currKnodeD,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(long),		// size to be copied
-									currKnode,				// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	offsetD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									offsetD,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(long),		// size to be copied
-									offset,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	lastKnodeD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									lastKnodeD,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(long),		// size to be copied
-									lastKnode,				// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	offset_2D
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									offset_2D,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(long),		// size to be copied
-									offset_2,				// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	startD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									startD,					// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(int),		// size to be copied
-									start,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	endD
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									endD,					// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(int),		// size to be copied
-									end,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	DEVICE IN/OUT
-	//====================================================================================================100
-
-	//==================================================50
-	//	ansDStart
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									endD,					// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(int),		// size to be copied
-									end,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	ansDLength
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									ansDLength,					// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									count*sizeof(int),		// size to be copied
-									reclength,					// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time3 = get_time();
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//======================================================================================================================================================150
-	//	KERNEL
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	Execution Parameters
-	//====================================================================================================100
-
-	size_t local_work_size[1];
-	local_work_size[0] = order < 1024 ? order : 1024;
-	size_t global_work_size[1];
-	global_work_size[0] = count * local_work_size[0];
-
-	printf("# of blocks = %d, # of threads/block = %d (ensure that device can handle)\n", (int)(global_work_size[0]/local_work_size[0]), (int)local_work_size[0]);
-
-	//====================================================================================================100
-	//	Kernel Arguments
-	//====================================================================================================100
-
-	clSetKernelArg(	kernel, 
-					0, 
-					sizeof(long), 
-					(void *) &maxheight);
-	clSetKernelArg(	kernel, 
-					1, 
-					sizeof(cl_mem), 
-					(void *) &knodesD);
-	clSetKernelArg(	kernel, 
-					2, 
-					sizeof(long), 
-					(void *) &knodes_elem);
-
-	clSetKernelArg(	kernel, 
-					3, 
-					sizeof(cl_mem), 
-					(void *) &currKnodeD);
-	clSetKernelArg(	kernel, 
-					4, 
-					sizeof(cl_mem), 
-					(void *) &offsetD);
-	clSetKernelArg(	kernel, 
-					5, 
-					sizeof(cl_mem), 
-					(void *) &lastKnodeD);
-	clSetKernelArg(	kernel, 
-					6, 
-					sizeof(cl_mem), 
-					(void *) &offset_2D);
-	clSetKernelArg(	kernel, 
-					7, 
-					sizeof(cl_mem), 
-					(void *) &startD);
-	clSetKernelArg(	kernel, 
-					8, 
-					sizeof(cl_mem), 
-					(void *) &endD);
-	clSetKernelArg(	kernel, 
-					9, 
-					sizeof(cl_mem), 
-					(void *) &ansDStart);
-	clSetKernelArg(	kernel, 
-					10, 
-					sizeof(cl_mem), 
-					(void *) &ansDLength);
-
-	//====================================================================================================100
-	//	Kernel
-	//====================================================================================================100
-
-	error = clEnqueueNDRangeKernel(	command_queue, 
-									kernel, 
-									1, 
-									NULL, 
-									global_work_size, 
-									local_work_size, 
-									0, 
-									NULL, 
-									NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Wait for all operations to finish NOT SURE WHERE THIS SHOULD GO
-	error = clFinish(command_queue);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time4 = get_time();
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY			COPY (CONTD.)
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	DEVICE IN/OUT
-	//====================================================================================================100
-
-	//==================================================50
-	//	ansDStart
-	//==================================================50
-
-	error = clEnqueueReadBuffer(command_queue,				// The command queue.
-								ansDStart,					// The image on the device.
-								CL_TRUE,					// Blocking? (ie. Wait at this line until read has finished?)
-								0,							// Offset. None in this case.
-								count*sizeof(int),			// Size to copy.
-								recstart,					// The pointer to the image on the host.
-								0,							// Number of events in wait list. Not used.
-								NULL,						// Event wait list. Not used.
-								NULL);						// Event object for determining status. Not used.
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	ansDLength
-	//==================================================50
-
-	error = clEnqueueReadBuffer(command_queue,				// The command queue.
-								ansDLength,					// The image on the device.
-								CL_TRUE,					// Blocking? (ie. Wait at this line until read has finished?)
-								0,							// Offset. None in this case.
-								count*sizeof(int),			// Size to copy.
-								reclength,					// The pointer to the image on the host.
-								0,							// Number of events in wait list. Not used.
-								NULL,						// Event wait list. Not used.
-								NULL);						// Event object for determining status. Not used.
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time5 = get_time();
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY DEALLOCATION
-	//======================================================================================================================================================150
-
-	// Release kernels...
-	clReleaseKernel(kernel);
-
-	// Now the program...
-	clReleaseProgram(program);
-
-	// Clean up the device memory...
-	clReleaseMemObject(knodesD);
-
-	clReleaseMemObject(currKnodeD);
-	clReleaseMemObject(offsetD);
-	clReleaseMemObject(lastKnodeD);
-	clReleaseMemObject(offset_2D);
-	clReleaseMemObject(startD);
-	clReleaseMemObject(endD);
-	clReleaseMemObject(ansDStart);
-	clReleaseMemObject(ansDLength);
-
-	// Flush the queue
-	error = clFlush(command_queue);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// ...and finally, the queue and context.
-	clReleaseCommandQueue(command_queue);
-
-	// ???
-	clReleaseContext(context);
-
-	time6 = get_time();
-
-	//======================================================================================================================================================150
-	//	DISPLAY TIMING
-	//======================================================================================================================================================150
-
-	printf("Time spent in different stages of GPU_CUDA KERNEL:\n");
-
-	printf("%15.12f s, %15.12f % : GPU: SET DEVICE / DRIVER INIT\n",	(float) (time1-time0) / 1000000, (float) (time1-time0) / (float) (time6-time0) * 100);
-	printf("%15.12f s, %15.12f % : GPU MEM: ALO\n", 					(float) (time2-time1) / 1000000, (float) (time2-time1) / (float) (time6-time0) * 100);
-	printf("%15.12f s, %15.12f % : GPU MEM: COPY IN\n",					(float) (time3-time2) / 1000000, (float) (time3-time2) / (float) (time6-time0) * 100);
-
-	printf("%15.12f s, %15.12f % : GPU: KERNEL\n",						(float) (time4-time3) / 1000000, (float) (time4-time3) / (float) (time6-time0) * 100);
-
-	printf("%15.12f s, %15.12f % : GPU MEM: COPY OUT\n",				(float) (time5-time4) / 1000000, (float) (time5-time4) / (float) (time6-time0) * 100);
-	printf("%15.12f s, %15.12f % : GPU MEM: FRE\n", 					(float) (time6-time5) / 1000000, (float) (time6-time5) / (float) (time6-time0) * 100);
-
-	printf("Total time:\n");
-	printf("%.12f s\n", 												(float) (time6-time0) / 1000000);
-
-	//======================================================================================================================================================150
-	//	END
-	//======================================================================================================================================================150
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 33
opencl/b+tree/kernel/kernel_gpu_opencl_wrapper_2.h

@@ -1,33 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	KERNEL_GPU_OPENCL_WRAPPER HEADER
-//========================================================================================================================================================================================================200
-
-void 
-kernel_gpu_opencl_wrapper_2(knode *knodes,
-							long knodes_elem,
-							long knodes_mem,
-
-							int order,
-							long maxheight,
-							int count,
-
-							long *currKnode,
-							long *offset,
-							long *lastKnode,
-							long *offset_2,
-							int *start,
-							int *end,
-							int *recstart,
-							int *reclength);
-
-//========================================================================================================================================================================================================200
-//	End
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 2413
opencl/b+tree/main.c

@@ -1,2413 +0,0 @@
-// # ifdef __cplusplus
-// extern "C" {
-// # endif
-
-//========================================================================================================================================================================================================200
-//======================================================================================================================================================150
-//====================================================================================================100
-//==================================================50
-
-//========================================================================================================================================================================================================200
-//	INFORMATION
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	UPDATE
-//======================================================================================================================================================150
-
-// 2009; Amittai Aviram; entire code written in C; 
-// 2010; Jordan Fix and Andrew Wilkes; code converted to CUDA; 
-// 2011.10; Lukasz G. Szafaryn; code converted to portable form, to C, OpenMP, CUDA, PGI versions; 
-// 2011.12; Lukasz G. Szafaryn; Split different versions for Rodinia.
-// 2011.12; Lukasz G. Szafaryn; code converted to OpenCL;
-
-//======================================================================================================================================================150
-//	DESCRIPTION
-//======================================================================================================================================================150
-
-// Description
-
-//======================================================================================================================================================150
-//	USE
-//======================================================================================================================================================150
-
-// EXAMPLE:
-// ./a.out -file ./input/mil.txt
-// ...then enter any of the following commands after the prompt > :
-// f <x>  -- Find the value under key <x>
-// p <x> -- Print the path from the root to key k and its associated value
-// t -- Print the B+ tree
-// l -- Print the keys of the leaves (bottom row of the tree)
-// v -- Toggle output of pointer addresses ("verbose") in tree and leaves.
-// k <x> -- Run <x> bundled queries on the CPU and GPU (B+Tree) (Selects random values for each search)
-// j <x> <y> -- Run a range search of <x> bundled queries on the CPU and GPU (B+Tree) with the range of each search of size <y>
-// x <z> -- Run a single search for value z on the GPU and CPU
-// y <a> <b> -- Run a single range search for range a-b on the GPU and CPU
-// q -- Quit. (Or use Ctl-D.)
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <stdio.h>									// (in directory known to compiler)			needed by printf, stderr
-#include <limits.h>									// (in directory known to compiler)			needed by INT_MIN, INT_MAX
-// #include <sys/time.h>							// (in directory known to compiler)			needed by ???
-#include <math.h>									// (in directory known to compiler)			needed by log, pow
-#include <string.h>									// (in directory known to compiler)			needed by memset
-
-//======================================================================================================================================================150
-//	COMMON
-//======================================================================================================================================================150
-
-#include "./common.h"								// (in directory provided here)
-
-//======================================================================================================================================================150
-//	DEFINE
-//======================================================================================================================================================150
-
-//======================================================================================================================================================150
-//	UTILITIES
-//======================================================================================================================================================150
-
-#include "./util/timer/timer.h"						// (in directory provided here)
-#include "./util/num/num.h"							// (in directory provided here)
-
-//======================================================================================================================================================150
-//	KERNEL HEADERS
-//======================================================================================================================================================150
-
-#include "./kernel/kernel_gpu_opencl_wrapper.h"		// (in directory provided here)
-#include "./kernel/kernel_gpu_opencl_wrapper_2.h"		// (in directory provided here)
-
-//======================================================================================================================================================150
-//	HEADER
-//======================================================================================================================================================150
-
-#include "./main.h"									// (in directory provided here)
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	VARIABLES
-//========================================================================================================================================================================================================200
-
-// general variables
-knode *knodes;
-record *krecords;
-char *mem;
-long freeptr;
-long malloc_size;
-long size;
-long maxheight;
-
-/* The order determines the maximum and minimum
-* number of entries (keys and pointers) in any
-* node.  Every node has at most order - 1 keys and
-* at least (roughly speaking) half that number.
-* Every leaf has as many pointers to data as keys,
-* and every internal node has one more pointer
-* to a subtree than the number of keys.
-* This global variable is initialized to the
-* default value.
-*/
-int order = DEFAULT_ORDER;
-
-/* The queue is used to print the tree in
-* level order, starting from the root
-* printing each entire rank on a separate
-* line, finishing with the leaves.
-*/
-node *queue = NULL;
-
-/* The user can toggle on and off the "verbose"
-* property, which causes the pointer addresses
-* to be printed out in hexadecimal notation
-* next to their corresponding keys.
-*/
-bool verbose_output = false;
-
-//========================================================================================================================================================================================================200
-//	FUNCTIONS
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	Components
-//======================================================================================================================================================150
-
-void 
-list_init(	list_t *l,
-			int32_t (*compare)(const void *key, 
-			const void *with),
-			void (*datum_delete)(void *))
-{
-  l->head = l->tail = NULL;
-  l->length = 0;
-  l->compare = compare;
-  l->datum_delete = datum_delete;
-}
-
-void 
-list_delete(list_t *l)
-{
-
-  list_item_t *li, *del;
-
-  for (li = l->head; li;) {
-
-    del = li;
-    li = li->next;
-    list_item_delete(del, l->datum_delete);
-  }
-
-  l->head = l->tail = NULL;
-  l->length = 0;
-}
-
-void 
-list_reset(list_t *l)
-{
-  list_delete(l);
-}
-
-void 
-list_insert_item_head(	list_t *l, 
-						list_item_t *i)
-{
-  if (l->head) {
-    i->next = l->head;
-    l->head->pred = i;
-    l->head = i;
-    l->head->pred = NULL;
-  } else {
-    l->head = l->tail = i;
-    i->next = i->pred = NULL;
-  }
-  l->length++;
-}
-
-void 
-list_insert_item_tail(	list_t *l, 
-						list_item_t *i)
-{
-  if (l->head) {
-    l->tail->next = i;
-    i->pred = l->tail;
-    i->next = NULL;
-    l->tail = i;
-  } else {
-    l->head = l->tail = i;
-    i->next = i->pred = NULL;
-  }
-  l->length++;
-}
-
-void 
-list_insert_item_before(list_t *l, 
-						list_item_t *next, 
-						list_item_t *i)
-{
-  /* Assume next is actually in the list! */
-  /* If it's not, we may lose the list.   */
-  if (l->head == next) {
-    i->next = next;
-    i->pred = NULL;
-    l->head = i;
-    next->pred = i;
-  } else {
-    i->next = next;
-    i->pred = next->pred;
-    next->pred->next = i;
-    next->pred = i;
-  }
-  l->length++;
-}
-
-void 
-list_insert_item_after(	list_t *l, 
-						list_item_t *pred, 
-						list_item_t *i)
-{
-  /* Assume pred is actually in the list! */
-  /* If it's not, we may lose the list.   */
-  if (l->tail == pred) {
-    i->pred = pred;
-    i->next = NULL;
-    l->tail = i;
-    pred->next = i;
-  } else {
-    i->pred = pred;
-    i->next = pred->next;
-    pred->next->pred = i;
-    pred->next = i;
-  }
-  l->length++;
-}
-
-void 
-list_insert_item_sorted(list_t *l, 
-						list_item_t *i)
-{
-  list_item_t *itr;
-
-  if (l->head) {
-    for (itr = l->head; itr && l->compare(list_item_get_datum(i),
-					  list_item_get_datum(itr)) < 0;
-	 itr = itr->next)
-      ;
-    if (itr) {
-      i->next = itr;
-      i->pred = itr->pred;
-      itr->pred = i;
-      i->pred->next = i;
-    } else {
-      l->tail->next = i;
-      i->pred = l->tail;
-      i->next = NULL;
-      l->tail = i;
-    }
-  } else {
-    l->head = l->tail = i;
-    i->pred = i->next = NULL;
-  }
-  l->length++;
-}
-
-void 
-list_insert_head(	list_t *l, 
-					void *v)
-{
-  list_item_t *i;
-  i = (list_item_t *)malloc(sizeof (*i));
-  list_item_init(i, v);
-  if (l->head) {
-    i->next = l->head;
-    l->head->pred = i;
-    l->head = i;
-    l->head->pred = NULL;
-  } else {
-    l->head = l->tail = i;
-    i->next = i->pred = NULL;
-  }
-  l->length++;
-
-}
-
-void 
-list_insert_tail(	list_t *l, 
-					void *v)
-{
-  list_item_t *i;
-
-  i = (list_item_t *)malloc(sizeof (*i));
-  list_item_init(i, v);
-  if (l->head) {
-    l->tail->next = i;
-    i->pred = l->tail;
-    i->next = NULL;
-    l->tail = i;
-  } else {
-    l->head = l->tail = i;
-    i->next = i->pred = NULL;
-  }
-  l->length++;
-}
-
-void 
-list_insert_before(	list_t *l, 
-					list_item_t *next, 
-					void *v)
-{
-  list_item_t *i;
-
-  i = (list_item_t *)malloc(sizeof (*i));
-  list_item_init(i, v);
-
-  /* Assume next is actually in the list! */
-  /* If it's not, we may lose the list.   */
-  if (l->head == next) {
-    i->next = next;
-    i->pred = NULL;
-    l->head = i;
-    next->pred = i;
-  } else {
-    i->next = next;
-    i->pred = next->pred;
-    next->pred->next = i;
-    next->pred = i;
-  }
-  l->length++;
-}
-
-void 
-list_insert_after(	list_t *l, 
-					list_item_t *pred, 
-					void *v)
-{
-  list_item_t *i;
-
-  i = (list_item_t *)malloc(sizeof (*i));
-  list_item_init(i, v);
-
-  /* Assume pred is actually in the list! */
-  /* If it's not, we may lose the list.   */
-  if (l->tail == pred) {
-    i->pred = pred;
-    i->next = NULL;
-    l->tail = i;
-    pred->next = i;
-  } else {
-    i->pred = pred;
-    i->next = pred->next;
-    pred->next->pred = i;
-    pred->next = i;
-  }
-  l->length++;
-}
-
-void 
-list_insert_sorted(	list_t *l, 
-					void *v)
-{
-  list_item_t *itr;
-  list_item_t *i;
-
-  i = (list_item_t *)malloc(sizeof (*i));
-  list_item_init(i, v);
-
-
-  if (l->head) {
-    for (itr = l->head; itr && l->compare(list_item_get_datum(i),
-					  list_item_get_datum(itr)) < 0;
-	 itr = itr->next)
-      ;
-    if (itr) {
-      i->next = itr;
-      i->pred = itr->pred;
-      itr->pred = i;
-      i->pred->next = i;
-    } else {
-      l->tail->next = i;
-      i->pred = l->tail;
-      i->next = NULL;
-      l->tail = i;
-    }
-  } else {
-    l->head = l->tail = i;
-    i->pred = i->next = NULL;
-  }
-  l->length++;
-}
-
-void 
-list_remove_item(	list_t *l, 
-					list_item_t *i)
-{
-  if (i == l->head) {
-    l->head = l->head->next;
-    if (l->head)
-      l->head->pred = NULL;
-    else
-      l->tail = NULL;
-  } else if (i == l->tail) {
-    l->tail = l->tail->pred;
-    l->tail->next = NULL;
-  } else {
-    i->pred->next = i->next;
-    i->next->pred = i->pred;
-  }
-  l->length--;
-  list_item_delete(i, l->datum_delete);
-}
-
-void 
-list_remove_head(list_t *l)
-{
-  list_remove_item(l, l->head);
-}
-
-void 
-list_remove_tail(list_t *l)
-{
-  list_remove_item(l, l->tail);
-}
-
-list_item_t* 
-list_find_item(	list_t *l, 
-				void *datum)
-{
-  list_item_t *li;
-
-  for (li = l->head; li && l->compare(datum, list_item_get_datum(li));
-       li = li->next)
-    ;
-
-  return li;
-}
-
-list_item_t* 
-list_get_head_item(list_t *l)
-{
-  return l->head;
-}
-
-list_item_t* 
-list_get_tail_item(list_t *l)
-{
-  return l->tail;
-}
-
-void* 
-list_find(	list_t *l, 
-			void *datum)
-{
-  list_item_t *li;
-
-  for (li = l->head; li && l->compare(datum, list_item_get_datum(li));
-       li = li->next)
-    ;
-
-  return li ? li->datum : NULL;
-}
-
-void* 
-list_get_head(list_t *l)
-{
-  return l->head ? l->head->datum : NULL;
-}
-
-void* 
-list_get_tail(list_t *l)
-{
-  return l->tail ? l->tail->datum : NULL;
-}
-
-uint32_t 
-list_get_length(list_t *l)
-{
-  return l->length;
-}
-
-bool 
-list_is_empty(list_t *l)
-{
-  return (l->length == 0);
-}
-
-bool 
-list_not_empty(list_t *l)
-{
-  return (l->length != 0);
-}
-
-void 
-list_visit_items(	list_t *l, 
-					void (*visitor)(void *v))
-{
-  list_item_t *li;
-
-  for (li = l->head; li; li = li->next)
-    visitor(list_item_get_datum(li));
-}
-
-void 
-list_item_init(	list_item_t *li, 
-				void *datum)
-{
-  li->pred = li->next = NULL;
-  li->datum = datum;
-}
-
-void 
-list_item_delete(	list_item_t *li, 
-					void (*datum_delete)(void *datum))
-{
-  if (datum_delete) {
-    datum_delete(li->datum);
-  }
-
-  free(li);
-}
-
-void *
-list_item_get_datum(list_item_t *li)
-{
-  return li->datum;
-}
-
-void 
-list_iterator_init(	list_t *l, 
-					list_iterator_t *li)
-{
-  *li = l ? l->head : NULL;
-}
-
-void 
-list_iterator_delete(list_iterator_t *li)
-{
-  *li = NULL;
-}
-
-void 
-list_iterator_next(list_iterator_t *li)
-{
-  if (*li)
-    *li = (*li)->next;
-}
-
-void 
-list_iterator_prev(list_iterator_t *li)
-{
-  if (*li)
-    *li = (*li)->pred;
-}
-
-void *
-list_iterator_get_datum(list_iterator_t *li)
-{
-  return *li ? (*li)->datum : NULL;
-}
-
-bool 
-list_iterator_is_valid(list_iterator_t *li)
-{
-  return (*li != NULL);
-}
-
-void 
-list_reverse_iterator_init(	list_t *l, 
-							list_reverse_iterator_t *li)
-{
-  *li = l ? l->tail : NULL;
-}
-
-void 
-list_reverse_iterator_delete(list_reverse_iterator_t *li)
-{
-  *li = NULL;
-}
-
-void 
-list_reverse_iterator_next(list_reverse_iterator_t *li)
-{
-  if (*li)
-    *li = (*li)->pred;
-}
-
-void 
-list_reverse_iterator_prev(list_reverse_iterator_t *li)
-{
-  if (*li)
-    *li = (*li)->next;
-}
-
-void *
-list_reverse_iterator_get_datum(list_reverse_iterator_t *li)
-{
-  return *li ? (*li)->datum : NULL;
-}
-
-bool 
-list_reverse_iterator_is_valid(list_reverse_iterator_t *li)
-{
-  return (li != NULL);
-}
-
-//======================================================================================================================================================150
-// OUTPUT AND UTILITIES
-//======================================================================================================================================================150
-
-/*   */
-void *
-kmalloc(int size)
-{
-
-	//printf("size: %d, current offset: %p\n",size,freeptr);
-	void * r = (void *)freeptr;
-	freeptr+=size;
-	if(freeptr > malloc_size+(long)mem){
-		printf("Memory Overflow\n");
-		exit(1);
-	}
-	return r;
-}
-
-//transforms the current B+ Tree into a single, contiguous block of memory to be used on the GPU
-long 
-transform_to_cuda(	node * root, 
-					bool verbose)
-{
-
-	struct timeval one,two;
-	double time;
-	gettimeofday (&one, NULL);
-	long max_nodes = (long)(pow(order,log(size)/log(order/2.0)-1) + 1);
-	malloc_size = size*sizeof(record) + max_nodes*sizeof(knode); 
-	mem = (char*)malloc(malloc_size);
-	if(mem==NULL){
-		printf("Initial malloc error\n");
-		exit(1);
-	}
-	freeptr = (long)mem;
-
-	krecords = (record * )kmalloc(size*sizeof(record));
-	// printf("%d records\n", size);
-	knodes = (knode *)kmalloc(max_nodes*sizeof(knode));
-	// printf("%d knodes\n", max_nodes);
-
-	queue = NULL;
-	enqueue(root);
-	node * n;
-	knode * k;
-	int i;
-	long nodeindex = 0;
-	long recordindex = 0;
-	long queueindex = 0;
-	knodes[0].location = nodeindex++;
-	
-	while( queue != NULL ) {
-		n = dequeue();
-		k = &knodes[queueindex];
-		k->location = queueindex++;
-		k->is_leaf = n->is_leaf;
-		k->num_keys = n->num_keys+2;
-		//start at 1 because 0 is set to INT_MIN
-		k->keys[0]=INT_MIN; 
-		k->keys[k->num_keys-1]=INT_MAX;
-		for(i=k->num_keys; i < order; i++)k->keys[i]=INT_MAX;
-		if(!k->is_leaf){
-			k->indices[0]=nodeindex++;
-			// if(k->indices[0]>3953){
-				// printf("ERROR: %d\n", k->indices[0]);
-			// }
-			for(i=1;i<k->num_keys-1;i++){
-				k->keys[i] = n->keys[i-1];
-				enqueue((node * )n->pointers[i-1]);
-				k->indices[i] = nodeindex++;
-				// if(k->indices[i]>3953){
-					// printf("ERROR 1: %d\n", k->indices[i]);
-				// }
-				//knodes[nodeindex].location = nodeindex++;
-			}
-			//for final point of n
-			enqueue((node * )n->pointers[i-1]);
-		}
-		else{
-			k->indices[0]=0;
-			for(i=1;i<k->num_keys-1;i++){
-				k->keys[i] = n->keys[i-1];
-				krecords[recordindex].value=((record *)n->pointers[i-1])->value;
-				k->indices[i] = recordindex++;
-				// if(k->indices[i]>3953){
-					// printf("ERROR 2: %d\n", k->indices[i]);
-				// }
-			}
-		}
-		
-		k->indices[k->num_keys-1]=queueindex;
-		// if(k->indices[k->num_keys-1]>3953){
-			// printf("ERROR 3: %d\n", k->indices[k->num_keys-1]);
-		// }
-
-		if(verbose){
-			printf("Successfully created knode with index %d\n", k->location);
-			printf("Is Leaf: %d, Num Keys: %d\n", k->is_leaf, k->num_keys);
-			printf("Pointers: ");
-			for(i=0;i<k->num_keys;i++)
-				printf("%d | ", k->indices[i]);
-			printf("\nKeys: ");
-			for(i=0;i<k->num_keys;i++)
-				printf("%d | ", k->keys[i]);
-			printf("\n\n");
-		}
-	}
-	long mem_used = size*sizeof(record)+(nodeindex)*sizeof(knode);
-	if(verbose){
-		for(i = 0; i < size; i++)
-			printf("%d ", krecords[i].value);
-		printf("\nNumber of records = %d, sizeof(record)=%d, total=%d\n",size,sizeof(record),size*sizeof(record));
-		printf("Number of knodes = %d, sizeof(knode)=%d, total=%d\n",nodeindex,sizeof(knode),(nodeindex)*sizeof(knode));
-		printf("\nDone Transformation. Mem used: %d\n", mem_used);
-	}
-	gettimeofday (&two, NULL);
-	double oneD = one.tv_sec + (double)one.tv_usec * .000001;
-	double twoD = two.tv_sec + (double)two.tv_usec * .000001;
-	time = twoD-oneD;
-	printf("Tree transformation took %f\n", time);
-
-	return mem_used;
-
-}
-
-/*   */
-list_t *
-findRange(	node * root, 
-			int start, 
-			int end) 
-{
-
-	int i;
-	node * c = find_leaf( root, start, false );
-
-	if (c == NULL) return NULL;
-	
-	list_t * retList = (list_t *)malloc(sizeof(list_t));
-	list_init(retList,NULL,NULL);
-	
-	int counter = 0;
-	bool cont = true;
-	while(cont && c!=0){
-		cont = false;
-		for(i = 0;i  < c->num_keys;i++){
-			if(c->keys[i] >= start && c->keys[i] <= end){
-				//list_insert_tail(retList,(record *)c->pointers[i]);
-				counter++;
-				cont = true;
-			}else{
-				cont = false;
-				break;
-			}
-		}
-		c = (node *)c->pointers[order-1];
-	}
-	return retList;
-}
-
-/* First message to the user. */
-void 
-usage_1( void ) 
-{
-
-	printf("B+ Tree of Order %d.\n", order);
-	printf("\tAmittai Aviram -- amittai.aviram@yale.edu  Version %s\n", Version);
-	printf("\tfollowing Silberschatz, Korth, Sidarshan, Database Concepts, 5th ed.\n\n");
-	printf("To build a B+ tree of a different order, start again and enter the order\n");
-	printf("as an integer argument:  bpt <order>.  ");
-	printf("3 <= order <=20\n");
-	printf("To start with input from a file of newline-delimited integers, start again and enter\n");
-	printf("the order followed by the filename:  bpt <order> <inputfile>.\n");
-
-}
-
-/* Second message to the user. */
-void 
-usage_2( void ) 
-{
-
-	printf("Enter any of the following commands after the prompt > :\n");
-	printf("\ti <k>  -- Insert <k> (an integer) as both key and value).\n");
-	printf("\tf <k>  -- Find the value under key <k>.\n");
-	printf("\tp <k> -- Print the path from the root to key k and its associated value.\n");
-	printf("\td <k>  -- Delete key <k> and its associated value.\n");
-	printf("\tx -- Destroy the whole tree.  Start again with an empty tree of the same order.\n");
-	printf("\tt -- Print the B+ tree.\n");
-	printf("\tl -- Print the keys of the leaves (bottom row of the tree).\n");
-	printf("\tv -- Toggle output of pointer addresses (\"verbose\") in tree and leaves.\n");
-	printf("\tq -- Quit. (Or use Ctl-D.)\n");
-	printf("\t? -- Print this help message.\n");
-}
-
-/* Helper function for printing the tree out.  See print_tree. */
-void 
-enqueue( node* new_node ) 
-{
-	node * c;
-	if (queue == NULL) {
-		queue = new_node;
-		queue->next = NULL;
-	}
-	else {
-		c = queue;
-		while(c->next != NULL) {
-			c = c->next;
-		}
-		c->next = new_node;
-		new_node->next = NULL;
-	}
-}
-
-/* Helper function for printing the tree out.  See print_tree. */
-node *
-dequeue( void ) 
-{
-	node * n = queue;
-	queue = queue->next;
-	n->next = NULL;
-	return n;
-}
-
-/* Prints the bottom row of keys of the tree (with their respective pointers, if the verbose_output flag is set. */
-void 
-print_leaves( node* root ) 
-{
-	int i;
-	node * c = root;
-	if (root == NULL) {
-		printf("Empty tree.\n");
-		return;
-	}
-	while (!c->is_leaf)
-	c = (node *) c->pointers[0];
-	while (true) {
-		for (i = 0; i < c->num_keys; i++) {
-			if (verbose_output)
-			//printf("%x ", (unsigned int)c->pointers[i]);
-			printf("%d ", c->keys[i]);
-		}
-		if (verbose_output)
-		//printf("%x ", (unsigned int)c->pointers[order - 1]);
-		if (c->pointers[order - 1] != NULL) {
-			printf(" | ");
-			c = (node *) c->pointers[order - 1];
-		}
-		else
-		break;
-	}
-	printf("\n");
-}
-
-/* Utility function to give the height of the tree, which length in number of edges of the path from the root to any leaf. */
-int 
-height( node* root ) 
-{
-	int h = 0;
-	node * c = root;
-	while (!c->is_leaf) {
-		c = (node *) c->pointers[0];
-		h++;
-	}
-	return h;
-}
-
-/* Utility function to give the length in edges of the path from any node to the root. */
-int 
-path_to_root( node* root, node* child ) 
-{
-	int length = 0;
-	node * c = child;
-	while (c != root) {
-		c = c->parent;
-		length++;
-	}
-	return length;
-}
-
-/* Prints the B+ tree in the command line in level (rank) order, with the keys in each node and the '|' symbol to separate nodes. With the verbose_output flag set. the values of the pointers corresponding to the keys also appear next to their respective keys, in hexadecimal notation. */
-void 
-print_tree( node* root ) 
-{
-
-	node * n = NULL;
-	int i = 0;
-	int rank = 0;
-	int new_rank = 0;
-
-	if (root == NULL) {
-		printf("Empty tree.\n");
-		return;
-	}
-	queue = NULL;
-	enqueue(root);
-	while( queue != NULL ) {
-		n = dequeue();
-		if (n->parent != NULL && n == n->parent->pointers[0]) {
-			new_rank = path_to_root( root, n );
-			if (new_rank != rank) {
-				rank = new_rank;
-				printf("\n");
-			}
-		}
-		if (verbose_output) 
-		printf("(%x)", n);
-		for (i = 0; i < n->num_keys; i++) {
-			if (verbose_output)
-			printf("%x ", n->pointers[i]);
-			printf("%d ", n->keys[i]);
-		}
-		if (!n->is_leaf)
-		for (i = 0; i <= n->num_keys; i++)
-		enqueue((node *) n->pointers[i]);
-		if (verbose_output) {
-			if (n->is_leaf) 
-			printf("%x ", n->pointers[order - 1]);
-			else
-			printf("%x ", n->pointers[n->num_keys]);
-		}
-		printf("| ");
-	}
-	printf("\n");
-}
-
-/* Traces the path from the root to a leaf, searching by key.  Displays information about the path if the verbose flag is set. Returns the leaf containing the given key. */
-node *
-find_leaf( node* root, int key, bool verbose ) 
-{
-
-	int i = 0;
-	node * c = root;
-	if (c == NULL) {
-		if (verbose) 
-			printf("Empty tree.\n");
-		return c;
-	}
-	while (!c->is_leaf) {
-		if (verbose) {
-			printf("[");
-			for (i = 0; i < c->num_keys - 1; i++)
-				printf("%d ", c->keys[i]);
-			printf("%d] ", c->keys[i]);
-		}
-		i = 0;
-		while (i < c->num_keys) {
-			if (key >= c->keys[i]) 
-				i++;
-			else 
-				break;
-		}
-		if (verbose)
-			printf("%d ->\n", i);
-		c = (node *)c->pointers[i];
-	}
-	if (verbose) {
-		printf("Leaf [");
-		for (i = 0; i < c->num_keys - 1; i++)
-			printf("%d ", c->keys[i]);
-		printf("%d] ->\n", c->keys[i]);
-	}
-	return c;
-
-}
-
-/* Finds and returns the record to which a key refers. */
-record *
-find( node* root, int key, bool verbose ) 
-{
-
-	int i = 0;
-	node * c = find_leaf( root, key, verbose );
-	if (c == NULL) 
-		return NULL;
-	for (i = 0; i < c->num_keys; i++)
-		if (c->keys[i] == key) 
-			break;
-	if (i == c->num_keys) 
-		return NULL;
-	else
-		return (record *)c->pointers[i];
-
-}
-
-/* Finds the appropriate place to split a node that is too big into two. */
-int 
-cut( int length ) 
-{
-	if (length % 2 == 0)
-	return length/2;
-	else
-	return length/2 + 1;
-}
-
-//======================================================================================================================================================150
-// INSERTION
-//======================================================================================================================================================150
-
-/* Creates a new record to hold the value to which a key refers. */
-record *
-make_record(int value) 
-{
-	record * new_record = (record *)malloc(sizeof(record));
-	if (new_record == NULL) {
-		perror("Record creation.");
-		exit(EXIT_FAILURE);
-	}
-	else {
-		new_record->value = value;
-	}
-	return new_record;
-}
-
-/* Creates a new general node, which can be adapted to serve as either a leaf or an internal node. */
-node *
-make_node( void ) 
-{
-	node * new_node;
-	new_node = (node *) malloc(sizeof(node));
-	if (new_node == NULL) {
-		perror("Node creation.");
-		exit(EXIT_FAILURE);
-	}
-	new_node->keys = (int *) malloc( (order - 1) * sizeof(int) );
-	if (new_node->keys == NULL) {
-		perror("New node keys array.");
-		exit(EXIT_FAILURE);
-	}
-	new_node->pointers = (void **) malloc( order * sizeof(void *) );
-	if (new_node->pointers == NULL) {
-		perror("New node pointers array.");
-		exit(EXIT_FAILURE);
-	}
-	new_node->is_leaf = false;
-	new_node->num_keys = 0;
-	new_node->parent = NULL;
-	new_node->next = NULL;
-	return new_node;
-}
-
-/* Creates a new leaf by creating a node and then adapting it appropriately. */
-node *
-make_leaf( void ) 
-{
-	node* leaf = make_node();
-	leaf->is_leaf = true;
-	return leaf;
-}
-
-/* Helper function used in insert_into_parent to find the index of the parent's pointer to the node to the left of the key to be inserted. */
-int 
-get_left_index(node* parent, node* left) 
-{
-
-	int left_index = 0;
-	while (left_index <= parent->num_keys && 
-	parent->pointers[left_index] != left)
-	left_index++;
-	return left_index;
-}
-
-/* Inserts a new pointer to a record and its corresponding key into a leaf. Returns the altered leaf. */
-node *
-insert_into_leaf( node* leaf, int key, record* pointer ) 
-{
-
-	int i, insertion_point;
-
-	insertion_point = 0;
-	while (insertion_point < leaf->num_keys && leaf->keys[insertion_point] < key)
-	insertion_point++;
-
-	for (i = leaf->num_keys; i > insertion_point; i--) {
-		leaf->keys[i] = leaf->keys[i - 1];
-		leaf->pointers[i] = leaf->pointers[i - 1];
-	}
-	leaf->keys[insertion_point] = key;
-	leaf->pointers[insertion_point] = pointer;
-	leaf->num_keys++;
-	return leaf;
-}
-
-/* Inserts a new key and pointer to a new record into a leaf so as to exceed the tree's order, causing the leaf to be split in half. */
-node *
-insert_into_leaf_after_splitting(	node* root, 
-									node* leaf, 
-									int key, 
-									record* pointer) 
-{
-
-	node * new_leaf;
-	int * temp_keys;
-	void ** temp_pointers;
-	int insertion_index, split, new_key, i, j;
-
-	new_leaf = make_leaf();
-
-	temp_keys = (int *) malloc( order * sizeof(int) );
-	if (temp_keys == NULL) {
-		perror("Temporary keys array.");
-		exit(EXIT_FAILURE);
-	}
-
-	temp_pointers = (void **) malloc( order * sizeof(void *) );
-	if (temp_pointers == NULL) {
-		perror("Temporary pointers array.");
-		exit(EXIT_FAILURE);
-	}
-
-	insertion_index = 0;
-	while (leaf->keys[insertion_index] < key && insertion_index < order - 1)
-	insertion_index++;
-
-	for (i = 0, j = 0; i < leaf->num_keys; i++, j++) {
-		if (j == insertion_index) j++;
-		temp_keys[j] = leaf->keys[i];
-		temp_pointers[j] = leaf->pointers[i];
-	}
-
-	temp_keys[insertion_index] = key;
-	temp_pointers[insertion_index] = pointer;
-
-	leaf->num_keys = 0;
-
-	split = cut(order - 1);
-
-	for (i = 0; i < split; i++) {
-		leaf->pointers[i] = temp_pointers[i];
-		leaf->keys[i] = temp_keys[i];
-		leaf->num_keys++;
-	}
-
-	for (i = split, j = 0; i < order; i++, j++) {
-		new_leaf->pointers[j] = temp_pointers[i];
-		new_leaf->keys[j] = temp_keys[i];
-		new_leaf->num_keys++;
-	}
-
-	free(temp_pointers);
-	free(temp_keys);
-
-	new_leaf->pointers[order - 1] = leaf->pointers[order - 1];
-	leaf->pointers[order - 1] = new_leaf;
-
-	for (i = leaf->num_keys; i < order - 1; i++)
-	leaf->pointers[i] = NULL;
-	for (i = new_leaf->num_keys; i < order - 1; i++)
-	new_leaf->pointers[i] = NULL;
-
-	new_leaf->parent = leaf->parent;
-	new_key = new_leaf->keys[0];
-
-	return insert_into_parent(root, leaf, new_key, new_leaf);
-}
-
-/* Inserts a new key and pointer to a node into a node into which these can fit without violating the B+ tree properties. */
-node *
-insert_into_node(	node* root, 
-					node* n, 
-					int left_index, 
-					int key, 
-					node* right) 
-{
-
-	int i;
-
-	for (i = n->num_keys; i > left_index; i--) {
-		n->pointers[i + 1] = n->pointers[i];
-		n->keys[i] = n->keys[i - 1];
-	}
-	n->pointers[left_index + 1] = right;
-	n->keys[left_index] = key;
-	n->num_keys++;
-	return root;
-}
-
-/* Inserts a new key and pointer to a node into a node, causing the node's size to exceed the order, and causing the node to split into two. */
-node *
-insert_into_node_after_splitting(	node* root, 
-									node* old_node, 
-									int left_index, 
-									int key, 
-									node * right) 
-{
-
-	int i, j, split, k_prime;
-	node * new_node, * child;
-	int * temp_keys;
-	node ** temp_pointers;
-
-	/* First create a temporary set of keys and pointers
-* to hold everything in order, including
-* the new key and pointer, inserted in their
-* correct places. 
-* Then create a new node and copy half of the 
-* keys and pointers to the old node and
-* the other half to the new.
-*/
-
-	temp_pointers = (node **) malloc( (order + 1) * sizeof(node *) );
-	if (temp_pointers == NULL) {
-		perror("Temporary pointers array for splitting nodes.");
-		exit(EXIT_FAILURE);
-	}
-	temp_keys = (int *) malloc( order * sizeof(int) );
-	if (temp_keys == NULL) {
-		perror("Temporary keys array for splitting nodes.");
-		exit(EXIT_FAILURE);
-	}
-
-	for (i = 0, j = 0; i < old_node->num_keys + 1; i++, j++) {
-		if (j == left_index + 1) j++;
-		temp_pointers[j] = (node *) old_node->pointers[i];
-	}
-
-	for (i = 0, j = 0; i < old_node->num_keys; i++, j++) {
-		if (j == left_index) j++;
-		temp_keys[j] = old_node->keys[i];
-	}
-
-	temp_pointers[left_index + 1] = right;
-	temp_keys[left_index] = key;
-
-	/* Create the new node and copy
-* half the keys and pointers to the
-* old and half to the new.
-*/  
-	split = cut(order);
-	new_node = make_node();
-	old_node->num_keys = 0;
-	for (i = 0; i < split - 1; i++) {
-		old_node->pointers[i] = temp_pointers[i];
-		old_node->keys[i] = temp_keys[i];
-		old_node->num_keys++;
-	}
-	old_node->pointers[i] = temp_pointers[i];
-	k_prime = temp_keys[split - 1];
-	for (++i, j = 0; i < order; i++, j++) {
-		new_node->pointers[j] = temp_pointers[i];
-		new_node->keys[j] = temp_keys[i];
-		new_node->num_keys++;
-	}
-	new_node->pointers[j] = temp_pointers[i];
-	free(temp_pointers);
-	free(temp_keys);
-	new_node->parent = old_node->parent;
-	for (i = 0; i <= new_node->num_keys; i++) {
-		child = (node *) new_node->pointers[i];
-		child->parent = new_node;
-	}
-
-	/* Insert a new key into the parent of the two
-* nodes resulting from the split, with
-* the old node to the left and the new to the right.
-*/
-
-	return insert_into_parent(root, old_node, k_prime, new_node);
-}
-
-/* Inserts a new node (leaf or internal node) into the B+ tree. Returns the root of the tree after insertion. */
-node *
-insert_into_parent(	node* root, 
-					node* left, 
-					int key, 
-					node* right) 
-{
-
-	int left_index;
-	node * parent;
-
-	parent = left->parent;
-
-	/* Case: new root. */
-
-	if (parent == NULL)
-	return insert_into_new_root(left, key, right);
-
-	/* Case: leaf or node. (Remainder of
-* function body.)  
-*/
-
-	/* Find the parent's pointer to the left 
-* node.
-*/
-
-	left_index = get_left_index(parent, left);
-
-
-	/* Simple case: the new key fits into the node. 
-*/
-
-	if (parent->num_keys < order - 1)
-	return insert_into_node(root, parent, left_index, key, right);
-
-	/* Harder case:  split a node in order 
-* to preserve the B+ tree properties.
-*/
-
-	return insert_into_node_after_splitting(root, parent, left_index, key, right);
-}
-
-/* Creates a new root for two subtrees and inserts the appropriate key into the new root. */
-node *
-insert_into_new_root(	node* left, 
-						int key, 
-						node* right) 
-{
-
-	node * root = make_node();
-	root->keys[0] = key;
-	root->pointers[0] = left;
-	root->pointers[1] = right;
-	root->num_keys++;
-	root->parent = NULL;
-	left->parent = root;
-	right->parent = root;
-	return root;
-}
-
-/* First insertion: start a new tree. */
-node *
-start_new_tree(	int key, 
-				record* pointer) 
-{
-
-	node * root = make_leaf();
-	root->keys[0] = key;
-	root->pointers[0] = pointer;
-	root->pointers[order - 1] = NULL;
-	root->parent = NULL;
-	root->num_keys++;
-	return root;
-}
-
-/* Master insertion function. Inserts a key and an associated value into the B+ tree, causing the tree to be adjusted however necessary to maintain the B+ tree properties. */
-node *
-insert(	node* root, 
-		int key, 
-		int value ) 
-{
-
-	record* pointer;
-	node* leaf;
-
-	/* The current implementation ignores duplicates. */
-	if (find(root, key, false) != NULL)
-		return root;
-
-	/* Create a new record for the value. */
-	pointer = make_record(value);
-
-	/* Case: the tree does not exist yet. Start a new tree. */
-	if (root == NULL) 
-		return start_new_tree(key, pointer);
-
-	/* Case: the tree already exists. (Rest of function body.) */
-	leaf = find_leaf(root, key, false);
-
-	/* Case: leaf has room for key and pointer. */
-	if (leaf->num_keys < order - 1) {
-		leaf = insert_into_leaf(leaf, key, pointer);
-		return root;
-	}
-
-	/* Case:  leaf must be split. */
-	return insert_into_leaf_after_splitting(root, leaf, key, pointer);
-}
-
-//======================================================================================================================================================150
-// DELETION
-//======================================================================================================================================================150
-
-/* Utility function for deletion. Retrieves the index of a node's nearest neighbor (sibling) to the left if one exists.  If not (the node is the leftmost child), returns -1 to signify this special case. */
-int 
-get_neighbor_index( node* n ) 
-{
-
-	int i;
-
-	/* Return the index of the key to the left
-* of the pointer in the parent pointing
-* to n.  
-* If n is the leftmost child, this means
-* return -1.
-*/
-	for (i = 0; i <= n->parent->num_keys; i++)
-	if (n->parent->pointers[i] == n)
-	return i - 1;
-
-	// Error state.
-	printf("Search for nonexistent pointer to node in parent.\n");
-	//printf("Node:  %#x\n", (unsigned int)n);
-	exit(EXIT_FAILURE);
-}
-
-/*   */
-node* 
-remove_entry_from_node(	node* n, 
-						int key, 
-						node * pointer) 
-{
-
-	int i, num_pointers;
-
-	// Remove the key and shift other keys accordingly.
-	i = 0;
-	while (n->keys[i] != key)
-	i++;
-	for (++i; i < n->num_keys; i++)
-	n->keys[i - 1] = n->keys[i];
-
-	// Remove the pointer and shift other pointers accordingly.
-	// First determine number of pointers.
-	num_pointers = n->is_leaf ? n->num_keys : n->num_keys + 1;
-	i = 0;
-	while (n->pointers[i] != pointer)
-	i++;
-	for (++i; i < num_pointers; i++)
-	n->pointers[i - 1] = n->pointers[i];
-
-
-	// One key fewer.
-	n->num_keys--;
-
-	// Set the other pointers to NULL for tidiness.
-	// A leaf uses the last pointer to point to the next leaf.
-	if (n->is_leaf)
-	for (i = n->num_keys; i < order - 1; i++)
-	n->pointers[i] = NULL;
-	else
-	for (i = n->num_keys + 1; i < order; i++)
-	n->pointers[i] = NULL;
-
-	return n;
-}
-
-/*   */
-node* 
-adjust_root(node* root) 
-{
-
-	node * new_root;
-
-	/* Case: nonempty root.
-* Key and pointer have already been deleted,
-* so nothing to be done.
-*/
-
-	if (root->num_keys > 0)
-	return root;
-
-	/* Case: empty root. 
-*/
-
-	// If it has a child, promote 
-	// the first (only) child
-	// as the new root.
-
-	if (!root->is_leaf) {
-		new_root = (node *) root->pointers[0];
-		new_root->parent = NULL;
-	}
-
-	// If it is a leaf (has no children),
-	// then the whole tree is empty.
-
-	else
-	new_root = NULL;
-
-	free(root->keys);
-	free(root->pointers);
-	free(root);
-
-	return new_root;
-}
-
-/* Coalesces a node that has become too small after deletion with a neighboring node that can accept the additional entries without exceeding the maximum. */
-node* 
-coalesce_nodes(	node* root, 
-				node* n, 
-				node* neighbor, 
-				int neighbor_index, 
-				int k_prime) 
-				{
-
-	int i, j, neighbor_insertion_index, n_start, n_end, new_k_prime;
-	node * tmp;
-	bool split;
-
-	/* Swap neighbor with node if node is on the
-* extreme left and neighbor is to its right.
-*/
-
-	if (neighbor_index == -1) {
-		tmp = n;
-		n = neighbor;
-		neighbor = tmp;
-	}
-
-	/* Starting point in the neighbor for copying
-* keys and pointers from n.
-* Recall that n and neighbor have swapped places
-* in the special case of n being a leftmost child.
-*/
-
-	neighbor_insertion_index = neighbor->num_keys;
-	
-	/*
-* Nonleaf nodes may sometimes need to remain split,
-* if the insertion of k_prime would cause the resulting
-* single coalesced node to exceed the limit order - 1.
-* The variable split is always false for leaf nodes
-* and only sometimes set to true for nonleaf nodes.
-*/
-
-	split = false;
-
-	/* Case:  nonleaf node.
-* Append k_prime and the following pointer.
-* If there is room in the neighbor, append
-* all pointers and keys from the neighbor.
-* Otherwise, append only cut(order) - 2 keys and
-* cut(order) - 1 pointers.
-*/
-
-	if (!n->is_leaf) {
-
-		/* Append k_prime.
-	*/
-
-		neighbor->keys[neighbor_insertion_index] = k_prime;
-		neighbor->num_keys++;
-
-
-		/* Case (default):  there is room for all of n's keys and pointers
-	* in the neighbor after appending k_prime.
-	*/
-
-		n_end = n->num_keys;
-
-		/* Case (special): k cannot fit with all the other keys and pointers
-	* into one coalesced node.
-	*/
-		n_start = 0; // Only used in this special case.
-		if (n->num_keys + neighbor->num_keys >= order) {
-			split = true;
-			n_end = cut(order) - 2;
-		}
-
-		for (i = neighbor_insertion_index + 1, j = 0; j < n_end; i++, j++) {
-			neighbor->keys[i] = n->keys[j];
-			neighbor->pointers[i] = n->pointers[j];
-			neighbor->num_keys++;
-			n->num_keys--;
-			n_start++;
-		}
-
-		/* The number of pointers is always
-	* one more than the number of keys.
-	*/
-
-		neighbor->pointers[i] = n->pointers[j];
-
-		/* If the nodes are still split, remove the first key from
-	* n.
-	*/
-		if (split) {
-			new_k_prime = n->keys[n_start];
-			for (i = 0, j = n_start + 1; i < n->num_keys; i++, j++) {
-				n->keys[i] = n->keys[j];
-				n->pointers[i] = n->pointers[j];
-			}
-			n->pointers[i] = n->pointers[j];
-			n->num_keys--;
-		}
-
-		/* All children must now point up to the same parent.
-	*/
-
-		for (i = 0; i < neighbor->num_keys + 1; i++) {
-			tmp = (node *)neighbor->pointers[i];
-			tmp->parent = neighbor;
-		}
-	}
-
-	/* In a leaf, append the keys and pointers of
-* n to the neighbor.
-* Set the neighbor's last pointer to point to
-* what had been n's right neighbor.
-*/
-
-	else {
-		for (i = neighbor_insertion_index, j = 0; j < n->num_keys; i++, j++) {
-			neighbor->keys[i] = n->keys[j];
-			neighbor->pointers[i] = n->pointers[j];
-			neighbor->num_keys++;
-		}
-		neighbor->pointers[order - 1] = n->pointers[order - 1];
-	}
-
-	if (!split) {
-		root = delete_entry(root, n->parent, k_prime, n);
-		free(n->keys);
-		free(n->pointers);
-		free(n); 
-	}
-	else
-	for (i = 0; i < n->parent->num_keys; i++)
-	if (n->parent->pointers[i + 1] == n) {
-		n->parent->keys[i] = new_k_prime;
-		break;
-	}
-
-	return root;
-
-}
-
-/* Redistributes entries between two nodes when one has become too small after deletion but its neighbor is too big to append the small node's entries without exceeding the maximum */
-node* 
-redistribute_nodes(	node* root, 
-					node* n, 
-					node* neighbor, 
-					int neighbor_index, 
-					int k_prime_index, 
-					int k_prime) 
-{  
-
-	int i;
-	node * tmp;
-
-	/* Case: n has a neighbor to the left. 
-* Pull the neighbor's last key-pointer pair over
-* from the neighbor's right end to n's left end.
-*/
-
-	if (neighbor_index != -1) {
-		if (!n->is_leaf)
-		n->pointers[n->num_keys + 1] = n->pointers[n->num_keys];
-		for (i = n->num_keys; i > 0; i--) {
-			n->keys[i] = n->keys[i - 1];
-			n->pointers[i] = n->pointers[i - 1];
-		}
-		if (!n->is_leaf) {
-			n->pointers[0] = neighbor->pointers[neighbor->num_keys];
-			tmp = (node *)n->pointers[0];
-			tmp->parent = n;
-			neighbor->pointers[neighbor->num_keys] = NULL;
-			n->keys[0] = k_prime;
-			n->parent->keys[k_prime_index] = neighbor->keys[neighbor->num_keys - 1];
-		}
-		else {
-			n->pointers[0] = neighbor->pointers[neighbor->num_keys - 1];
-			neighbor->pointers[neighbor->num_keys - 1] = NULL;
-			n->keys[0] = neighbor->keys[neighbor->num_keys - 1];
-			n->parent->keys[k_prime_index] = n->keys[0];
-		}
-	}
-
-	/* Case: n is the leftmost child.
-* Take a key-pointer pair from the neighbor to the right.
-* Move the neighbor's leftmost key-pointer pair
-* to n's rightmost position.
-*/
-
-	else {  
-		if (n->is_leaf) {
-			n->keys[n->num_keys] = neighbor->keys[0];
-			n->pointers[n->num_keys] = neighbor->pointers[0];
-			n->parent->keys[k_prime_index] = neighbor->keys[1];
-		}
-		else {
-			n->keys[n->num_keys] = k_prime;
-			n->pointers[n->num_keys + 1] = neighbor->pointers[0];
-			tmp = (node *)n->pointers[n->num_keys + 1];
-			tmp->parent = n;
-			n->parent->keys[k_prime_index] = neighbor->keys[0];
-		}
-		for (i = 0; i < neighbor->num_keys; i++) {
-			neighbor->keys[i] = neighbor->keys[i + 1];
-			neighbor->pointers[i] = neighbor->pointers[i + 1];
-		}
-		if (!n->is_leaf)
-		neighbor->pointers[i] = neighbor->pointers[i + 1];
-	}
-
-	/* n now has one more key and one more pointer;
-* the neighbor has one fewer of each.
-*/
-
-	n->num_keys++;
-	neighbor->num_keys--;
-
-	return root;
-}
-
-/* Deletes an entry from the B+ tree. Removes the record and its key and pointer from the leaf, and then makes all appropriate changes to preserve the B+ tree properties. */
-node* 
-delete_entry(	node* root, 
-				node* n, 
-				int key, 
-				void* pointer ) 
-{
-
-	int min_keys;
-	node * neighbor;
-	int neighbor_index;
-	int k_prime_index, k_prime;
-	int capacity;
-
-	// Remove key and pointer from node.
-
-	n = remove_entry_from_node(n, key, (node *) pointer);
-
-	/* Case:  deletion from the root. 
-*/
-
-	if (n == root) 
-	return adjust_root(root);
-
-
-	/* Case:  deletion from a node below the root.
-* (Rest of function body.)
-*/
-
-	/* Determine minimum allowable size of node,
-* to be preserved after deletion.
-*/
-
-	min_keys = n->is_leaf ? cut(order - 1) : cut(order) - 1;
-
-	/* Case:  node stays at or above minimum.
-* (The simple case.)
-*/
-
-	if (n->num_keys >= min_keys)
-	return root;
-
-	/* Case:  node falls below minimum.
-* Either coalescence or redistribution
-* is needed.
-*/
-
-	/* Find the appropriate neighbor node with which
-* to coalesce.
-* Also find the key (k_prime) in the parent
-* between the pointer to node n and the pointer
-* to the neighbor.
-*/
-
-	neighbor_index = get_neighbor_index( n );
-	k_prime_index = neighbor_index == -1 ? 0 : neighbor_index;
-	k_prime = n->parent->keys[k_prime_index];
-	neighbor = neighbor_index == -1 ? (node *) n->parent->pointers[1] : 
-	(node *)n->parent->pointers[neighbor_index];
-
-	capacity = n->is_leaf ? order : order - 1;
-
-	/* Coalescence. */
-
-	if (neighbor->num_keys + n->num_keys < capacity)
-	return coalesce_nodes(root, n, neighbor, neighbor_index, k_prime);
-
-	/* Redistribution. */
-
-	else
-	return redistribute_nodes(root, n, neighbor, neighbor_index, k_prime_index, k_prime);
-}
-
-/* Master deletion function. */
-node* 
-deleteVal(	node* root, 
-			int key) 
-{
-
-	node * key_leaf;
-	record * key_record;
-
-	key_record = find(root, key, false);
-	key_leaf = find_leaf(root, key, false);
-	if (key_record != NULL && key_leaf != NULL) {
-		free(key_record);
-		root = delete_entry(root, key_leaf, key, key_record);
-	}
-	return root;
-}
-
-/*   */
-void 
-destroy_tree_nodes(node* root) 
-{
-	int i;
-	if (root->is_leaf)
-	for (i = 0; i < root->num_keys; i++)
-	free(root->pointers[i]);
-	else
-	for (i = 0; i < root->num_keys + 1; i++)
-	destroy_tree_nodes((node *) root->pointers[i]);
-	free(root->pointers);
-	free(root->keys);
-	free(root);
-}
-
-/*   */
-node* 
-destroy_tree(node* root) 
-{
-	destroy_tree_nodes(root);
-	return NULL;
-}
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	MAIN FUNCTION
-//========================================================================================================================================================================================================200
-
-int 
-main(	int argc, 
-		char** argv ) 
-{
-
-  printf("WG size of kernel 1 = %d WG size of kernel 2 = %d \n", DEFAULT_ORDER, DEFAULT_ORDER_2);
-	// ------------------------------------------------------------60
-	// figure out and display whether 32-bit or 64-bit architecture
-	// ------------------------------------------------------------60
-
-	// if(sizeof(int *)==8){
-		// printf("64 bit machine\n");
-	// }
-	// else if(sizeof(int *)==4){
-		// printf("32 bit machine\n");
-	// }
-
-	// ------------------------------------------------------------60
-	// read inputs
-	// ------------------------------------------------------------60
-
-	// assing default values
-	int cur_arg;
-	int arch_arg;
-	arch_arg = 0;
-	int cores_arg;
-	cores_arg = 1;
-	char *input_file = NULL;
-	char *command_file = NULL;
-	char *output="output.txt";
-	FILE * pFile;
-
-	// go through arguments
-	for(cur_arg=1; cur_arg<argc; cur_arg++){
-	  // check if -file
-	  if(strcmp(argv[cur_arg], "file")==0){
-	    // check if value provided
-	    if(argc>=cur_arg+1){
-	      input_file = argv[cur_arg+1];
-	      cur_arg = cur_arg+1;
-	      // value is not a number
-	    }
-	    // value not provided
-	    else{
-	      printf("ERROR: Missing value to -file parameter\n");
-	      return -1;
-	    }
-	  }
-	  else if(strcmp(argv[cur_arg], "command")==0){
-	    // check if value provided
-	    if(argc>=cur_arg+1){
-	      command_file = argv[cur_arg+1];
-	      cur_arg = cur_arg+1;
-	      // value is not a number
-	    }
-	    // value not provided
-	    else{
-	      printf("ERROR: Missing value to command parameter\n");
-	      return -1;
-	    }
-	  }
-	}
-	// Print configuration
-	  if((input_file==NULL)||(command_file==NULL))
-	    printf("Usage: ./b+tree file input_file command command_list\n");
-
-	  // For debug
-	  printf("Input File: %s \n", input_file);
-	  printf("Command File: %s \n", command_file);
-
-
-     FILE * commandFile;
-     long lSize;
-     char * commandBuffer;
-     size_t result;
-
-     commandFile = fopen ( command_file, "rb" );
-     if (commandFile==NULL) {fputs ("Command File error",stderr); exit (1);}
-     
-     // obtain file size:
-     fseek (commandFile , 0 , SEEK_END);
-     lSize = ftell (commandFile);
-     rewind (commandFile);
-
-     // allocate memory to contain the whole file:
-     commandBuffer = (char*) malloc (sizeof(char)*lSize);
-     if (commandBuffer == NULL) {fputs ("Command Buffer memory error",stderr); exit (2);}
-     
-     // copy the file into the buffer:
-     result = fread (commandBuffer,1,lSize,commandFile);
-     if (result != lSize) {fputs ("Command file reading error",stderr); exit (3);}
-
-     /* the whole file is now loaded in the memory buffer. */
-
-  // terminate
-     fclose (commandFile);
-
-     // For Debug
-     char *sPointer=commandBuffer;
-     printf("Command Buffer: \n");
-     printf("%s",commandBuffer);
-     //
-
-
-     pFile = fopen (output,"w+");
-     if (pFile==NULL) 
-       fputs ("Fail to open %s !\n",output);
-     fprintf(pFile,"******starting******\n");
-     fclose(pFile);
-
-	// ------------------------------------------------------------60
-	// general variables
-	// ------------------------------------------------------------60
-
-	FILE *file_pointer;
-	node *root;
-	root = NULL;
-	record *r;
-	int input;
-	char instruction;
-	order = DEFAULT_ORDER_2;
-	verbose_output = false;
-
-	//usage_1();  
-	//usage_2();
-
-	// ------------------------------------------------------------60
-	// get input from file, if file provided
-	// ------------------------------------------------------------60
-
-	if (input_file != NULL) {
-
-		printf("Getting input from file %s...\n", argv[1]);
-
-		// open input file
-		file_pointer = fopen(input_file, "r");
-		if (file_pointer == NULL) {
-			perror("Failure to open input file.");
-			exit(EXIT_FAILURE);
-		}
-
-		// get # of numbers in the file
-		fscanf(file_pointer, "%d\n", &input);
-		size = input;
-
-		// save all numbers
-		while (!feof(file_pointer)) {
-			fscanf(file_pointer, "%d\n", &input);
-			root = insert(root, input, input);
-		}
-
-		// close file
-		fclose(file_pointer);
-		//print_tree(root);
-		//printf("Height of tree = %d\n", height(root));
-
-	}
-	else{
-		printf("ERROR: Argument -file missing\n");
-		return 0;
-	}
-
-	// ------------------------------------------------------------60
-	// get tree statistics
-	// ------------------------------------------------------------60
-
-	printf("Transforming data to a GPU suitable structure...\n");
-	long mem_used = transform_to_cuda(root,0);
-	maxheight = height(root);
-	long rootLoc = (long)knodes - (long)mem;
-
-	// ------------------------------------------------------------60
-	// process commands
-	// ------------------------------------------------------------60
-	char *commandPointer=commandBuffer;
-	printf("Waiting for command\n");
-	printf("> ");
-	while (sscanf(commandPointer, "%c", &instruction) != EOF) {
-	  commandPointer++;
-	  switch (instruction) {
-			// ----------------------------------------40
-			// Insert
-			// ----------------------------------------40
-
-			case 'i':
-			{
-				scanf("%d", &input);
-				while (getchar() != (int)'\n');
-				root = insert(root, input, input);
-				print_tree(root);
-				break;
-			}
-
-			// ----------------------------------------40
-			// n/a
-			// ----------------------------------------40
-
-			case 'f':
-			{
-			}
-
-			// ----------------------------------------40
-			// find
-			// ----------------------------------------40
-
-			case 'p':
-			{
-				scanf("%d", &input);
-				while (getchar() != (int)'\n');
-				r = find(root, input, instruction == 'p');
-				if (r == NULL)
-				printf("Record not found under key %d.\n", input);
-				else 
-				printf("Record found: %d\n",r->value);
-				break;
-			}
-
-			// ----------------------------------------40
-			// delete value
-			// ----------------------------------------40
-
-			case 'd':
-			{
-				scanf("%d", &input);
-				while (getchar() != (int)'\n');
-				root = (node *) deleteVal(root, input);
-				print_tree(root);
-				break;
-			}
-
-			// ----------------------------------------40
-			// destroy tree
-			// ----------------------------------------40
-
-			case 'x':
-			{
-				while (getchar() != (int)'\n');
-				root = destroy_tree(root);
-				print_tree(root);
-				break;
-			}
-
-			// ----------------------------------------40
-			// print leaves
-			// ----------------------------------------40
-
-			case 'l':
-			{
-				while (getchar() != (int)'\n');
-				print_leaves(root);
-				break;
-			}
-
-			// ----------------------------------------40
-			// print tree
-			// ----------------------------------------40
-
-			case 't':
-			{
-				while (getchar() != (int)'\n');
-				print_tree(root);
-				break;
-			}
-
-			// ----------------------------------------40
-			// toggle verbose output
-			// ----------------------------------------40
-
-			case 'v':
-			{
-				while (getchar() != (int)'\n');
-				verbose_output = !verbose_output;
-				break;
-			}
-
-			// ----------------------------------------40
-			// quit
-			// ----------------------------------------40
-
-			case 'q':
-			{
-				while (getchar() != (int)'\n');
-				return EXIT_SUCCESS;
-			}
-
-			// ----------------------------------------40
-			// [GPU] find K (initK, findK)
-			// ----------------------------------------40
-
-			case 'k':
-			{
-
-				// get # of queries from user
-				int count;
-				sscanf(commandPointer, "%d", &count);
-				while(*commandPointer!=32 && commandPointer!='\n')
-				  commandPointer++;
-
-				printf("\n ******command: k count=%d \n",count);
-				if(count > 65535){
-					printf("ERROR: Number of requested querries should be 65,535 at most. (limited by # of CUDA blocks)\n");
-					exit(0);
-				}
-
-				// INPUT: records CPU allocation (setting pointer in mem variable)
-				record *records = (record *)mem;
-				long records_elem = (long)rootLoc / sizeof(record);
-				long records_mem = (long)rootLoc;
-				printf("records_elem=%d, records_unit_mem=%d, records_mem=%d\n", (int)records_elem, (int)sizeof(record), (int)records_mem);
-
-				// INPUT: knodes CPU allocation (setting pointer in mem variable)
-				knode *knodes = (knode *)((long)mem + (long)rootLoc);
-				long knodes_elem = ((long)(mem_used) - (long)rootLoc) / sizeof(knode);
-				long knodes_mem = (long)(mem_used) - (long)rootLoc;
-				printf("knodes_elem=%d, knodes_unit_mem=%d, knodes_mem=%d\n", (int)knodes_elem, (int)sizeof(knode), (int)knodes_mem);
-
-				// INPUT: currKnode CPU allocation
-				long *currKnode;
-				currKnode = (long *)malloc(count*sizeof(long));
-				// INPUT: offset CPU initialization
-				memset(currKnode, 0, count*sizeof(long));
-
-				// INPUT: offset CPU allocation
-				long *offset;
-				offset = (long *)malloc(count*sizeof(long));
-				// INPUT: offset CPU initialization
-				memset(offset, 0, count*sizeof(long));
-
-				// INPUT: keys CPU allocation
-				int *keys;
-				keys = (int *)malloc(count*sizeof(int));
-				// INPUT: keys CPU initialization
-				int i;
-				for(i = 0; i < count; i++){
-					keys[i] = (rand()/(float)RAND_MAX)*size;
-				}
-
-				// OUTPUT: ans CPU allocation
-				record *ans = (record *)malloc(sizeof(record)*count);
-				// OUTPUT: ans CPU initialization
-				for(i = 0; i < count; i++){
-					ans[i].value = -1;
-				}
-
-				// OpenCL kernel
-				kernel_gpu_opencl_wrapper(	records,
-											records_mem,
-											knodes,
-											knodes_elem,
-											knodes_mem,
-
-											order,
-											maxheight,
-											count,
-
-											currKnode,
-											offset,
-											keys,
-											ans);
-
-				pFile = fopen (output,"aw+");
-				if (pFile==NULL)
-				  {
-				    fputs ("Fail to open %s !\n",output);
-				  }
-				
-				fprintf(pFile,"\n ******command: k count=%d \n",count);
-				for(i = 0; i < count; i++){
-				  fprintf(pFile, "%d    %d\n",i, ans[i].value);
-				}
-				fprintf(pFile, " \n");
-                                fclose(pFile);
-				
-
-				// free memory
-				free(currKnode);
-				free(offset);
-				free(keys);
-				free(ans);
-
-				// break out of case
-				break;
-
-			}
-
-			// ----------------------------------------40
-			// find range
-			// ----------------------------------------40
-
-			case 'r':
-			{
-				int start, end;
-				scanf("%d", &start);
-				scanf("%d", &end);
-				if(start > end){
-					input = start;
-					start = end;
-					end = input;
-				}
-				printf("For range %d to %d, ",start,end);
-				list_t * ansList;
-				ansList = findRange(root, start, end);
-				printf("%d records found\n", list_get_length(ansList));
-				//list_iterator_t iter;
-				free(ansList);
-				break;
-			}
-
-			// ----------------------------------------40
-			// [GPU] find Range K (initK, findRangeK)
-			// ----------------------------------------40
-
-			case 'j':
-			{
-
-				// get # of queries from user
-				int count;
-				sscanf(commandPointer, "%d", &count);
-				while(*commandPointer!=32 && commandPointer!='\n')
-				  commandPointer++;
-
-				int rSize;
-				sscanf(commandPointer, "%d", &rSize);
-				while(*commandPointer!=32 && commandPointer!='\n')
-				  commandPointer++;
-
-				printf("\n******command: j count=%d, rSize=%d \n",count, rSize);
-
-				if(rSize > size || rSize < 0) {
-					printf("Search range size is larger than data set size %d.\n", (int)size);
-					exit(0);
-				}
-
-				// INPUT: knodes CPU allocation (setting pointer in mem variable)
-				knode *knodes = (knode *)((long)mem + (long)rootLoc);
-				long knodes_elem = ((long)(mem_used) - (long)rootLoc) / sizeof(knode);
-				long knodes_mem = (long)(mem_used) - (long)rootLoc;
-				printf("knodes_elem=%d, knodes_unit_mem=%d, knodes_mem=%d\n", (int)knodes_elem, (int)sizeof(knode), (int)knodes_mem);
-
-				// INPUT: currKnode CPU allocation
-				long *currKnode;
-				currKnode = (long *)malloc(count*sizeof(long));
-				// INPUT: offset CPU initialization
-				memset (currKnode, 0, count*sizeof(long));
-
-				// INPUT: offset CPU allocation
-				long *offset;
-				offset = (long *)malloc(count*sizeof(long));
-				// INPUT: offset CPU initialization
-				memset (offset, 0, count*sizeof(long));
-
-				// INPUT: lastKnode CPU allocation
-				long *lastKnode;
-				lastKnode = (long *)malloc(count*sizeof(long));
-				// INPUT: offset CPU initialization
-				memset (lastKnode, 0, count*sizeof(long));
-
-				// INPUT: offset_2 CPU allocation
-				long *offset_2;
-				offset_2 = (long *)malloc(count*sizeof(long));
-				// INPUT: offset CPU initialization
-				memset (offset_2, 0, count*sizeof(long));
-
-				// INPUT: start, end CPU allocation
-				int *start;
-				start = (int *)malloc(count*sizeof(int));
-				int *end;
-				end = (int *)malloc(count*sizeof(int));
-				// INPUT: start, end CPU initialization
-				int i;
-				for(i = 0; i < count; i++){
-					start[i] = (rand()/(float)RAND_MAX)*size;
-					end[i] = start[i]+rSize;
-					if(end[i] >= size){ 
-						start[i] = start[i] - (end[i] - size);
-						end[i]= size-1;
-					}
-				}
-
-				// INPUT: recstart, reclenght CPU allocation
-				int *recstart;
-				recstart = (int *)malloc(count*sizeof(int));
-				int *reclength;
-				reclength = (int *)malloc(count*sizeof(int));
-				// OUTPUT: ans CPU initialization
-				for(i = 0; i < count; i++){
-					recstart[i] = 0;
-					reclength[i] = 0;
-				}
-
-				// CUDA kernel
-				kernel_gpu_opencl_wrapper_2(knodes,
-											knodes_elem,
-											knodes_mem,
-
-											order,
-											maxheight,
-											count,
-
-											currKnode,
-											offset,
-											lastKnode,
-											offset_2,
-											start,
-											end,
-											recstart,
-											reclength);
-
-			
-				pFile = fopen (output,"aw+");
-				if (pFile==NULL)
-				  {
-				    fputs ("Fail to open %s !\n",output);
-				  }
-
-				fprintf(pFile,"\n******command: j count=%d, rSize=%d \n",count, rSize);				
-				for(i = 0; i < count; i++){
-				  fprintf(pFile, "%d    %d    %d\n",i, recstart[i],reclength[i]);
-				}
-				fprintf(pFile, " \n");
-                                fclose(pFile);
-
-				// free memory
-				free(currKnode);
-				free(offset);
-				free(lastKnode);
-				free(offset_2);
-				free(start);
-				free(end);
-				free(recstart);
-				free(reclength);
-
-				// break out of case
-				break;
-
-			}
-
-			// ----------------------------------------40
-			// default
-			// ----------------------------------------40
-
-			default:
-			{
-
-				//usage_2();
-				break;
-
-			}
-
-		}
-		printf("> ");
-
-	}
-	printf("\n");
-
-	// ------------------------------------------------------------60
-	// free remaining memory and exit
-	// ------------------------------------------------------------60
-
-	free(mem);
-	return EXIT_SUCCESS;
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// # ifdef __cplusplus
-// }
-// # endif

+ 0 - 19
opencl/b+tree/main.h

@@ -1,19 +0,0 @@
-// # ifdef __cplusplus
-// extern "C" {
-// # endif
-
-//===============================================================================================================================================================================================================200
-//	HEADER
-//===============================================================================================================================================================================================================200
-
-int 
-main(	int argc, 
-		char *argv []);
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-// # ifdef __cplusplus
-// }
-// # endif

BIN
opencl/b+tree/penmp


+ 0 - 1
opencl/b+tree/run

@@ -1 +0,0 @@
-./b+tree.out file ../../data/b+tree/mil.txt command ../../data/b+tree/command.txt

+ 0 - 53
opencl/b+tree/util/num/num.c

@@ -1,53 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	DESCRIPTION
-//===============================================================================================================================================================================================================200
-
-// Returns:	0 if string does not represent integer
-//			1 if string represents integer
-
-//===============================================================================================================================================================================================================200
-//	NUM CODE
-//===============================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	ISINTEGER FUNCTION
-//======================================================================================================================================================150
-
-int isInteger(char *str){
-
-	//====================================================================================================100
-	//	make sure it's not empty
-	//====================================================================================================100
-
-	if (*str == '\0'){
-		return 0;
-	}
-
-	//====================================================================================================100
-	//	if any digit is not a number, return false
-	//====================================================================================================100
-
-	for(; *str != '\0'; str++){
-		if (*str < 48 || *str > 57){	// digit characters (need to include . if checking for float)
-			return 0;
-		}
-	}
-
-	//====================================================================================================100
-	//	it got past all my checks so I think it's a number
-	//====================================================================================================100
-
-	return 1;
-}
-
-//===============================================================================================================================================================================================================200
-//	END NUM CODE
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 21
opencl/b+tree/util/num/num.h

@@ -1,21 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	FILE HEADER
-//===============================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	ISINTEGER FUNCTION PROTOTYPE
-//======================================================================================================================================================150
-
-int isInteger(char *str);
-
-//===============================================================================================================================================================================================================200
-//	END FILE HEADER
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 138
opencl/b+tree/util/opencl/opencl.c

@@ -1,138 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	INCLUDE/DEFINE
-//===============================================================================================================================================================================================================200
-
-#include "opencl.h"					// (in directory)	function headers
-#include <CL/cl.h>
-//===============================================================================================================================================================================================================200
-//	LOAD KERNEL SOURCE CODE FUNCTION
-//===============================================================================================================================================================================================================200
-
-char *
-load_kernel_source(const char *filename)
-{
-	// Open the source file
-	FILE *file = fopen(filename, "r");
-	if (file == NULL){
-		fatal("Error opening kernel source file\n");
-	}
-
-	// Determine the size of the file
-	if (fseek(file, 0, SEEK_END)){
-		fatal("Error reading kernel source file\n");
-	}
-	size_t size = ftell(file);
-
-	// Allocate space for the source code (plus one for null-terminator)
-	char *source = (char *) malloc(size + 1);
-
-	// Read the source code into the string
-	fseek(file, 0, SEEK_SET);
-	// printf("Number of elements: %lu\nSize = %lu", fread(source, 1, size, file), size);
-	// exit(1);
-	if (fread(source, 1, size, file) != size){
-		fatal("Error reading kernel source file\n");
-	}
-
-	// Null-terminate the string
-	source[size] = '\0';
-
-	// Return the pointer to the string
-	return source;
-}
-
-//===============================================================================================================================================================================================================200
-//	PRINT ERROR FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-fatal(const char *s)
-{
-	fprintf(stderr, "Error: %s\n", s);
-	exit(1);
-}
-
-//===============================================================================================================================================================================================================200
-//	PRINT OPENCL ERROR FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-fatal_CL(cl_int error, int line_no) {
-
-	printf("Error at line %d: ", line_no);
-
-	switch(error) {
-
-		case CL_SUCCESS: 									printf("CL_SUCCESS\n"); break;
-		case CL_DEVICE_NOT_FOUND: 							printf("CL_DEVICE_NOT_FOUND\n"); break;
-		case CL_DEVICE_NOT_AVAILABLE: 						printf("CL_DEVICE_NOT_AVAILABLE\n"); break;
-		case CL_COMPILER_NOT_AVAILABLE: 					printf("CL_COMPILER_NOT_AVAILABLE\n"); break;
-		case CL_MEM_OBJECT_ALLOCATION_FAILURE: 				printf("CL_MEM_OBJECT_ALLOCATION_FAILURE\n"); break;
-		case CL_OUT_OF_RESOURCES: 							printf("CL_OUT_OF_RESOURCES\n"); break;
-		case CL_OUT_OF_HOST_MEMORY: 						printf("CL_OUT_OF_HOST_MEMORY\n"); break;
-		case CL_PROFILING_INFO_NOT_AVAILABLE: 				printf("CL_PROFILING_INFO_NOT_AVAILABLE\n"); break;
-		case CL_MEM_COPY_OVERLAP: 							printf("CL_MEM_COPY_OVERLAP\n"); break;
-		case CL_IMAGE_FORMAT_MISMATCH: 						printf("CL_IMAGE_FORMAT_MISMATCH\n"); break;
-		case CL_IMAGE_FORMAT_NOT_SUPPORTED: 				printf("CL_IMAGE_FORMAT_NOT_SUPPORTED\n"); break;
-		case CL_BUILD_PROGRAM_FAILURE: 						printf("CL_BUILD_PROGRAM_FAILURE\n"); break;
-		case CL_MAP_FAILURE: 								printf("CL_MAP_FAILURE\n"); break;
-		case CL_INVALID_VALUE: 								printf("CL_INVALID_VALUE\n"); break;
-		case CL_INVALID_DEVICE_TYPE: 						printf("CL_INVALID_DEVICE_TYPE\n"); break;
-		case CL_INVALID_PLATFORM: 							printf("CL_INVALID_PLATFORM\n"); break;
-		case CL_INVALID_DEVICE: 							printf("CL_INVALID_DEVICE\n"); break;
-		case CL_INVALID_CONTEXT: 							printf("CL_INVALID_CONTEXT\n"); break;
-		case CL_INVALID_QUEUE_PROPERTIES: 					printf("CL_INVALID_QUEUE_PROPERTIES\n"); break;
-		case CL_INVALID_COMMAND_QUEUE: 						printf("CL_INVALID_COMMAND_QUEUE\n"); break;
-		case CL_INVALID_HOST_PTR: 							printf("CL_INVALID_HOST_PTR\n"); break;
-		case CL_INVALID_MEM_OBJECT: 						printf("CL_INVALID_MEM_OBJECT\n"); break;
-		case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: 			printf("CL_INVALID_IMAGE_FORMAT_DESCRIPTOR\n"); break;
-		case CL_INVALID_IMAGE_SIZE: 						printf("CL_INVALID_IMAGE_SIZE\n"); break;
-		case CL_INVALID_SAMPLER: 							printf("CL_INVALID_SAMPLER\n"); break;
-		case CL_INVALID_BINARY: 							printf("CL_INVALID_BINARY\n"); break;
-		case CL_INVALID_BUILD_OPTIONS: 						printf("CL_INVALID_BUILD_OPTIONS\n"); break;
-		case CL_INVALID_PROGRAM: 							printf("CL_INVALID_PROGRAM\n"); break;
-		case CL_INVALID_PROGRAM_EXECUTABLE: 				printf("CL_INVALID_PROGRAM_EXECUTABLE\n"); break;
-		case CL_INVALID_KERNEL_NAME: 						printf("CL_INVALID_KERNEL_NAME\n"); break;
-		case CL_INVALID_KERNEL_DEFINITION: 					printf("CL_INVALID_KERNEL_DEFINITION\n"); break;
-		case CL_INVALID_KERNEL: 							printf("CL_INVALID_KERNEL\n"); break;
-		case CL_INVALID_ARG_INDEX: 							printf("CL_INVALID_ARG_INDEX\n"); break;
-		case CL_INVALID_ARG_VALUE: 							printf("CL_INVALID_ARG_VALUE\n"); break;
-		case CL_INVALID_ARG_SIZE: 							printf("CL_INVALID_ARG_SIZE\n"); break;
-		case CL_INVALID_KERNEL_ARGS: 						printf("CL_INVALID_KERNEL_ARGS\n"); break;
-		case CL_INVALID_WORK_DIMENSION: 					printf("CL_INVALID_WORK_DIMENSION\n"); break;
-		case CL_INVALID_WORK_GROUP_SIZE: 					printf("CL_INVALID_WORK_GROUP_SIZE\n"); break;
-		case CL_INVALID_WORK_ITEM_SIZE: 					printf("CL_INVALID_WORK_ITEM_SIZE\n"); break;
-		case CL_INVALID_GLOBAL_OFFSET: 						printf("CL_INVALID_GLOBAL_OFFSET\n"); break;
-		case CL_INVALID_EVENT_WAIT_LIST: 					printf("CL_INVALID_EVENT_WAIT_LIST\n"); break;
-		case CL_INVALID_EVENT: 								printf("CL_INVALID_EVENT\n"); break;
-		case CL_INVALID_OPERATION: 							printf("CL_INVALID_OPERATION\n"); break;
-		case CL_INVALID_GL_OBJECT: 							printf("CL_INVALID_GL_OBJECT\n"); break;
-		case CL_INVALID_BUFFER_SIZE: 						printf("CL_INVALID_BUFFER_SIZE\n"); break;
-		case CL_INVALID_MIP_LEVEL: 							printf("CL_INVALID_MIP_LEVEL\n"); break;
-		case CL_INVALID_GLOBAL_WORK_SIZE: 					printf("CL_INVALID_GLOBAL_WORK_SIZE\n"); break;
-
-		#ifdef CL_VERSION_1_1
-		case CL_MISALIGNED_SUB_BUFFER_OFFSET: 				printf("CL_MISALIGNED_SUB_BUFFER_OFFSET\n"); break;
-		case CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST:	printf("CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST\n"); break;
-		/* case CL_INVALID_PROPERTY: 							printf("CL_INVALID_PROPERTY\n"); break; */
-		#endif
-
-		default:											printf("Invalid OpenCL error code\n");
-
-	}
-
-	exit(error);
-
-}
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 40
opencl/b+tree/util/opencl/opencl.h

@@ -1,40 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	INCLUDE/DEFINE
-//===============================================================================================================================================================================================================200
-
-#include <stdio.h>					// (in path known to compiler)		needed by printf
-
-#include <CL/cl.h>					// (in path specified to compiler)	needed by OpenCL types
-
-//===============================================================================================================================================================================================================200
-//	LOAD KERNEL SOURCE CODE FUNCTION HEADER
-//===============================================================================================================================================================================================================200
-
-char *
-load_kernel_source(const char *filename);
-
-//===============================================================================================================================================================================================================200
-//	PRINT ERROR FUNCTION HEADER
-//===============================================================================================================================================================================================================200
-
-void 
-fatal(const char *s);
-
-//===============================================================================================================================================================================================================200
-//	PRINT OPENCL ERROR FUNCTION HEADER
-//===============================================================================================================================================================================================================200
-
-void 
-fatal_CL(cl_int error, int line_no);
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 36
opencl/b+tree/util/timer/timer.c

@@ -1,36 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	TIMER CODE
-//===============================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	INCLUDE/DEFINE
-//======================================================================================================================================================150
-
-#include <stdlib.h>
-
-//======================================================================================================================================================150
-//	FUNCTIONS
-//======================================================================================================================================================150
-
-//====================================================================================================100
-//	DISPLAY TIME
-//====================================================================================================100
-
- // Returns the current system time in microseconds
-long long get_time() {
-	struct timeval tv;
-	gettimeofday(&tv, NULL);
-	return (tv.tv_sec * 1000000) + tv.tv_usec;
-}
-
-//===============================================================================================================================================================================================================200
-//	END TIMER CODE
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 22
opencl/b+tree/util/timer/timer.h

@@ -1,22 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	TIMER HEADER
-//===============================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	FUNCTION PROTOTYPES
-//======================================================================================================================================================150
-
-long long 
-get_time();
-
-//===============================================================================================================================================================================================================200
-//	END TIMER HEADER
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 9
opencl/heartwall/README

@@ -1,9 +0,0 @@
-******Adjustable work group size*****
-USAGE:
-make clean
-make KERNEL_DIM="-DRD_WG_SIZE_0=256"
-
-######OUTPUT FOR VALIDATION########
-USAGE:
-make clean
-make OUTPUT=Y

+ 0 - 82
opencl/heartwall/info/README

@@ -1,82 +0,0 @@
-//========================================================================================================================================================================================================200
-//	INFO
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	UPDATE
-//======================================================================================================================================================150
-
-//	2009.12 Lukasz G. Szafaryn
-//		-- converted from MATLAB to CUDA
-//	2010.01 Lukasz G. Szafaryn
-//		-- arranged, commented
-//	2012.05 Lukasz G. Szafaryn
-//		-- arranged, commented
-//	2012.05 Lukasz G. Szafaryn
-//		-- converted from CUDA to OpenCL
-
-//======================================================================================================================================================150
-//	DESCRIPTION
-//======================================================================================================================================================150
-
-// The Heart Wall application tracks the movement of a mouse heart over a sequence of 104 609x590 ultrasound images to record response to the stimulus. 
-// In its initial stage, the program performs image processing operations on the first image to detect initial, partial shapes of inner and outer heart walls. 
-// These operations include: edge detection, SRAD despeckling (also part of Rodinia suite), morphological transformation and dilation. In order to reconstruct 
-// approximated full shapes of heart walls, the program generates ellipses that are superimposed over the image and sampled to mark points on the heart walls 
-// (Hough Search). In its final stage (Heart Wall Tracking presented here), program tracks movement of surfaces by detecting the movement of image areas under 
-// sample points as the shapes of the heart walls change throughout the sequence of images.
-
-// Tracking is the final stage of the Heart Wall application. It takes the positions of heart walls from the first ultrasound image in the sequence as determined by the 
-// initial detection stage in the application. Tracking code is implemented in the form of multiple nested loops that process batches of 10 frames and 51 points in each 
-// image. Displacement of heart walls is detected by comparing currently processed frame to the template frame which is updated after processing a batch of frames. 
-// There is a sequential dependency between processed frames. The processing of each point consist of a large number of small serial steps with interleaved control 
-// statements. Each of the steps involves a small amount of computation performed only on a subset of entire image. This stage of the application accounts for almost 
-// all of the execution time (the exact ratio depends on the number of ultrasound images). 
-
-//======================================================================================================================================================150
-//	PAPERS
-//======================================================================================================================================================150
-
-// L. G. Szafaryn, K. Skadron, and J. J. Saucerman. "Experiences Accelerating MATLAB Systems Biology Applications." In Proceedings of the Workshop on Biomedicine 
-// in Computing: Systems, Architectures, and Circuits (BiC) 2009, in conjunction with the 36th IEEE/ACM International Symposium on Computer Architecture (ISCA), 
-// June 2009. <http://www.cs.virginia.edu/~skadron/Papers/BiC09.pdf>
-
-//======================================================================================================================================================150
-//	DOWNLOAD
-//======================================================================================================================================================150
-
-// Rodinia Benchmark Suite page
-
-//======================================================================================================================================================150
-//	IMPLEMENTATION-SPECIFIC DESCRIPTION (OpenCL)
-//======================================================================================================================================================150
-
-// This is the OpenCL version of Tracking code.
-
-// OpenCL implementation of this code is a classic example of the exploitation of braided parallelism. Processing of sample points is assigned to multiprocessors (TLP), 
-// while processing of individual pixels in each sample image is assigned to processors inside each multiprocessor. However, each GPU multiprocessor is usually 
-// underutilized because of the limited amount of computation at each computation step. Large size of processed images and lack temporal locality did not allow for 
-// utilization of fast shared memory. Also the GPU overhead (data transfer and kernel launch) are significant. In order to provide better speedup, more drastic GPU 
-// optimization techniques that sacrificed modularity (in order to include code in one kernel call) were used. These techniques also combined unrelated functions and 
-// data transfers in single kernels.
-
-//======================================================================================================================================================150
-//	RUNNING THIS CODE
-//======================================================================================================================================================150
-
-// The code takes the followint input files that need to be located in the same directory as the source files:
-// 1) video file (input.avi)
-// 2) text file with parameters (input.txt)
-
-// The following are the command parameters to the application:
-// 1) Number of frames to process. Needs to be integer <= to the number of frames in the input file.
-// Example:
-// ./a.out 104
-
-//======================================================================================================================================================150
-//	End
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	End
-//========================================================================================================================================================================================================200

+ 0 - 2235
opencl/heartwall/kernel/kernel_gpu_opencl.cl

@@ -1,2235 +0,0 @@
-//========================================================================================================================================================================================================200
-//	DEFINE / INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	MAIN FUNCTION HEADER
-//======================================================================================================================================================150
-
-#include "./main.h"
-
-//======================================================================================================================================================150
-//	End
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	KERNEL
-//========================================================================================================================================================================================================200
-
-__kernel void 
-kernel_gpu_opencl(	// structures
-					params_common d_common,					// 0
-
-					// common_change
-					__global fp* d_frame,					// 1	INPUT
-					int d_frame_no,							// 2	INPUT
-
-					// common
-					__global int* d_endoRow,				// 3	INPUT
-					__global int* d_endoCol,				// 4	INPUT
-					__global int* d_tEndoRowLoc,			// 5	OUTPUT	common.endoPoints * common.no_frames
-					__global int* d_tEndoColLoc,			// 6	OUTPUT	common.endoPoints * common.no_frames
-					__global int* d_epiRow,					// 7	INPUT
-					__global int* d_epiCol,					// 8	INPUT
-					__global int* d_tEpiRowLoc,				// 9	OUTPUT	common.epiPoints * common.no_frames
-					__global int* d_tEpiColLoc,				// 10	OUTPUT	common.epiPoints * common.no_frames
-
-					// common_unique
-					__global fp* d_endoT,					// 11	OUTPUT	common.in_elem * common.endoPoints
-					__global fp* d_epiT,					// 12	OUTPUT	common.in_elem * common.epiPoints
-					__global fp* d_in2_all,					// 13	OUTPUT	common.in2_elem * common.allPoints
-					__global fp* d_conv_all,				// 14	OUTPUT	common.conv_elem * common.allPoints
-					__global fp* d_in2_pad_cumv_all,		// 15	OUTPUT	common.in2_pad_cumv_elem * common.allPoints
-					__global fp* d_in2_pad_cumv_sel_all,	// 16	OUTPUT	common.in2_pad_cumv_sel_elem * common.allPoints
-					__global fp* d_in2_sub_cumh_all,		// 17	OUTPUT	common.in2_sub_cumh_elem * common.allPoints
-					__global fp* d_in2_sub_cumh_sel_all,	// 18	OUTPUT	common.in2_sub_cumh_sel_elem * common.allPoints
-					__global fp* d_in2_sub2_all,			// 19	OUTPUT	common.in2_sub2_elem * common.allPoints
-					__global fp* d_in2_sqr_all,				// 20	OUTPUT	common.in2_elem * common.allPoints
-					__global fp* d_in2_sqr_sub2_all,		// 21	OUTPUT	common.in2_sub2_elem * common.allPoints
-					__global fp* d_in_sqr_all,				// 22	OUTPUT	common.in_elem * common.allPoints
-					__global fp* d_tMask_all,				// 23	OUTPUT	common.tMask_elem * common.allPoints
-					__global fp* d_mask_conv_all,			// 24	OUTPUT	common.mask_conv_elem * common.allPoints
-
-					// // local
-					// __local fp* d_in_mod_temp,			// 25	OUTPUT	common.in_elem
-					// __local fp* in_partial_sum,			// 26	OUTPUT	common.in_cols
-					// __local fp* in_sqr_partial_sum,		// 27	OUTPUT	common.in_sqr_rows
-					// __local fp* par_max_val,				// 28	OUTPUT	common.mask_conv_rows
-					// __local int* par_max_coo)			// 29	OUTPUT	common.mask_conv_rows
-
-					// local
-					__global fp* d_in_mod_temp_all,			// 25	OUTPUT	common.in_elem * common.allPoints
-					__global fp* in_partial_sum_all,		// 26	OUTPUT	common.in_cols * common.allPoints
-					__global fp* in_sqr_partial_sum_all,	// 27	OUTPUT	common.in_sqr_rows * common.allPoints
-					__global fp* par_max_val_all,			// 28	OUTPUT	common.mask_conv_rows * common.allPoints
-					__global int* par_max_coo_all,			// 29	OUTPUT	common.mask_conv_rows * common.allPoints
-
-					__global fp* in_final_sum_all,			// 30	OUTPUT	common.allPoints
-					__global fp* in_sqr_final_sum_all,		// 31	OUTPUT	common.allPoints
-					__global fp* denomT_all,				// 32	OUTPUT	common.allPoints
-
-					__global fp* checksum)					// 33	OUTPUT	100
-
-{
-
-	//======================================================================================================================================================150
-	//	COMMON VARIABLES
-	//======================================================================================================================================================150
-
-	// __global fp* d_in;
-	int rot_row;
-	int rot_col;
-	int in2_rowlow;
-	int in2_collow;
-	int ic;
-	int jc;
-	int jp1;
-	int ja1, ja2;
-	int ip1;
-	int ia1, ia2;
-	int ja, jb;
-	int ia, ib;
-	fp s;
-	int i;
-	int j;
-	int row;
-	int col;
-	int ori_row;
-	int ori_col;
-	int position;
-	fp sum;
-	int pos_ori;
-	fp temp;
-	fp temp2;
-	int location;
-	int cent;
-	int tMask_row; 
-	int tMask_col;
-	fp largest_value_current = 0;
-	fp largest_value = 0;
-	int largest_coordinate_current = 0;
-	int largest_coordinate = 0;
-	fp fin_max_val = 0;
-	int fin_max_coo = 0;
-	int largest_row;
-	int largest_col;
-	int offset_row;
-	int offset_col;
-	fp mean;
-	fp mean_sqr;
-	fp variance;
-	fp deviation;
-	int pointer;
-	int ori_pointer;
-	int loc_pointer;
-
-	// __local fp in_final_sum;
-	// __local fp in_sqr_final_sum;
-	// __local fp denomT;
-
-	//======================================================================================================================================================150
-	//	BLOCK/THREAD IDs
-	//======================================================================================================================================================150
-
-	int bx = get_group_id(0);															// get current horizontal block index (0-n)
-	int tx = get_local_id(0);															// get current horizontal thread index (0-n)
-	int ei_new;
-
-	//======================================================================================================================================================150
-	//	UNIQUE STRUCTURE RECONSTRUCTED HERE
-	//======================================================================================================================================================150
-
-	// common
-	__global fp* d_common_change_d_frame = &d_frame[0];
-
-	// offsets for either endo or epi points (separate arrays for endo and epi points)
-	int d_unique_point_no;
-	__global int* d_unique_d_Row;
-	__global int* d_unique_d_Col;
-	__global int* d_unique_d_tRowLoc;
-	__global int* d_unique_d_tColLoc;
-	__global fp* d_in;
-	if(bx < d_common.endoPoints){
-		d_unique_point_no = bx;													// endo point number 0-???
-		d_unique_d_Row = d_endoRow;												// initial endo row coordinates
-		d_unique_d_Col = d_endoCol;												// initial endo col coordinates
-		d_unique_d_tRowLoc = d_tEndoRowLoc;										// all endo row coordinates
-		d_unique_d_tColLoc = d_tEndoColLoc;										// all endo col coordinates
-		d_in = &d_endoT[d_unique_point_no * d_common.in_elem];					// endo templates
-	}
-	else{
-		d_unique_point_no = bx-d_common.endoPoints;								// epi point number 0-???
-		d_unique_d_Row = d_epiRow;												// initial epi row coordinates
-		d_unique_d_Col = d_epiCol;												// initial epi col coordinates
-		d_unique_d_tRowLoc = d_tEpiRowLoc;										// all epi row coordinates
-		d_unique_d_tColLoc = d_tEpiColLoc;										// all epi col coordinates
-		d_in = &d_epiT[d_unique_point_no * d_common.in_elem];					// epi templates
-	}
-
-	// offsets for all points (one array for all points)
-	__global fp* d_unique_d_in2 = &d_in2_all[bx*d_common.in2_elem];
-	__global fp* d_unique_d_conv = &d_conv_all[bx*d_common.conv_elem];
-	__global fp* d_unique_d_in2_pad_cumv = &d_in2_pad_cumv_all[bx*d_common.in2_pad_cumv_elem];
-	__global fp* d_unique_d_in2_pad_cumv_sel = &d_in2_pad_cumv_sel_all[bx*d_common.in2_pad_cumv_sel_elem];
-	__global fp* d_unique_d_in2_sub_cumh = &d_in2_sub_cumh_all[bx*d_common.in2_sub_cumh_elem];
-	__global fp* d_unique_d_in2_sub_cumh_sel = &d_in2_sub_cumh_sel_all[bx*d_common.in2_sub_cumh_sel_elem];
-	__global fp* d_unique_d_in2_sub2 = &d_in2_sub2_all[bx*d_common.in2_sub2_elem];
-	__global fp* d_unique_d_in2_sqr = &d_in2_sqr_all[bx*d_common.in2_sqr_elem];
-	__global fp* d_unique_d_in2_sqr_sub2 = &d_in2_sqr_sub2_all[bx*d_common.in2_sqr_sub2_elem];
-	__global fp* d_unique_d_in_sqr = &d_in_sqr_all[bx*d_common.in_sqr_elem];
-	__global fp* d_unique_d_tMask = &d_tMask_all[bx*d_common.tMask_elem];
-	__global fp* d_unique_d_mask_conv = &d_mask_conv_all[bx*d_common.mask_conv_elem];
-
-	// used to be local
-	__global fp* d_in_mod_temp = &d_in_mod_temp_all[bx*d_common.in_elem];
-	__global fp* in_partial_sum = &in_partial_sum_all[bx*d_common.in_cols];
-	__global fp* in_sqr_partial_sum = &in_sqr_partial_sum_all[bx*d_common.in_sqr_rows];
-	__global fp* par_max_val = &par_max_val_all[bx*d_common.mask_conv_rows];
-	__global int* par_max_coo = &par_max_coo_all[bx*d_common.mask_conv_rows];
-
-	__global fp* in_final_sum = &in_final_sum_all[bx];
-	__global fp* in_sqr_final_sum = &in_sqr_final_sum_all[bx];
-	__global fp* denomT = &denomT_all[bx];
-
-	//======================================================================================================================================================150
-	//	END
-	//======================================================================================================================================================150
-
-	//======================================================================================================================================================150
-	//	Initialize checksum
-	//======================================================================================================================================================150
-#ifdef TEST_CHECKSUM
-	if(bx==0 && tx==0){
-
-		for(i=0; i<CHECK; i++){
-			checksum[i] = 0;
-		}
-
-	}
-#endif
-	//======================================================================================================================================================150
-	//	INITIAL COORDINATE AND TEMPLATE UPDATE
-	//======================================================================================================================================================150
-
-	// generate templates based on the first frame only
-	if(d_frame_no == 0){
-
-		//====================================================================================================100
-		//	Initialize cross-frame variables
-		//====================================================================================================100
-#ifdef INIT
-		// only the first thread initializes
-		if(tx==0){
-
-			// this block and for all frames
-			for(i=0; i<d_common.no_frames; i++){
-				d_unique_d_tRowLoc[d_unique_point_no*d_common.no_frames+i] = 0;
-				d_unique_d_tColLoc[d_unique_point_no*d_common.no_frames+i] = 0;
-			}
-
-			// this block
-			for(i=0; i<d_common.in_elem; i++){
-				d_in[i] = 0;
-			}
-
-		}
-#endif
-		//====================================================================================================100
-		//	SYNCHRONIZE THREADS
-		//====================================================================================================100
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//====================================================================================================100
-		//	UPDATE ROW LOC AND COL LOC
-		//====================================================================================================100
-
-		// uptade temporary endo/epi row/col coordinates (in each block corresponding to point, narrow work to one thread)
-		ei_new = tx;
-		if(ei_new == 0){
-
-			// update temporary row/col coordinates
-			pointer = d_unique_point_no*d_common.no_frames+d_frame_no;
-			d_unique_d_tRowLoc[pointer] = d_unique_d_Row[d_unique_point_no];
-			d_unique_d_tColLoc[pointer] = d_unique_d_Col[d_unique_point_no];
-
-		}
-
-		//====================================================================================================100
-		//	CREATE TEMPLATES
-		//====================================================================================================100
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in_rows == 0){
-				row = d_common.in_rows - 1;
-				col = col-1;
-			}
-
-			// figure out row/col location in corresponding new template area in image and give to every thread (get top left corner and progress down and right)
-			ori_row = d_unique_d_Row[d_unique_point_no] - 25 + row - 1;
-			ori_col = d_unique_d_Col[d_unique_point_no] - 25 + col - 1;
-			ori_pointer = ori_col*d_common.frame_rows+ori_row;
-
-			// update template
-			d_in[col*d_common.in_rows+row] = d_common_change_d_frame[ori_pointer];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//====================================================================================================100
-		//	SYNCHRONIZE THREADS
-		//====================================================================================================100
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//====================================================================================================100
-		//	CHECKSUM
-		//====================================================================================================100
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in_elem; i++){
-				checksum[0] = checksum[0]+d_in[i];
-			}
-		}
-
-		//====================================================================================================100
-		//	SYNCHRONIZE THREADS
-		//====================================================================================================100
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//====================================================================================================100
-		//	End
-		//====================================================================================================100
-
-	}
-
-	//======================================================================================================================================================150
-	//	PROCESS POINTS
-	//======================================================================================================================================================150
-
-	// process points in all frames except for the first one
-	if(d_frame_no != 0){
-
-		//====================================================================================================100
-		//	Initialize frame-specific variables
-		//====================================================================================================100
-#ifdef INIT
-		// only the first thread initializes
-		if(tx==0){
-
-			// this block
-			for(i=0; i<d_common.in2_elem; i++){
-				d_unique_d_in2[i] = 0;
-			}
-			for(i=0; i<d_common.conv_elem; i++){
-				d_unique_d_conv[i] = 0;
-			}
-			for(i=0; i<d_common.in2_pad_cumv_elem; i++){
-				d_unique_d_in2_pad_cumv[i] = 0;
-			}
-			for(i=0; i<d_common.in2_pad_cumv_sel_elem; i++){
-				d_unique_d_in2_pad_cumv_sel[i] = 0;
-			}
-			for(i=0; i<d_common.in2_sub_cumh_elem; i++){
-				d_unique_d_in2_sub_cumh[i] = 0;
-			}
-			for(i=0; i<d_common.in2_sub_cumh_sel_elem; i++){
-				d_unique_d_in2_sub_cumh_sel[i] = 0;
-			}
-			for(i=0; i<d_common.in2_sub2_elem; i++){
-				d_unique_d_in2_sub2[i] = 0;
-			}
-			for(i=0; i<d_common.in2_sqr_elem; i++){
-				d_unique_d_in2_sqr[i] = 0;
-			}
-			for(i=0; i<d_common.in2_sqr_sub2_elem; i++){
-				d_unique_d_in2_sqr_sub2[i] = 0;
-			}
-			for(i=0; i<d_common.in_sqr_elem; i++){
-				d_unique_d_in_sqr[i] = 0;
-			}
-			for(i=0; i<d_common.tMask_elem; i++){
-				d_unique_d_tMask[i] = 0;
-			}
-			for(i=0; i<d_common.mask_conv_elem; i++){
-				d_unique_d_mask_conv[i] = 0;
-			}
-
-			for(i=0; i<d_common.in_elem; i++){
-				d_in_mod_temp[i] = 0;
-			}
-			for(i=0; i<d_common.in_cols; i++){
-				in_partial_sum[i] = 0;
-			}
-			for(i=0; i<d_common.in_sqr_rows; i++){
-				in_sqr_partial_sum[i] = 0;
-			}
-			for(i=0; i<d_common.mask_conv_rows; i++){
-				par_max_val[i] = 0;
-			}
-			for(i=0; i<d_common.mask_conv_rows; i++){
-				par_max_coo[i] = 0;
-			}
-
-			in_final_sum[0] = 0;
-			in_sqr_final_sum[0] = 0;
-			denomT[0] = 0;
-
-		}
-#endif
-		//====================================================================================================100
-		//	SYNCHRONIZE THREADS
-		//====================================================================================================100
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//====================================================================================================100
-		//	SELECTION
-		//====================================================================================================100
-
-		in2_rowlow = d_unique_d_Row[d_unique_point_no] - d_common.sSize;													// (1 to n+1)
-		in2_collow = d_unique_d_Col[d_unique_point_no] - d_common.sSize;
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in2_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_rows == 0){
-				row = d_common.in2_rows - 1;
-				col = col-1;
-			}
-
-			// figure out corresponding location in old matrix and copy values to new matrix
-			ori_row = row + in2_rowlow - 1;
-			ori_col = col + in2_collow - 1;
-			d_unique_d_in2[ei_new] = d_common_change_d_frame[ori_col*d_common.frame_rows+ori_row];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//====================================================================================================100
-		//	SYNCHRONIZE THREADS
-		//====================================================================================================100
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//====================================================================================================100
-		//	CHECKSUM
-		//====================================================================================================100
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_elem; i++){
-				checksum[1] = checksum[1]+d_unique_d_in2[i];
-			}
-		}
-
-		//====================================================================================================100
-		//	SYNCHRONIZE THREADS
-		//====================================================================================================100
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//====================================================================================================100
-		//	CONVOLUTION
-		//====================================================================================================100
-
-		//==================================================50
-		//	ROTATION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in_elem){
-		// while(ei_new < 1){
-
-			// figure out row/col location in padded array
-			row = (ei_new+1) % d_common.in_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in_rows == 0){
-				row = d_common.in_rows - 1;
-				col = col-1;
-			}
-
-			// execution
-			rot_row = (d_common.in_rows-1) - row;
-			rot_col = (d_common.in_rows-1) - col;
-			d_in_mod_temp[ei_new] = d_in[rot_col*d_common.in_rows+rot_row];
-			// d_in_mod_temp[ei_new] = d_in[0];
-			// d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_in_pointer];
-			// d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no * d_common.in_elem];
-			// d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no * 2601];
-			// if((d_unique_point_no * d_common.in_elem) > (2601*51
-				// printf("frame_no IS %d\n", d_common_change[0].frame_no);
-			// d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no];
-
-			// d_in_mod_temp[ei_new] = 1;
-			// kot = d_in[rot_col*d_common.in_rows+rot_row];
-			// d_in_mod_temp[ei_new] = kot;
-			// d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_in_pointer+rot_col*d_common.in_rows+rot_row];
-			// d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no * d_common.in_elem+rot_col*d_common.in_rows+rot_row];
-			//d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no];
-			// d_unique_d_T[d_unique_in_pointer+rot_col*d_common.in_rows+rot_row] = 1;
-			// d_unique_d_T[d_unique_in_pointer] = 1;
-			// d_endoT[d_unique_in_pointer] = 1;
-			// d_in_mod_temp[ei_new] = 1;
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in_elem; i++){
-				checksum[2] = checksum[2]+d_in_mod_temp[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	ACTUAL CONVOLUTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.conv_elem){
-
-			// figure out row/col location in array
-			ic = (ei_new+1) % d_common.conv_rows;												// (1-n)
-			jc = (ei_new+1) / d_common.conv_rows + 1;											// (1-n)
-			if((ei_new+1) % d_common.conv_rows == 0){
-				ic = d_common.conv_rows;
-				jc = jc-1;
-			}
-
-			//
-			j = jc + d_common.joffset;
-			jp1 = j + 1;
-			if(d_common.in2_cols < jp1){
-				ja1 = jp1 - d_common.in2_cols;
-			}
-			else{
-				ja1 = 1;
-			}
-			if(d_common.in_cols < j){
-				ja2 = d_common.in_cols;
-			}
-			else{
-				ja2 = j;
-			}
-
-			i = ic + d_common.ioffset;
-			ip1 = i + 1;
-			
-			if(d_common.in2_rows < ip1){
-				ia1 = ip1 - d_common.in2_rows;
-			}
-			else{
-				ia1 = 1;
-			}
-			if(d_common.in_rows < i){
-				ia2 = d_common.in_rows;
-			}
-			else{
-				ia2 = i;
-			}
-
-			s = 0;
-
-			for(ja=ja1; ja<=ja2; ja++){
-				jb = jp1 - ja;
-				for(ia=ia1; ia<=ia2; ia++){
-					ib = ip1 - ia;
-					s = s + d_in_mod_temp[d_common.in_rows*(ja-1)+ia-1] * d_unique_d_in2[d_common.in2_rows*(jb-1)+ib-1];
-				}
-			}
-
-			//d_unique_d_conv[d_common.conv_rows*(jc-1)+ic-1] = s;
-			d_unique_d_conv[ei_new] = s;
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.conv_elem; i++){
-				checksum[3] = checksum[3]+d_unique_d_conv[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	End
-		//==================================================50
-
-		//====================================================================================================100
-		// 	CUMULATIVE SUM	(LOCAL)
-		//====================================================================================================100
-
-		//==================================================50
-		//	PADD ARRAY
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_pad_cumv_elem){
-
-			// figure out row/col location in padded array
-			row = (ei_new+1) % d_common.in2_pad_cumv_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_pad_cumv_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_pad_cumv_rows == 0){
-				row = d_common.in2_pad_cumv_rows - 1;
-				col = col-1;
-			}
-
-			// execution
-			if(	row > (d_common.in2_pad_add_rows-1) &&														// do if has numbers in original array
-				row < (d_common.in2_pad_add_rows+d_common.in2_rows) && 
-				col > (d_common.in2_pad_add_cols-1) && 
-				col < (d_common.in2_pad_add_cols+d_common.in2_cols)){
-				ori_row = row - d_common.in2_pad_add_rows;
-				ori_col = col - d_common.in2_pad_add_cols;
-				d_unique_d_in2_pad_cumv[ei_new] = d_unique_d_in2[ori_col*d_common.in2_rows+ori_row];
-			}
-			else{																			// do if otherwise
-				d_unique_d_in2_pad_cumv[ei_new] = 0;
-			}
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_pad_cumv_elem; i++){
-				checksum[4] = checksum[4]+d_unique_d_in2_pad_cumv[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	VERTICAL CUMULATIVE SUM
-		//==================================================50
-
-		//work
-		ei_new = tx;
-		while(ei_new < d_common.in2_pad_cumv_cols){
-
-			// figure out column position
-			pos_ori = ei_new*d_common.in2_pad_cumv_rows;
-
-			// variables
-			sum = 0;
-			
-			// loop through all rows
-			for(position = pos_ori; position < pos_ori+d_common.in2_pad_cumv_rows; position = position + 1){
-				d_unique_d_in2_pad_cumv[position] = d_unique_d_in2_pad_cumv[position] + sum;
-				sum = d_unique_d_in2_pad_cumv[position];
-			}
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_pad_cumv_cols; i++){
-				checksum[5] = checksum[5]+d_unique_d_in2_pad_cumv[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SELECTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_pad_cumv_sel_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in2_pad_cumv_sel_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_pad_cumv_sel_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_pad_cumv_sel_rows == 0){
-				row = d_common.in2_pad_cumv_sel_rows - 1;
-				col = col-1;
-			}
-
-			// figure out corresponding location in old matrix and copy values to new matrix
-			ori_row = row + d_common.in2_pad_cumv_sel_rowlow - 1;
-			ori_col = col + d_common.in2_pad_cumv_sel_collow - 1;
-			d_unique_d_in2_pad_cumv_sel[ei_new] = d_unique_d_in2_pad_cumv[ori_col*d_common.in2_pad_cumv_rows+ori_row];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_pad_cumv_sel_elem; i++){
-				checksum[6] = checksum[6]+d_unique_d_in2_pad_cumv_sel[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SELECTION 2
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub_cumh_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in2_sub_cumh_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_sub_cumh_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_sub_cumh_rows == 0){
-				row = d_common.in2_sub_cumh_rows - 1;
-				col = col-1;
-			}
-
-			// figure out corresponding location in old matrix and copy values to new matrix
-			ori_row = row + d_common.in2_pad_cumv_sel2_rowlow - 1;
-			ori_col = col + d_common.in2_pad_cumv_sel2_collow - 1;
-			d_unique_d_in2_sub_cumh[ei_new] = d_unique_d_in2_pad_cumv[ori_col*d_common.in2_pad_cumv_rows+ori_row];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub_cumh_elem; i++){
-				checksum[7] = checksum[7]+d_unique_d_in2_sub_cumh[i];
-			}
-		}
-#endif
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	SUBTRACTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub_cumh_elem){
-
-			// subtract
-			d_unique_d_in2_sub_cumh[ei_new] = d_unique_d_in2_pad_cumv_sel[ei_new] - d_unique_d_in2_sub_cumh[ei_new];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub_cumh_elem; i++){
-				checksum[8] = checksum[8]+d_unique_d_in2_sub_cumh[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	HORIZONTAL CUMULATIVE SUM
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub_cumh_rows){
-
-			// figure out row position
-			pos_ori = ei_new;
-
-			// variables
-			sum = 0;
-
-			// loop through all rows
-			for(position = pos_ori; position < pos_ori+d_common.in2_sub_cumh_elem; position = position + d_common.in2_sub_cumh_rows){
-				d_unique_d_in2_sub_cumh[position] = d_unique_d_in2_sub_cumh[position] + sum;
-				sum = d_unique_d_in2_sub_cumh[position];
-			}
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub_cumh_elem; i++){
-				checksum[9] = checksum[9]+d_unique_d_in2_sub_cumh[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SELECTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub_cumh_sel_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in2_sub_cumh_sel_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_sub_cumh_sel_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_sub_cumh_sel_rows == 0){
-				row = d_common.in2_sub_cumh_sel_rows - 1;
-				col = col - 1;
-			}
-
-			// figure out corresponding location in old matrix and copy values to new matrix
-			ori_row = row + d_common.in2_sub_cumh_sel_rowlow - 1;
-			ori_col = col + d_common.in2_sub_cumh_sel_collow - 1;
-			d_unique_d_in2_sub_cumh_sel[ei_new] = d_unique_d_in2_sub_cumh[ori_col*d_common.in2_sub_cumh_rows+ori_row];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub_cumh_sel_elem; i++){
-				checksum[10] = checksum[10]+d_unique_d_in2_sub_cumh_sel[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SELECTION 2
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub2_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in2_sub2_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_sub2_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_sub2_rows == 0){
-				row = d_common.in2_sub2_rows - 1;
-				col = col-1;
-			}
-
-			// figure out corresponding location in old matrix and copy values to new matrix
-			ori_row = row + d_common.in2_sub_cumh_sel2_rowlow - 1;
-			ori_col = col + d_common.in2_sub_cumh_sel2_collow - 1;
-			d_unique_d_in2_sub2[ei_new] = d_unique_d_in2_sub_cumh[ori_col*d_common.in2_sub_cumh_rows+ori_row];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub2_elem; i++){
-				checksum[11] = checksum[11]+d_unique_d_in2_sub2[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SUBTRACTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub2_elem){
-
-			// subtract
-			d_unique_d_in2_sub2[ei_new] = d_unique_d_in2_sub_cumh_sel[ei_new] - d_unique_d_in2_sub2[ei_new];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub2_elem; i++){
-				checksum[12] = checksum[12]+d_unique_d_in2_sub2[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	End
-		//==================================================50
-
-		//====================================================================================================100
-		//	CUMULATIVE SUM 2
-		//====================================================================================================100
-
-		//==================================================50
-		//	MULTIPLICATION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sqr_elem){
-
-			temp = d_unique_d_in2[ei_new];
-			d_unique_d_in2_sqr[ei_new] = temp * temp;
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sqr_elem; i++){
-				checksum[13] = checksum[13]+d_unique_d_in2_sqr[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	PAD ARRAY, VERTICAL CUMULATIVE SUM
-		//==================================================50
-
-		//==================================================50
-		//	PAD ARRAY
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_pad_cumv_elem){
-
-			// figure out row/col location in padded array
-			row = (ei_new+1) % d_common.in2_pad_cumv_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_pad_cumv_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_pad_cumv_rows == 0){
-				row = d_common.in2_pad_cumv_rows - 1;
-				col = col-1;
-			}
-
-			// execution
-			if(	row > (d_common.in2_pad_add_rows-1) &&													// do if has numbers in original array
-				row < (d_common.in2_pad_add_rows+d_common.in2_sqr_rows) && 
-				col > (d_common.in2_pad_add_cols-1) && 
-				col < (d_common.in2_pad_add_cols+d_common.in2_sqr_cols)){
-				ori_row = row - d_common.in2_pad_add_rows;
-				ori_col = col - d_common.in2_pad_add_cols;
-				d_unique_d_in2_pad_cumv[ei_new] = d_unique_d_in2_sqr[ori_col*d_common.in2_sqr_rows+ori_row];
-			}
-			else{																							// do if otherwise
-				d_unique_d_in2_pad_cumv[ei_new] = 0;
-			}
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_pad_cumv_elem; i++){
-				checksum[14] = checksum[14]+d_unique_d_in2_pad_cumv[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	VERTICAL CUMULATIVE SUM
-		//==================================================50
-
-		//work
-		ei_new = tx;
-		while(ei_new < d_common.in2_pad_cumv_cols){
-
-			// figure out column position
-			pos_ori = ei_new*d_common.in2_pad_cumv_rows;
-
-			// variables
-			sum = 0;
-			
-			// loop through all rows
-			for(position = pos_ori; position < pos_ori+d_common.in2_pad_cumv_rows; position = position + 1){
-				d_unique_d_in2_pad_cumv[position] = d_unique_d_in2_pad_cumv[position] + sum;
-				sum = d_unique_d_in2_pad_cumv[position];
-			}
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_pad_cumv_elem; i++){
-				checksum[15] = checksum[15]+d_unique_d_in2_pad_cumv[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SELECTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_pad_cumv_sel_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in2_pad_cumv_sel_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_pad_cumv_sel_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_pad_cumv_sel_rows == 0){
-				row = d_common.in2_pad_cumv_sel_rows - 1;
-				col = col-1;
-			}
-
-			// figure out corresponding location in old matrix and copy values to new matrix
-			ori_row = row + d_common.in2_pad_cumv_sel_rowlow - 1;
-			ori_col = col + d_common.in2_pad_cumv_sel_collow - 1;
-			d_unique_d_in2_pad_cumv_sel[ei_new] = d_unique_d_in2_pad_cumv[ori_col*d_common.in2_pad_cumv_rows+ori_row];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_pad_cumv_sel_elem; i++){
-				checksum[16] = checksum[16]+d_unique_d_in2_pad_cumv_sel[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SELECTION 2
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub_cumh_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in2_sub_cumh_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_sub_cumh_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_sub_cumh_rows == 0){
-				row = d_common.in2_sub_cumh_rows - 1;
-				col = col-1;
-			}
-
-			// figure out corresponding location in old matrix and copy values to new matrix
-			ori_row = row + d_common.in2_pad_cumv_sel2_rowlow - 1;
-			ori_col = col + d_common.in2_pad_cumv_sel2_collow - 1;
-			d_unique_d_in2_sub_cumh[ei_new] = d_unique_d_in2_pad_cumv[ori_col*d_common.in2_pad_cumv_rows+ori_row];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub_cumh_elem; i++){
-				checksum[17] = checksum[17]+d_unique_d_in2_sub_cumh[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SUBTRACTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub_cumh_elem){
-
-			// subtract
-			d_unique_d_in2_sub_cumh[ei_new] = d_unique_d_in2_pad_cumv_sel[ei_new] - d_unique_d_in2_sub_cumh[ei_new];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub_cumh_elem; i++){
-				checksum[18] = checksum[18]+d_unique_d_in2_sub_cumh[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	HORIZONTAL CUMULATIVE SUM
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub_cumh_rows){
-
-			// figure out row position
-			pos_ori = ei_new;
-
-			// variables
-			sum = 0;
-
-			// loop through all rows
-			for(position = pos_ori; position < pos_ori+d_common.in2_sub_cumh_elem; position = position + d_common.in2_sub_cumh_rows){
-				d_unique_d_in2_sub_cumh[position] = d_unique_d_in2_sub_cumh[position] + sum;
-				sum = d_unique_d_in2_sub_cumh[position];
-			}
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub_cumh_rows; i++){
-				checksum[19] = checksum[19]+d_unique_d_in2_sub_cumh[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SELECTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub_cumh_sel_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in2_sub_cumh_sel_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_sub_cumh_sel_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_sub_cumh_sel_rows == 0){
-				row = d_common.in2_sub_cumh_sel_rows - 1;
-				col = col - 1;
-			}
-
-			// figure out corresponding location in old matrix and copy values to new matrix
-			ori_row = row + d_common.in2_sub_cumh_sel_rowlow - 1;
-			ori_col = col + d_common.in2_sub_cumh_sel_collow - 1;
-			d_unique_d_in2_sub_cumh_sel[ei_new] = d_unique_d_in2_sub_cumh[ori_col*d_common.in2_sub_cumh_rows+ori_row];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub_cumh_sel_elem; i++){
-				checksum[20] = checksum[20]+d_unique_d_in2_sub_cumh_sel[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SELECTION 2
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub2_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in2_sub2_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in2_sub2_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in2_sub2_rows == 0){
-				row = d_common.in2_sub2_rows - 1;
-				col = col-1;
-			}
-
-			// figure out corresponding location in old matrix and copy values to new matrix
-			ori_row = row + d_common.in2_sub_cumh_sel2_rowlow - 1;
-			ori_col = col + d_common.in2_sub_cumh_sel2_collow - 1;
-			d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_in2_sub_cumh[ori_col*d_common.in2_sub_cumh_rows+ori_row];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub2_elem; i++){
-				checksum[21] = checksum[21]+d_unique_d_in2_sqr_sub2[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	SUBTRACTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub2_elem){
-
-			// subtract
-			d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_in2_sub_cumh_sel[ei_new] - d_unique_d_in2_sqr_sub2[ei_new];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub2_elem; i++){
-				checksum[22] = checksum[22]+d_unique_d_in2_sqr_sub2[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	End
-		//==================================================50
-
-		//====================================================================================================100
-		//	FINAL
-		//====================================================================================================100
-
-		//==================================================50
-		//	DENOMINATOR A		SAVE RESULT IN CUMULATIVE SUM A2
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub2_elem){
-
-			temp = d_unique_d_in2_sub2[ei_new];
-			temp2 = d_unique_d_in2_sqr_sub2[ei_new] - (temp * temp / d_common.in_elem);
-			if(temp2 < 0){
-				temp2 = 0;
-			}
-			d_unique_d_in2_sqr_sub2[ei_new] = sqrt(temp2);
-			
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub2_elem; i++){
-				checksum[23] = checksum[23]+d_unique_d_in2_sqr_sub2[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	MULTIPLICATION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in_sqr_elem){
-
-			temp = d_in[ei_new];
-			d_unique_d_in_sqr[ei_new] = temp * temp;
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in_sqr_elem; i++){
-				checksum[24] = checksum[24]+d_unique_d_in_sqr[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	IN SUM
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in_cols){
-
-			sum = 0;
-			for(i = 0; i < d_common.in_rows; i++){
-
-				sum = sum + d_in[ei_new*d_common.in_rows+i];
-
-			}
-			in_partial_sum[ei_new] = sum;
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in_cols; i++){
-				checksum[25] = checksum[25]+in_partial_sum[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	IN_SQR SUM
-		//==================================================50
-
-		ei_new = tx;
-		while(ei_new < d_common.in_sqr_rows){
-				
-			sum = 0;
-			for(i = 0; i < d_common.in_sqr_cols; i++){
-
-				sum = sum + d_unique_d_in_sqr[ei_new+d_common.in_sqr_rows*i];
-
-			}
-			in_sqr_partial_sum[ei_new] = sum;
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in_sqr_rows; i++){
-				checksum[26] = checksum[26]+in_sqr_partial_sum[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	FINAL SUMMATION
-		//==================================================50
-
-		if(tx == 0){
-
-			in_final_sum[0] = 0;
-			for(i = 0; i<d_common.in_cols; i++){
-				// in_final_sum = in_final_sum + in_partial_sum[i];
-				in_final_sum[0] = in_final_sum[0] + in_partial_sum[i];
-			}
-
-		}else if(tx == 1){
-
-			in_sqr_final_sum[0] = 0;
-			for(i = 0; i<d_common.in_sqr_cols; i++){
-				// in_sqr_final_sum = in_sqr_final_sum + in_sqr_partial_sum[i];
-				in_sqr_final_sum[0] = in_sqr_final_sum[0] + in_sqr_partial_sum[i];
-			}
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			checksum[27] = checksum[27]+in_final_sum[0]+in_sqr_final_sum[0];
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	DENOMINATOR T
-		//==================================================50
-
-		if(tx == 0){
-
-			// mean = in_final_sum / d_common.in_elem;													// gets mean (average) value of element in ROI
-			mean = in_final_sum[0] / d_common.in_elem;													// gets mean (average) value of element in ROI
-			mean_sqr = mean * mean;
-			// variance  = (in_sqr_final_sum / d_common.in_elem) - mean_sqr;							// gets variance of ROI
-			variance  = (in_sqr_final_sum[0] / d_common.in_elem) - mean_sqr;							// gets variance of ROI
-			deviation = sqrt(variance);																// gets standard deviation of ROI
-
-			// denomT = sqrt((float)(d_common.in_elem-1))*deviation;
-			denomT[0] = sqrt((float)(d_common.in_elem-1))*deviation;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			checksum[28] = checksum[28]+denomT[i];
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	DENOMINATOR		SAVE RESULT IN CUMULATIVE SUM A2
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub2_elem){
-
-			// d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_in2_sqr_sub2[ei_new] * denomT;
-			d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_in2_sqr_sub2[ei_new] * denomT[0];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub2_elem; i++){
-				checksum[29] = checksum[29]+d_unique_d_in2_sqr_sub2[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	NUMERATOR	SAVE RESULT IN CONVOLUTION
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.conv_elem){
-
-			// d_unique_d_conv[ei_new] = d_unique_d_conv[ei_new] - d_unique_d_in2_sub2[ei_new] * in_final_sum / d_common.in_elem;
-			d_unique_d_conv[ei_new] = d_unique_d_conv[ei_new] - d_unique_d_in2_sub2[ei_new] * in_final_sum[0] / d_common.in_elem;
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.conv_elem; i++){
-				checksum[30] = checksum[30]+d_unique_d_conv[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	CORRELATION	SAVE RESULT IN CUMULATIVE SUM A2
-		//==================================================50
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in2_sub2_elem){
-
-			d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_conv[ei_new] / d_unique_d_in2_sqr_sub2[ei_new];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in2_sub2_elem; i++){
-				checksum[31] = checksum[31]+d_unique_d_in2_sqr_sub2[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	End
-		//==================================================50
-
-		//====================================================================================================100
-		//	TEMPLATE MASK CREATE
-		//====================================================================================================100
-
-		cent = d_common.sSize + d_common.tSize + 1;
-		if(d_frame_no == 0){
-			tMask_row = cent + d_unique_d_Row[d_unique_point_no] - d_unique_d_Row[d_unique_point_no] - 1;
-			tMask_col = cent + d_unique_d_Col[d_unique_point_no] - d_unique_d_Col[d_unique_point_no] - 1;
-		}
-		else{
-			pointer = d_unique_point_no*d_common.no_frames+d_frame_no-1;
-			tMask_row = cent + d_unique_d_tRowLoc[pointer] - d_unique_d_Row[d_unique_point_no] - 1;
-			tMask_col = cent + d_unique_d_tColLoc[pointer] - d_unique_d_Col[d_unique_point_no] - 1;
-		}
-
-		//work
-		ei_new = tx;
-		while(ei_new < d_common.tMask_elem){
-
-			location = tMask_col*d_common.tMask_rows + tMask_row;
-
-			if(ei_new==location){
-				d_unique_d_tMask[ei_new] = 1;
-			}
-			else{
-				d_unique_d_tMask[ei_new] = 0;
-			}
-
-			//go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.tMask_elem; i++){
-				checksum[32] = checksum[32]+d_unique_d_tMask[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	End
-		//==================================================50
-
-		//====================================================================================================100
-		//	MASK CONVOLUTION
-		//====================================================================================================100
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.mask_conv_elem){
-
-			// figure out row/col location in array
-			ic = (ei_new+1) % d_common.mask_conv_rows;												// (1-n)
-			jc = (ei_new+1) / d_common.mask_conv_rows + 1;											// (1-n)
-			if((ei_new+1) % d_common.mask_conv_rows == 0){
-				ic = d_common.mask_conv_rows;
-				jc = jc-1;
-			}
-
-			//
-			j = jc + d_common.mask_conv_joffset;
-			jp1 = j + 1;
-			if(d_common.mask_cols < jp1){
-				ja1 = jp1 - d_common.mask_cols;
-			}
-			else{
-				ja1 = 1;
-			}
-			if(d_common.tMask_cols < j){
-				ja2 = d_common.tMask_cols;
-			}
-			else{
-				ja2 = j;
-			}
-
-			i = ic + d_common.mask_conv_ioffset;
-			ip1 = i + 1;
-			
-			if(d_common.mask_rows < ip1){
-				ia1 = ip1 - d_common.mask_rows;
-			}
-			else{
-				ia1 = 1;
-			}
-			if(d_common.tMask_rows < i){
-				ia2 = d_common.tMask_rows;
-			}
-			else{
-				ia2 = i;
-			}
-
-			s = 0;
-
-			for(ja=ja1; ja<=ja2; ja++){
-				jb = jp1 - ja;
-				for(ia=ia1; ia<=ia2; ia++){
-					ib = ip1 - ia;
-					s = s + d_unique_d_tMask[d_common.tMask_rows*(ja-1)+ia-1] * 1;
-				}
-			}
-
-			// //d_unique_d_mask_conv[d_common.mask_conv_rows*(jc-1)+ic-1] = s;
-			d_unique_d_mask_conv[ei_new] = d_unique_d_in2_sqr_sub2[ei_new] * s;
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.mask_conv_elem; i++){
-				checksum[33] = checksum[33]+d_unique_d_mask_conv[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	End
-		//==================================================50
-
-		//====================================================================================================100
-		//	MAXIMUM VALUE
-		//====================================================================================================100
-
-		//==================================================50
-		//	INITIAL SEARCH
-		//==================================================50
-
-		ei_new = tx;
-		while(ei_new < d_common.mask_conv_rows){
-
-			for(i=0; i<d_common.mask_conv_cols; i++){
-				largest_coordinate_current = ei_new*d_common.mask_conv_rows+i;
-				largest_value_current = fabs(d_unique_d_mask_conv[largest_coordinate_current]);
-				if(largest_value_current > largest_value){
-					largest_coordinate = largest_coordinate_current;
-					largest_value = largest_value_current;
-				}
-			}
-			par_max_coo[ei_new] = largest_coordinate;
-			par_max_val[ei_new] = largest_value;
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.mask_conv_rows; i++){
-				checksum[34] = checksum[34]+par_max_coo[i]+par_max_val[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	FINAL SEARCH
-		//==================================================50
-
-		if(tx == 0){
-
-			for(i = 0; i < d_common.mask_conv_rows; i++){
-				if(par_max_val[i] > fin_max_val){
-					fin_max_val = par_max_val[i];
-					fin_max_coo = par_max_coo[i];
-				}
-			}
-
-			// convert coordinate to row/col form
-			largest_row = (fin_max_coo+1) % d_common.mask_conv_rows - 1;											// (0-n) row
-			largest_col = (fin_max_coo+1) / d_common.mask_conv_rows;												// (0-n) column
-			if((fin_max_coo+1) % d_common.mask_conv_rows == 0){
-				largest_row = d_common.mask_conv_rows - 1;
-				largest_col = largest_col - 1;
-			}
-
-			// calculate offset
-			largest_row = largest_row + 1;																	// compensate to match MATLAB format (1-n)
-			largest_col = largest_col + 1;																	// compensate to match MATLAB format (1-n)
-			offset_row = largest_row - d_common.in_rows - (d_common.sSize - d_common.tSize);
-			offset_col = largest_col - d_common.in_cols - (d_common.sSize - d_common.tSize);
-			pointer = d_unique_point_no*d_common.no_frames+d_frame_no;
-			d_unique_d_tRowLoc[pointer] = d_unique_d_Row[d_unique_point_no] + offset_row;
-			d_unique_d_tColLoc[pointer] = d_unique_d_Col[d_unique_point_no] + offset_col;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			checksum[35] = checksum[35]+d_unique_d_tRowLoc[pointer]+d_unique_d_tColLoc[pointer];
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	End
-		//==================================================50
-
-		//====================================================================================================100
-		//	End
-		//====================================================================================================100
-
-	}
-
-	//======================================================================================================================================================150
-	//	PERIODIC COORDINATE AND TEMPLATE UPDATE
-	//======================================================================================================================================================150
-
-	if(d_frame_no != 0 && (d_frame_no)%10 == 0){
-
-		//====================================================================================================100
-		// initialize cross-frame variables
-		//====================================================================================================100
-#ifdef INIT
-		// only the first thread initializes
-		if(tx==0){
-
-			// this block
-			for(i=0; i<d_common.in_elem; i++){
-				d_in[i] = 0;
-			}
-
-		}
-#endif
-		//====================================================================================================100
-		//	SYNCHRONIZE THREADS
-		//====================================================================================================100
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//====================================================================================================100
-		// if the last frame in the bath, update template
-		//====================================================================================================100
-
-		// update coordinate
-		loc_pointer = d_unique_point_no*d_common.no_frames+d_frame_no;
-
-		d_unique_d_Row[d_unique_point_no] = d_unique_d_tRowLoc[loc_pointer];
-		d_unique_d_Col[d_unique_point_no] = d_unique_d_tColLoc[loc_pointer];
-
-		// work
-		ei_new = tx;
-		while(ei_new < d_common.in_elem){
-
-			// figure out row/col location in new matrix
-			row = (ei_new+1) % d_common.in_rows - 1;												// (0-n) row
-			col = (ei_new+1) / d_common.in_rows + 1 - 1;											// (0-n) column
-			if((ei_new+1) % d_common.in_rows == 0){
-				row = d_common.in_rows - 1;
-				col = col-1;
-			}
-
-			// figure out row/col location in corresponding new template area in image and give to every thread (get top left corner and progress down and right)
-			ori_row = d_unique_d_Row[d_unique_point_no] - 25 + row - 1;
-			ori_col = d_unique_d_Col[d_unique_point_no] - 25 + col - 1;
-			ori_pointer = ori_col*d_common.frame_rows+ori_row;
-
-			// update template
-			d_in[ei_new] = d_common.alpha*d_in[ei_new] + (1-d_common.alpha)*d_common_change_d_frame[ori_pointer];
-
-			// go for second round
-			ei_new = ei_new + NUMBER_THREADS;
-
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-
-		//==================================================50
-		//	CHECKSUM
-		//==================================================50
-#ifdef TEST_CHECKSUM
-		if(bx==0 && tx==0){
-			for(i=0; i<d_common.in_elem; i++){
-				checksum[36] = checksum[36]+d_in[i];
-			}
-		}
-
-		//==================================================50
-		//	SYNCHRONIZE THREADS
-		//==================================================50
-
-		barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
-#endif
-		//==================================================50
-		//	End
-		//==================================================50
-
-		//====================================================================================================100
-		//	End
-		//====================================================================================================100
-
-	}
-
-	//======================================================================================================================================================150
-	//	End
-	//======================================================================================================================================================150
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200

+ 0 - 1467
opencl/heartwall/kernel/kernel_gpu_opencl_wrapper.c

@@ -1,1467 +0,0 @@
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <CL/cl.h>									// (in directory specified to compiler)		needed by OpenCL types and functions
-
-//======================================================================================================================================================150
-//	MAIN FUNCTION HEADER
-//======================================================================================================================================================150
-
-#include "./../main.h"								// (in main directory)						needed to recognized input parameters
-
-//======================================================================================================================================================150
-//	DEFINE
-//======================================================================================================================================================150
-
-//======================================================================================================================================================150
-//	UTILITIES
-//======================================================================================================================================================150
-
-#include "./../util/opencl/opencl.h"				// (in directory)							needed by device functions
-#include "./../util/avi/avilib.h"					// (in directory)							needed by avi functions
-#include "./../util/avi/avimod.h"					// (in directory)							needed by avi functions
-
-//======================================================================================================================================================150
-//	KERNEL_GPU_CUDA_WRAPPER FUNCTION HEADER
-//======================================================================================================================================================150
-
-#include "./kernel_gpu_opencl_wrapper.h"			// (in directory)
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	KERNEL_GPU_CUDA_WRAPPER FUNCTION
-//========================================================================================================================================================================================================200
-
-void 
-kernel_gpu_opencl_wrapper(	params_common common,
-							int* endoRow,
-							int* endoCol,
-							int* tEndoRowLoc,
-							int* tEndoColLoc,
-							int* epiRow,
-							int* epiCol,
-							int* tEpiRowLoc,
-							int* tEpiColLoc,
-							avi_t* frames,
-              int platform_id,
-              int device_id,
-              int use_gpu)
-{
-
-	//======================================================================================================================================================150
-	//	CPU VARIABLES
-	//======================================================================================================================================================150
-
-	// common variables
-	int i;
-
-	//======================================================================================================================================================150
-	//	GPU SETUP
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	COMMON VARIABLES
-	//====================================================================================================100
-
-	// common variables
-	int error;
-
-	//====================================================================================================100
-	//	GET PLATFORMS (Intel, AMD, NVIDIA, based on provided library), SELECT ONE
-	//====================================================================================================100
-
-	// Get number of available platforms
-	cl_uint num_platforms;
-	error = clGetPlatformIDs(	0, 
-								NULL, 
-								&num_platforms);		// # of platforms
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	printf("# of platforms %d\n", num_platforms);
-
-	// Get list of available platforms
-	cl_platform_id *platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id) * num_platforms);
-	error = clGetPlatformIDs(	num_platforms, 
-								platforms, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Get names of platforms and print them
-	cl_char pbuf[100];
-	int plat_count;
-	cl_platform_id platform;
-	for(plat_count = 0; plat_count < num_platforms; plat_count++){
-
-		platform = platforms[plat_count];
-
-		error = clGetPlatformInfo(	platform, 
-							CL_PLATFORM_VENDOR, 
-							sizeof(pbuf), 
-							pbuf, 
-							NULL);
-		if (error != CL_SUCCESS) 
-			fatal_CL(error, __LINE__);
-		printf("\tPlatform %d: %s\n", plat_count, pbuf);
-
-	}
-
-	// Select platform on the basis of the passed as function argument
-	platform = platforms[platform_id];
-	printf("Selecting platform %d\n", platform_id);
-
-	//====================================================================================================100
-	//	CREATE CONTEXT FOR THE PLATFORM
-	//====================================================================================================100
-
-	// Create context properties for selected platform
-	cl_context_properties context_properties[3] = {	CL_CONTEXT_PLATFORM, 
-													(cl_context_properties) platform, 
-													0};
-                          
-  // Create the device_type selector in the basis of the argument passed (use_gpu)                        
-  cl_device_type device_type = use_gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU;
-  
-	// Create context for selected platform being GPU or CPU
-	cl_context context;
-	context = clCreateContextFromType(	context_properties, 
-										device_type, 
-										NULL, 
-										NULL, 
-										&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	GET DEVICES AVAILABLE FOR THE CONTEXT, SELECT ONE
-	//====================================================================================================100
-
-	// Get number of devices (previousely selected for the context)
-	size_t devices_size;
-	error = clGetContextInfo(	context, 
-								CL_CONTEXT_DEVICES, 
-								0, 
-								NULL, 
-								&devices_size);		// number of bytes (devices * sizeof(cl_device_id))
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	int num_devices = devices_size / sizeof(cl_device_id);
-	printf("# of devices %d\n", num_devices);
-
-	// Get the list of devices (previousely selected for the context)
-	cl_device_id* devices = (cl_device_id*)malloc(num_devices*sizeof(cl_device_id));
-	error = clGetContextInfo(	context, 
-								CL_CONTEXT_DEVICES, 
-								devices_size, 
-								devices, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Get names of devices and print them
-	cl_char dbuf[100];
-	int devi_count;
-	cl_device_id device;
-	for(devi_count = 0; devi_count < num_devices; devi_count++){
-
-		device = devices[devi_count];
-
-		error = clGetDeviceInfo(device, 
-								CL_DEVICE_NAME, 
-								sizeof(dbuf), 
-								dbuf, 
-								NULL);
-		if (error != CL_SUCCESS) 
-			fatal_CL(error, __LINE__);
-		printf("\tDevice %d: %s\n", devi_count, dbuf);
-
-	}
-
-	// Select device on the basis of the argument passed as function argument
-	device = devices[device_id];
-	printf("Selecting device %d\n", device_id);
-
-	//====================================================================================================100
-	//	CREATE COMMAND QUEUE FOR THE DEVICE
-	//====================================================================================================100
-
-	// Create a command queue
-	cl_command_queue command_queue;
-	command_queue = clCreateCommandQueue(	context, 
-											device, 
-											0, 
-											&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	CREATE PROGRAM, COMPILE IT
-	//====================================================================================================100
-
-	// Load kernel source code from file
-	const char *source = load_kernel_source("./kernel/kernel_gpu_opencl.cl");
-	size_t sourceSize = strlen(source);
-
-	// Create the program
-	cl_program program = clCreateProgramWithSource(	context, 
-													1, 
-													&source, 
-													&sourceSize, 
-													&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-
-  char clOptions[150];
-//  sprintf(clOptions,"-I../../src");                                                    
-  sprintf(clOptions,"-I.");
-#ifdef RD_WG_SIZE
-  sprintf(clOptions + strlen(clOptions), " -DRD_WG_SIZE=%d", RD_WG_SIZE);
-#endif
-#ifdef RD_WG_SIZE_0
-  sprintf(clOptions + strlen(clOptions), " -DRD_WG_SIZE_0=%d", RD_WG_SIZE_0);
-#endif
-#ifdef RD_WG_SIZE_0_0
-  sprintf(clOptions + strlen(clOptions), " -DRD_WG_SIZE_0_0=%d", RD_WG_SIZE_0_0);
-#endif
-	// Compile the program
-	error = clBuildProgram(	program, 
-							1, 
-							&device, 
-							clOptions, 
-							NULL, 
-							NULL);
-	// Print warnings and errors from compilation
-	static cl_char log[65536]; 
-	memset(log, 0, sizeof(log));
-	clGetProgramBuildInfo(	program, 
-							device, 
-							CL_PROGRAM_BUILD_LOG, 
-							sizeof(log)-1, 
-							log, 
-							NULL);
-	printf("-----OpenCL Compiler Output-----\n");
-	if (strstr(log,"warning:") || strstr(log, "error:")) 
-		printf("<<<<\n%s\n>>>>\n", log);
-	printf("--------------------------------\n");
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Create kernel
-	cl_kernel kernel;
-	kernel = clCreateKernel(program, 
-							"kernel_gpu_opencl", 
-							&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	TRIGGERING INITIAL DRIVER OVERHEAD
-	//====================================================================================================100
-
-	// cudaThreadSynchronize();		// the above does it
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY ALLOCATION
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	Common	(COPY IN)
-	//====================================================================================================100
-
-	cl_mem d_common;
-	d_common = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.common_mem,
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	Frame	(COPY IN)
-	//====================================================================================================100
-
-	// common
-	cl_mem d_frame;
-	d_frame = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.frame_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	Inputs	(COPY IN)
-	//====================================================================================================100
-
-	//==================================================50
-	//	endo points
-	//==================================================50
-
-	// common
-	cl_mem d_endoRow;
-	d_endoRow = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.endo_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	cl_mem d_endoCol;
-	d_endoCol = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.endo_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	cl_mem d_tEndoRowLoc;
-	d_tEndoRowLoc = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.endo_mem * common.no_frames, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	cl_mem d_tEndoColLoc;
-	d_tEndoColLoc = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.endo_mem * common.no_frames, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	epi points
-	//==================================================50
-
-	// common
-	cl_mem d_epiRow;
-	d_epiRow = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.epi_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	cl_mem d_epiCol;
-	d_epiCol = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.epi_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	cl_mem d_tEpiRowLoc;
-	d_tEpiRowLoc = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.epi_mem * common.no_frames, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	cl_mem d_tEpiColLoc;
-	d_tEpiColLoc = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.epi_mem * common.no_frames, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	// 	Array of Templates for All Points	(COPY IN)
-	//====================================================================================================100
-
-	//==================================================50
-	// template sizes
-	//==================================================50
-
-	// common
-	printf("tSize is %d, sSize is %d\n", common.tSize, common.sSize);
-	common.in_rows = common.tSize + 1 + common.tSize;
-	common.in_cols = common.in_rows;
-	common.in_elem = common.in_rows * common.in_cols;
-	common.in_mem = sizeof(fp) * common.in_elem;
-
-	//==================================================50
-	// endo points templates
-	//==================================================50
-
-	// common
-	cl_mem d_endoT;
-	d_endoT = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.in_mem * common.endoPoints, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	// epi points templates
-	//==================================================50
-
-	// common
-	cl_mem d_epiT;
-	d_epiT = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.in_mem * common.epiPoints, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	// 	AREA AROUND POINT		FROM	FRAME	(LOCAL)
-	//====================================================================================================100
-
-	// common
-	common.in2_rows = common.sSize + 1 + common.sSize;
-	common.in2_cols = common.in2_rows;
-	common.in2_elem = common.in2_rows * common.in2_cols;
-	common.in2_mem = sizeof(fp) * common.in2_elem;
-
-	// unique
-	cl_mem d_in2;
-	d_in2 = clCreateBuffer(	context, 
-							CL_MEM_READ_WRITE, 
-							common.in2_mem * common.allPoints, 
-							NULL, 
-							&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	// 	CONVOLUTION	(LOCAL)
-	//====================================================================================================100
-
-	// common
-	common.conv_rows = common.in_rows + common.in2_rows - 1;												// number of rows in I
-	common.conv_cols = common.in_cols + common.in2_cols - 1;												// number of columns in I
-	common.conv_elem = common.conv_rows * common.conv_cols;													// number of elements
-	common.conv_mem = sizeof(fp) * common.conv_elem;
-	common.ioffset = 0;
-	common.joffset = 0;
-
-	// unique
-	cl_mem d_conv;
-	d_conv = clCreateBuffer(context, 
-							CL_MEM_READ_WRITE, 
-							common.conv_mem * common.allPoints, 
-							NULL, 
-							&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	// 	CUMULATIVE SUM	(LOCAL)
-	//====================================================================================================100
-
-	//==================================================50
-	// 	PADDING OF ARRAY, VERTICAL CUMULATIVE SUM
-	//==================================================50
-
-	// common
-	common.in2_pad_add_rows = common.in_rows;
-	common.in2_pad_add_cols = common.in_cols;
-
-	common.in2_pad_cumv_rows = common.in2_rows + 2*common.in2_pad_add_rows;
-	common.in2_pad_cumv_cols = common.in2_cols + 2*common.in2_pad_add_cols;
-	common.in2_pad_cumv_elem = common.in2_pad_cumv_rows * common.in2_pad_cumv_cols;
-	common.in2_pad_cumv_mem = sizeof(fp) * common.in2_pad_cumv_elem;
-
-	// unique
-	cl_mem d_in2_pad_cumv;
-	d_in2_pad_cumv = clCreateBuffer(context, 
-									CL_MEM_READ_WRITE, 
-									common.in2_pad_cumv_mem * common.allPoints, 
-									NULL, 
-									&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	// 	SELECTION
-	//==================================================50
-
-	// common
-	common.in2_pad_cumv_sel_rowlow = 1 + common.in_rows;													// (1 to n+1)
-	common.in2_pad_cumv_sel_rowhig = common.in2_pad_cumv_rows - 1;
-	common.in2_pad_cumv_sel_collow = 1;
-	common.in2_pad_cumv_sel_colhig = common.in2_pad_cumv_cols;
-	common.in2_pad_cumv_sel_rows = common.in2_pad_cumv_sel_rowhig - common.in2_pad_cumv_sel_rowlow + 1;
-	common.in2_pad_cumv_sel_cols = common.in2_pad_cumv_sel_colhig - common.in2_pad_cumv_sel_collow + 1;
-	common.in2_pad_cumv_sel_elem = common.in2_pad_cumv_sel_rows * common.in2_pad_cumv_sel_cols;
-	common.in2_pad_cumv_sel_mem = sizeof(fp) * common.in2_pad_cumv_sel_elem;
-
-	// unique
-	cl_mem d_in2_pad_cumv_sel;
-	d_in2_pad_cumv_sel = clCreateBuffer(context, 
-										CL_MEM_READ_WRITE, 
-										common.in2_pad_cumv_sel_mem * common.allPoints, 
-										NULL, 
-										&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	// 	SELECTION	2, SUBTRACTION, HORIZONTAL CUMULATIVE SUM
-	//==================================================50
-
-	// common
-	common.in2_pad_cumv_sel2_rowlow = 1;
-	common.in2_pad_cumv_sel2_rowhig = common.in2_pad_cumv_rows - common.in_rows - 1;
-	common.in2_pad_cumv_sel2_collow = 1;
-	common.in2_pad_cumv_sel2_colhig = common.in2_pad_cumv_cols;
-	common.in2_sub_cumh_rows = common.in2_pad_cumv_sel2_rowhig - common.in2_pad_cumv_sel2_rowlow + 1;
-	common.in2_sub_cumh_cols = common.in2_pad_cumv_sel2_colhig - common.in2_pad_cumv_sel2_collow + 1;
-	common.in2_sub_cumh_elem = common.in2_sub_cumh_rows * common.in2_sub_cumh_cols;
-	common.in2_sub_cumh_mem = sizeof(fp) * common.in2_sub_cumh_elem;
-
-	// unique
-	cl_mem d_in2_sub_cumh;
-	d_in2_sub_cumh = clCreateBuffer(context, 
-									CL_MEM_READ_WRITE, 
-									common.in2_sub_cumh_mem * common.allPoints, 
-									NULL, 
-									&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	// 	SELECTION
-	//==================================================50
-
-	// common
-	common.in2_sub_cumh_sel_rowlow = 1;
-	common.in2_sub_cumh_sel_rowhig = common.in2_sub_cumh_rows;
-	common.in2_sub_cumh_sel_collow = 1 + common.in_cols;
-	common.in2_sub_cumh_sel_colhig = common.in2_sub_cumh_cols - 1;
-	common.in2_sub_cumh_sel_rows = common.in2_sub_cumh_sel_rowhig - common.in2_sub_cumh_sel_rowlow + 1;
-	common.in2_sub_cumh_sel_cols = common.in2_sub_cumh_sel_colhig - common.in2_sub_cumh_sel_collow + 1;
-	common.in2_sub_cumh_sel_elem = common.in2_sub_cumh_sel_rows * common.in2_sub_cumh_sel_cols;
-	common.in2_sub_cumh_sel_mem = sizeof(fp) * common.in2_sub_cumh_sel_elem;
-
-	// unique
-	cl_mem d_in2_sub_cumh_sel;
-	d_in2_sub_cumh_sel = clCreateBuffer(context, 
-										CL_MEM_READ_WRITE, 
-										common.in2_sub_cumh_sel_mem * common.allPoints, 
-										NULL, 
-										&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	SELECTION 2, SUBTRACTION
-	//==================================================50
-
-	// common
-	common.in2_sub_cumh_sel2_rowlow = 1;
-	common.in2_sub_cumh_sel2_rowhig = common.in2_sub_cumh_rows;
-	common.in2_sub_cumh_sel2_collow = 1;
-	common.in2_sub_cumh_sel2_colhig = common.in2_sub_cumh_cols - common.in_cols - 1;
-	common.in2_sub2_rows = common.in2_sub_cumh_sel2_rowhig - common.in2_sub_cumh_sel2_rowlow + 1;
-	common.in2_sub2_cols = common.in2_sub_cumh_sel2_colhig - common.in2_sub_cumh_sel2_collow + 1;
-	common.in2_sub2_elem = common.in2_sub2_rows * common.in2_sub2_cols;
-	common.in2_sub2_mem = sizeof(fp) * common.in2_sub2_elem;
-
-	// unique
-	cl_mem d_in2_sub2;
-	d_in2_sub2 = clCreateBuffer(context, 
-								CL_MEM_READ_WRITE, 
-								common.in2_sub2_mem * common.allPoints, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	CUMULATIVE SUM 2	(LOCAL)
-	//====================================================================================================100
-
-	//==================================================50
-	//	MULTIPLICATION
-	//==================================================50
-
-	// common
-	common.in2_sqr_rows = common.in2_rows;
-	common.in2_sqr_cols = common.in2_cols;
-	common.in2_sqr_elem = common.in2_elem;
-	common.in2_sqr_mem = common.in2_mem;
-
-	// unique
-	cl_mem d_in2_sqr;
-	d_in2_sqr = clCreateBuffer(context, 
-								CL_MEM_READ_WRITE, 
-								common.in2_sqr_mem * common.allPoints, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	SELECTION 2, SUBTRACTION
-	//==================================================50
-
-	// common
-	common.in2_sqr_sub2_rows = common.in2_sub2_rows;
-	common.in2_sqr_sub2_cols = common.in2_sub2_cols;
-	common.in2_sqr_sub2_elem = common.in2_sub2_elem;
-	common.in2_sqr_sub2_mem = common.in2_sub2_mem;
-
-	// unique
-	cl_mem d_in2_sqr_sub2;
-	d_in2_sqr_sub2 = clCreateBuffer(context, 
-									CL_MEM_READ_WRITE, 
-									common.in2_sqr_sub2_mem * common.allPoints, 
-									NULL, 
-									&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	FINAL	(LOCAL)
-	//====================================================================================================100
-
-	// common
-	common.in_sqr_rows = common.in_rows;
-	common.in_sqr_cols = common.in_cols;
-	common.in_sqr_elem = common.in_elem;
-	common.in_sqr_mem = common.in_mem;
-
-	// unique
-	cl_mem d_in_sqr;
-	d_in_sqr = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.in_sqr_mem * common.allPoints, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	TEMPLATE MASK CREATE	(LOCAL)
-	//====================================================================================================100
-
-	// common
-	common.tMask_rows = common.in_rows + (common.sSize+1+common.sSize) - 1;
-	common.tMask_cols = common.tMask_rows;
-	common.tMask_elem = common.tMask_rows * common.tMask_cols;
-	common.tMask_mem = sizeof(fp) * common.tMask_elem;
-
-	// unique
-	cl_mem d_tMask;
-	d_tMask = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								common.tMask_mem * common.allPoints, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	POINT MASK INITIALIZE	(LOCAL)
-	//====================================================================================================100
-
-	// common
-	common.mask_rows = common.maxMove;
-	common.mask_cols = common.mask_rows;
-	common.mask_elem = common.mask_rows * common.mask_cols;
-	common.mask_mem = sizeof(fp) * common.mask_elem;
-
-	//====================================================================================================100
-	//	MASK CONVOLUTION	(LOCAL)
-	//====================================================================================================100
-
-	// common
-	common.mask_conv_rows = common.tMask_rows;												// number of rows in I
-	common.mask_conv_cols = common.tMask_cols;												// number of columns in I
-	common.mask_conv_elem = common.mask_conv_rows * common.mask_conv_cols;												// number of elements
-	common.mask_conv_mem = sizeof(fp) * common.mask_conv_elem;
-	common.mask_conv_ioffset = (common.mask_rows-1)/2;
-	if((common.mask_rows-1) % 2 > 0.5){
-		common.mask_conv_ioffset = common.mask_conv_ioffset + 1;
-	}
-	common.mask_conv_joffset = (common.mask_cols-1)/2;
-	if((common.mask_cols-1) % 2 > 0.5){
-		common.mask_conv_joffset = common.mask_conv_joffset + 1;
-	}
-
-	// unique
-	cl_mem d_mask_conv;
-	d_mask_conv = clCreateBuffer(	context, 
-									CL_MEM_READ_WRITE, 
-									common.mask_conv_mem * common.allPoints, 
-									NULL, 
-									&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	GPU MEMORY			COPY
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	Inputs
-	//====================================================================================================100
-
-	//==================================================50
-	// endo points
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue, 
-									d_endoRow, 
-									1, 
-									0, 
-									common.endo_mem, 
-									endoRow, 
-									0, 
-									0, 
-									0);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	error = clEnqueueWriteBuffer(	command_queue, 
-									d_endoCol, 
-									1, 
-									0, 
-									common.endo_mem, 
-									endoCol, 
-									0, 
-									0, 
-									0);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	// epi points
-	//==================================================50
-
-	error = clEnqueueWriteBuffer(	command_queue, 
-									d_epiRow, 
-									1, 
-									0, 
-									common.epi_mem, 
-									epiRow, 
-									0, 
-									0, 
-									0);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	error = clEnqueueWriteBuffer(	command_queue, 
-									d_epiCol, 
-									1, 
-									0, 
-									common.epi_mem, 
-									epiCol, 
-									0, 
-									0, 
-									0);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//==================================================50
-	//	END
-	//==================================================50
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	KERNEL
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	EXECUTION PARAMETERS
-	//====================================================================================================100
-
-	// All kernels operations within kernel use same max size of threads. Size of block size is set to the size appropriate for max size operation (on padded matrix). Other use subsets of that.
-	size_t local_work_size[1];
-	local_work_size[0] = NUMBER_THREADS;
-	size_t global_work_size[1];
-	global_work_size[0] = common.allPoints * local_work_size[0];
-
-	printf("# of workgroups = %d, # of threads/workgroup = %d (ensure that device can handle)\n", (int)(global_work_size[0]/local_work_size[0]), (int)local_work_size[0]);
-
-	//====================================================================================================100
-	//	COPY ARGUMENTS
-	//====================================================================================================100
-
-	error = clEnqueueWriteBuffer(	command_queue, 
-									d_common, 
-									1, 
-									0, 
-									common.common_mem, 
-									&common, 
-									0, 
-									0, 
-									0);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	set kernel arguments
-	//====================================================================================================100
-
-	// structures
-	error = clSetKernelArg(	kernel, 
-							0, 
-							sizeof(params_common), 
-							(void *) &common);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// common
-	error = clSetKernelArg(	kernel, 
-							3, 
-							sizeof(cl_mem), 
-							(void *) &d_endoRow);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							4, 
-							sizeof(cl_mem), 
-							(void *) &d_endoCol);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							5, 
-							sizeof(cl_mem), 
-							(void *) &d_tEndoRowLoc);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							6, 
-							sizeof(cl_mem), 
-							(void *) &d_tEndoColLoc);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							7, 
-							sizeof(cl_mem), 
-							(void *) &d_epiRow);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							8, 
-							sizeof(cl_mem), 
-							(void *) &d_epiCol);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							9, 
-							sizeof(cl_mem), 
-							(void *) &d_tEpiRowLoc);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							10, 
-							sizeof(cl_mem), 
-							(void *) &d_tEpiColLoc);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// common_unique
-	error = clSetKernelArg(	kernel, 
-							11, 
-							sizeof(cl_mem), 
-							(void *) &d_endoT);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							12, 
-							sizeof(cl_mem), 
-							(void *) &d_epiT);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							13, 
-							sizeof(cl_mem), 
-							(void *) &d_in2);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							14, 
-							sizeof(cl_mem), 
-							(void *) &d_conv);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							15, 
-							sizeof(cl_mem), 
-							(void *) &d_in2_pad_cumv);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							16, 
-							sizeof(cl_mem), 
-							(void *) &d_in2_pad_cumv_sel);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							17, 
-							sizeof(cl_mem), 
-							(void *) &d_in2_sub_cumh);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							18, 
-							sizeof(cl_mem), 
-							(void *) &d_in2_sub_cumh_sel);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							19, 
-							sizeof(cl_mem), 
-							(void *) &d_in2_sub2);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							20, 
-							sizeof(cl_mem), 
-							(void *) &d_in2_sqr);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							21, 
-							sizeof(cl_mem), 
-							(void *) &d_in2_sqr_sub2);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							22, 
-							sizeof(cl_mem), 
-							(void *) &d_in_sqr);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							23, 
-							sizeof(cl_mem), 
-							(void *) &d_tMask);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							24, 
-							sizeof(cl_mem), 
-							(void *) &d_mask_conv);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// // local
-	// // int local_size_one;
-	// // local_size_one = common.in_rows;
-	// error = clSetKernelArg(	kernel, 
-							// 25, 
-							// // sizeof(fp) * local_size_one, 	// size 51
-							// sizeof(fp) * common.in_elem,
-							// NULL);
-	// if (error != CL_SUCCESS) 
-		// fatal_CL(error, __LINE__);
-	// error = clSetKernelArg(	kernel, 
-							// 26, 
-							// // sizeof(fp) * local_size_one, 	// size 51
-							// sizeof(fp) * common.in_cols,
-							// NULL);
-	// if (error != CL_SUCCESS) 
-		// fatal_CL(error, __LINE__);
-	// // int local_size_two;
-	// // local_size_two = common.in_rows + common.in2_rows - 1;
-	// error = clSetKernelArg(	kernel, 
-							// 27, 
-							// // sizeof(fp) * local_size_two, 	// size 51+81-1=131
-							// sizeof(fp) * common.in_sqr_rows,
-							// NULL);
-	// if (error != CL_SUCCESS) 
-		// fatal_CL(error, __LINE__);
-	// error = clSetKernelArg(	kernel, 
-							// 28, 
-							// // sizeof(fp) * local_size_two, 	// size 51+81-1=131
-							// sizeof(fp) * common.mask_conv_rows,
-							// NULL);
-	// if (error != CL_SUCCESS) 
-		// fatal_CL(error, __LINE__);
-	// // int local_size_three;
-	// // local_size_three = common.in_rows * common.in_rows;
-	// error = clSetKernelArg(	kernel, 
-							// 29, 
-							// // sizeof(fp) * local_size_three, 	// size 51*51=2601
-							// sizeof(int) * common.mask_conv_rows,
-							// NULL);
-	// if (error != CL_SUCCESS) 
-		// fatal_CL(error, __LINE__);
-
-	// int local_size;
-	// local_size = (common.in_elem + common.in_cols + common.in_sqr_rows + common.mask_conv_rows) * 4 + common.mask_conv_rows * 2;
-	// printf("size of used local memory/workgroup = %dB (ensure that device can handle)\n", local_size);
-
-	cl_mem d_in_mod_temp;
-	d_in_mod_temp = clCreateBuffer(	context, 
-									CL_MEM_READ_WRITE, 
-									sizeof(fp) * common.in_elem * common.allPoints, 
-									NULL, 
-									&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	cl_mem in_partial_sum;
-	in_partial_sum = clCreateBuffer(context, 
-										CL_MEM_READ_WRITE, 
-										sizeof(fp) * common.in_cols * common.allPoints, 
-										NULL, 
-										&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	cl_mem in_sqr_partial_sum;
-	in_sqr_partial_sum = clCreateBuffer(context, 
-										CL_MEM_READ_WRITE, 
-										sizeof(fp) * common.in_sqr_rows * common.allPoints, 
-										NULL, 
-										&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	cl_mem par_max_val;
-	par_max_val = clCreateBuffer(	context, 
-									CL_MEM_READ_WRITE, 
-									sizeof(fp) * common.mask_conv_rows * common.allPoints, 
-									NULL, 
-									&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	cl_mem par_max_coo;
-	par_max_coo = clCreateBuffer(	context, 
-									CL_MEM_READ_WRITE, 
-									sizeof(int) * common.mask_conv_rows * common.allPoints, 
-									NULL, 
-									&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	cl_mem in_final_sum;
-	in_final_sum = clCreateBuffer(	context, 
-									CL_MEM_READ_WRITE, 
-									sizeof(fp) * common.allPoints, 
-									NULL, 
-									&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	cl_mem in_sqr_final_sum;
-	in_sqr_final_sum = clCreateBuffer(	context, 
-										CL_MEM_READ_WRITE, 
-										sizeof(fp) * common.allPoints, 
-										NULL, 
-										&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	cl_mem denomT;
-	denomT = clCreateBuffer(context, 
-							CL_MEM_READ_WRITE, 
-							sizeof(fp) * common.allPoints, 
-							NULL, 
-							&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-
-
-	error = clSetKernelArg(	kernel, 
-							25, 
-							sizeof(cl_mem),
-							(void *) &d_in_mod_temp);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							26, 
-							sizeof(cl_mem),
-							(void *) &in_partial_sum);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							27, 
-							sizeof(cl_mem),
-							(void *) &in_sqr_partial_sum);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							28, 
-							sizeof(cl_mem),
-							(void *) &par_max_val);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							29, 
-							sizeof(cl_mem),
-							(void *) &par_max_coo);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							30, 
-							sizeof(cl_mem),
-							(void *) &in_final_sum);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							31, 
-							sizeof(cl_mem),
-							(void *) &in_sqr_final_sum);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clSetKernelArg(	kernel, 
-							32, 
-							sizeof(cl_mem),
-							(void *) &denomT);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-
-
-	cl_mem d_checksum;
-	d_checksum = clCreateBuffer(context, 
-								CL_MEM_READ_WRITE, 
-								sizeof(fp) * CHECK, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	error = clSetKernelArg(	kernel, 
-							33, 
-							sizeof(cl_mem),
-							(void *) &d_checksum);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	PRINT FRAME PROGRESS START
-	//====================================================================================================100
-
-	printf("frame progress: ");
-	fflush(NULL);
-
-	//====================================================================================================100
-	//	LAUNCH
-	//====================================================================================================100
-
-	// variables
-	fp* frame;
-	int frame_no;
-
-	for(frame_no=0; frame_no<common.frames_processed; frame_no++){
-
-		//==================================================50
-		//	get and write current frame to GPU buffer
-		//==================================================50
-
-		// Extract a cropped version of the first frame from the video file
-		frame = get_frame(	frames,								// pointer to video file
-							frame_no,							// number of frame that needs to be returned
-							0,									// cropped?
-							0,									// scaled?
-							1);									// converted
-
-		// copy frame to GPU memory
-		error = clEnqueueWriteBuffer(	command_queue, 
-										d_frame, 
-										1, 
-										0, 
-										common.frame_mem, 
-										frame, 
-										0, 
-										0, 
-										0);
-		if (error != CL_SUCCESS) 
-			fatal_CL(error, __LINE__);
-
-		//==================================================50
-		//	kernel arguments that change inside this loop
-		//==================================================50
-
-		// common_change
-		error = clSetKernelArg(	kernel, 
-								1, 
-								sizeof(cl_mem), 
-								(void *) &d_frame);
-		if (error != CL_SUCCESS) 
-			fatal_CL(error, __LINE__);
-		error = clSetKernelArg(	kernel, 
-								2, 
-								sizeof(int), 
-								(void *) &frame_no);
-		if (error != CL_SUCCESS) 
-			fatal_CL(error, __LINE__);
-
-		//==================================================50
-		//	launch kernel
-		//==================================================50
-
-		error = clEnqueueNDRangeKernel(	command_queue, 
-										kernel, 
-										1, 
-										NULL, 
-										global_work_size, 
-										local_work_size, 
-										0, 
-										NULL, 
-										NULL);
-		if (error != CL_SUCCESS) 
-			fatal_CL(error, __LINE__);
-
-		//==================================================50
-		//	finish iteration
-		//==================================================50
-
-		// Synchronization, wait for all operations in the command queue so far to finish
-		error = clFinish(command_queue);
-		if (error != CL_SUCCESS) 
-			fatal_CL(error, __LINE__);
-
-		// free frame after each loop iteration, since AVI library allocates memory for every frame fetched
-		free(frame);
-
-		//==================================================50
-		//	print frame progress
-		//==================================================50
-
-		// print frame progress
-		printf("%d ", frame_no);
-		fflush(NULL);
-
-		//==================================================50
-		//	DISPLAY CHECKSUM (TESTING)
-		//==================================================50
-
-#ifdef TEST_CHECKSUM
-		fp* checksum;
-		checksum = (fp*)malloc(sizeof(fp) * CHECK);
-		error = clEnqueueReadBuffer(command_queue,
-									d_checksum,
-									CL_TRUE,
-									0,
-									sizeof(fp)*CHECK,
-									checksum,
-									0,
-									NULL,
-									NULL);
-		if (error != CL_SUCCESS) 
-			fatal_CL(error, __LINE__);
-		printf("CHECKSUM:\n");
-		for(i=0; i<CHECK; i++){
-				printf("%f ", checksum[i]);
-		}
-		printf("\n\n");
-#endif
-
-		//==================================================50
-		//	End
-		//==================================================50
-
-	}
-
-	//====================================================================================================100
-	//	PRINT FRAME PROGRESS END
-	//====================================================================================================100
-
-	printf("\n");
-	fflush(NULL);
-
-	//======================================================================================================================================================150
-	//	OUTPUT
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	// endo points
-	//====================================================================================================100
-
-	error = clEnqueueReadBuffer(command_queue,
-								d_tEndoRowLoc,
-								CL_TRUE,
-								0,
-								common.endo_mem * common.no_frames,
-								tEndoRowLoc,
-								0,
-								NULL,
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// for testing of the output
-#ifdef TEST_OUTPUT
-	int j;
-	for(i=0; i<common.frames_processed; i++){
-		printf("%d: ", i);
-		for(j=0; j<common.endoPoints; j++){
-			printf("%d ", tEndoRowLoc[j*common.no_frames+i]);
-		}
-		printf("\n\n");
-	}
-#endif
-
-	error = clEnqueueReadBuffer(command_queue,
-								d_tEndoColLoc,
-								CL_TRUE,
-								0,
-								common.endo_mem * common.no_frames,
-								tEndoColLoc,
-								0,
-								NULL,
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	// epi points
-	//====================================================================================================100
-
-	error = clEnqueueReadBuffer(command_queue,
-								d_tEpiRowLoc,
-								CL_TRUE,
-								0,
-								common.epi_mem * common.no_frames,
-								tEpiRowLoc,
-								0,
-								NULL,
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);;
-
-	error = clEnqueueReadBuffer(command_queue,
-								d_tEpiColLoc,
-								CL_TRUE,
-								0,
-								common.epi_mem * common.no_frames,
-								tEpiColLoc,
-								0,
-								NULL,
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//======================================================================================================================================================150
-	//	DEALLOCATION
-	//======================================================================================================================================================150
-
-	// OpenCL structures
-	error = clReleaseKernel(kernel);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseProgram(program);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// common_change
-	error = clReleaseMemObject(d_frame);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// common
-	error = clReleaseMemObject(d_endoRow);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_endoCol);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_tEndoRowLoc);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_tEndoColLoc);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_epiRow);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_epiCol);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_tEpiRowLoc);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_tEpiColLoc);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// common_unique
-	error = clReleaseMemObject(d_endoT);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_epiT);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_in2);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_conv);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_in2_pad_cumv);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_in2_pad_cumv_sel);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_in2_sub_cumh);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_in2_sub_cumh_sel);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_in2_sub2);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_in2_sqr);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_in2_sqr_sub2);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_in_sqr);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_tMask);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseMemObject(d_mask_conv);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// OpenCL structures
-	error = clFlush(command_queue);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseCommandQueue(command_queue);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	error = clReleaseContext(context);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//======================================================================================================================================================150
-	//	End
-	//======================================================================================================================================================150
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200

+ 0 - 30
opencl/heartwall/kernel/kernel_gpu_opencl_wrapper.h

@@ -1,30 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//========================================================================================================================================================================================================200
-//	KERNEL_GPU_CUDA_WRAPPER HEADER
-//========================================================================================================================================================================================================200
-
-void 
-kernel_gpu_opencl_wrapper(params_common common,
-							int* endoRow,
-							int* endoCol,
-							int* tEndoRowLoc,
-							int* tEndoColLoc,
-							int* epiRow,
-							int* epiCol,
-							int* tEpiRowLoc,
-							int* tEpiColLoc,
-							avi_t* frames,
-              int platform_id,
-              int device_id,
-              int use_gpu);
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 296
opencl/heartwall/main.c

@@ -1,296 +0,0 @@
-//========================================================================================================================================================================================================200
-//======================================================================================================================================================150
-//====================================================================================================100
-//==================================================50
-
-//========================================================================================================================================================================================================200
-//	DEFINE / INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <stdlib.h>								// (in directory known to compiler)
-#include <math.h>								// (in directory known to compiler)
-#include <string.h>								// (in directory known to compiler)
-
-//======================================================================================================================================================150
-//	MAIN FUNCTION HEADER
-//======================================================================================================================================================150
-
-#include "./main.h"								// (in the main program folder)	needed to recognized input parameters
-
-//======================================================================================================================================================150
-//	UTILITIES
-//======================================================================================================================================================150
-
-#include "./util/avi/avilib.h"					// (in directory)							needed by avi functions
-#include "./util/avi/avimod.h"					// (in directory)							needed by avi functions
-
-//======================================================================================================================================================150
-//	KERNEL
-//======================================================================================================================================================150
-
-#include "./kernel/kernel_gpu_opencl_wrapper.h"
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	MAIN FUNCTION
-//========================================================================================================================================================================================================200
-
-int 
-main(	int argc, 
-		char* argv []){
-
-
-  printf("WG size of kernel = %d \n", NUMBER_THREADS);
-	//======================================================================================================================================================150
-	//	VARIABLES
-	//======================================================================================================================================================150
-
-	// time
-	long long time0;
-	long long time1;
-	long long time2;
-	long long time3;
-	long long time4;
-	long long time5;
-
-	// other
-	int i;
-	avi_t* frames;
-  
-  // OpenCL platform and device selection
-  int platform_id = 0;
-  int device_id = 0;
-  int use_gpu = 0;
-
-	time0 = get_time();
-
-	//======================================================================================================================================================150
-	//	STRUCTURES, GLOBAL STRUCTURE VARIABLES
-	//======================================================================================================================================================150
-
-	params_common common;
-	common.common_mem = sizeof(params_common);
-
-	//======================================================================================================================================================150
-	// 	FRAME INFO
-	//======================================================================================================================================================150
-
-	// variables
-	char* video_file_name;
-
-	// open movie file
- 	video_file_name = (char *) "../../data/heartwall/test.avi";
-	frames = (avi_t*)AVI_open_input_file(video_file_name, 1);														// added casting
-	if (frames == NULL)  {
-		   AVI_print_error((char *) "Error with AVI_open_input_file");
-		   return -1;
-	}
-
-	// dimensions
-	common.no_frames = AVI_video_frames(frames);
-	common.frame_rows = AVI_video_height(frames);
-	common.frame_cols = AVI_video_width(frames);
-	common.frame_elem = common.frame_rows * common.frame_cols;
-	common.frame_mem = sizeof(fp) * common.frame_elem;
-
-	time1 = get_time();
-
-	//======================================================================================================================================================150
-	// 	CHECK INPUT ARGUMENTS
-	//======================================================================================================================================================150
-
-	if(argc!=5){
-		printf("ERROR: missing argument (number of frames to processed) or too many arguments\n\
-    Usage <number of frames> <platform_id> <device_id> <use_gpu>");
-		return 0;
-	}
-	else{
-		common.frames_processed = atoi(argv[1]);
-		if(common.frames_processed<0 || common.frames_processed>common.no_frames){
-			printf("ERROR: %d is an incorrect number of frames specified, select in the range of 0-%d\n", common.frames_processed, common.no_frames);
-			return 0;
-		}
-    platform_id = atoi(argv[2]);
-    device_id = atoi(argv[3]);
-    use_gpu = atoi(argv[4]);
-	}
-
-	time2 = get_time();
-
-	//======================================================================================================================================================150
-	//	INPUTS
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	READ PARAMETERS FROM FILE
-	//====================================================================================================100
-
-	read_parameters(	"../../data/heartwall/input.txt",
-						&common.tSize,
-						&common.sSize,
-						&common.maxMove,
-						&common.alpha);
-
-	//====================================================================================================100
-	//	READ SIZE OF INPUTS FROM FILE
-	//====================================================================================================100
-
-	read_header(	"../../data/heartwall/input.txt",
-					&common.endoPoints,
-					&common.epiPoints);
-
-	common.allPoints = common.endoPoints + common.epiPoints;
-
-	//====================================================================================================100
-	//	READ DATA FROM FILE
-	//====================================================================================================100
-
-	//==================================================50
-	//	ENDO POINTS MEMORY ALLOCATION
-	//==================================================50
-
-	common.endo_mem = sizeof(int) * common.endoPoints;
-
-	int* endoRow;
-	endoRow = (int*)malloc(common.endo_mem);
-	int* endoCol;
-	endoCol = (int*)malloc(common.endo_mem);
-	int* tEndoRowLoc;
-	tEndoRowLoc = (int*)malloc(common.endo_mem * common.no_frames);
-	int* tEndoColLoc;
-	tEndoColLoc = (int*)malloc(common.endo_mem * common.no_frames);
-
-	//==================================================50
-	//	EPI POINTS MEMORY ALLOCATION
-	//==================================================50
-
-	common.epi_mem = sizeof(int) * common.epiPoints;
-
-	int* epiRow;
-	epiRow = (int *)malloc(common.epi_mem);
-	int* epiCol;
-	epiCol = (int *)malloc(common.epi_mem);
-	int* tEpiRowLoc;
-	tEpiRowLoc = (int *)malloc(common.epi_mem * common.no_frames);
-	int* tEpiColLoc;
-	tEpiColLoc = (int *)malloc(common.epi_mem * common.no_frames);
-
-	//==================================================50
-	//	READ DATA FROM FILE
-	//==================================================50
-
-	read_data(	"../../data/heartwall/input.txt",
-				common.endoPoints,
-				endoRow,
-				endoCol,
-				common.epiPoints,
-				epiRow,
-				epiCol);
-
-	//==================================================50
-	//	End
-	//==================================================50
-
-	//====================================================================================================100
-	//	End
-	//====================================================================================================100
-
-	time3 = get_time();
-
-	//======================================================================================================================================================150
-	//	KERNELL WRAPPER CALL
-	//======================================================================================================================================================150
-
-	kernel_gpu_opencl_wrapper(	common,
-								endoRow,
-								endoCol,
-								tEndoRowLoc,
-								tEndoColLoc,
-								epiRow,
-								epiCol,
-								tEpiRowLoc,
-								tEpiColLoc,
-								frames,
-                platform_id,
-                device_id,
-                use_gpu);
-
-	time4 = get_time();
-
-	//==================================================50
-	//	DUMP DATA TO FILE
-	//==================================================50
-#ifdef OUTPUT
-	write_data(	"result.txt",
-			common.no_frames,
-			common.frames_processed,		
-				common.endoPoints,
-				tEndoRowLoc,
-				tEndoColLoc,
-				common.epiPoints,
-				tEpiRowLoc,
-				tEpiColLoc);
-
-#endif
-	//==================================================50
-	//	End
-	//==================================================50
-
-
-	//======================================================================================================================================================150
-	//	DEALLOCATION
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	// endo points
-	//====================================================================================================100
-
-	free(endoRow);
-	free(endoCol);
-	free(tEndoRowLoc);
-	free(tEndoColLoc);
-
-	//====================================================================================================100
-	// epi points
-	//====================================================================================================100
-
-	free(epiRow);
-	free(epiCol);
-	free(tEpiRowLoc);
-	free(tEpiColLoc);
-
-	//====================================================================================================100
-	//	End
-	//====================================================================================================100
-
-	time5= get_time();
-
-	//======================================================================================================================================================150
-	//	DISPLAY TIMING
-	//======================================================================================================================================================150
-
-	printf("Time spent in different stages of the application:\n");
-	printf("%15.12f s, %15.12f % : READ INITIAL VIDEO FRAME\n",												(fp) (time1-time0) / 1000000, (fp) (time1-time0) / (fp) (time5-time0) * 100);
-	printf("%15.12f s, %15.12f % : READ COMMAND LINE PARAMETERS\n",											(fp) (time2-time1) / 1000000, (fp) (time2-time1) / (fp) (time5-time0) * 100);
-	printf("%15.12f s, %15.12f % : READ INPUTS FROM FILE\n",												(fp) (time3-time2) / 1000000, (fp) (time3-time2) / (fp) (time5-time0) * 100);
-	printf("%15.12f s, %15.12f % : GPU ALLOCATION, COPYING, COMPUTATION\n",									(fp) (time4-time3) / 1000000, (fp) (time4-time3) / (fp) (time5-time0) * 100);
-	printf("%15.12f s, %15.12f % : FREE MEMORY\n", 															(fp) (time5-time4) / 1000000, (fp) (time5-time4) / (fp) (time5-time0) * 100);
-	printf("Total time:\n");
-	printf("%15.12f s\n", 																					(fp) (time5-time0) / 1000000);
-
-	//======================================================================================================================================================150
-	//	End
-	//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	End
-//========================================================================================================================================================================================================200
-
-}

+ 0 - 271
opencl/heartwall/main.h

@@ -1,271 +0,0 @@
-//========================================================================================================================================================================================================200
-//	DEFINE / INCLUDE
-//========================================================================================================================================================================================================200
-
-#define fp float
-
-#ifdef RD_WG_SIZE_0_0
-        #define NUMBER_THREADS RD_WG_SIZE_0_0
-#elif defined(RD_WG_SIZE_0)
-        #define NUMBER_THREADS RD_WG_SIZE_0
-#elif defined(RD_WG_SIZE)
-        #define NUMBER_THREADS RD_WG_SIZE
-#else
-        #define NUMBER_THREADS 128
-#endif
-
-#define CHECK 37
-// #define TEST_CHECKSUM
-// #define TEST_OUTPUT
-// #define INIT
-
-// need to define these for static allocation of constant memory in GPU, because it cannot be allocated dynamically
-#define ENDO_POINTS 20
-#define EPI_POINTS 31
-#define ALL_POINTS 51
-
-//========================================================================================================================================================================================================200
-//	PARAMS_COMMON STRUCTURE
-//========================================================================================================================================================================================================200
-
-typedef struct params_common{
-
-	//======================================================================================================================================================150
-	//	HARDCODED INPUTS FROM MATLAB
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	UNIQUE PARAMETER STRUCTURE MEMORY SIZE
-	//====================================================================================================100
-
-	int common_change_mem;
-	int common_mem;
-	int unique_mem;
-
-	//====================================================================================================100
-	//	USER INPUT
-	//====================================================================================================100
-
-	int frames_processed;
-
-	//====================================================================================================100
-	//	CONSTANTS
-	//====================================================================================================100
-
-	int sSize;
-	int tSize;
-	int maxMove;
-	fp alpha;
-
-	//====================================================================================================100
-	//	FRAME
-	//====================================================================================================100
-
-	int no_frames;
-	int frame_rows;
-	int frame_cols;
-	int frame_elem;
-	int frame_mem;
-
-	//====================================================================================================100
-	//	ENDO POINTS
-	//====================================================================================================100
-
-	int endoPoints;
-	int endo_mem;
-
-	//====================================================================================================100
-	//	EPI POINTS
-	//====================================================================================================100
-	int epiPoints;
-	int epi_mem;
-
-	//====================================================================================================100
-	//	ALL POINTS
-	//====================================================================================================100
-
-	int allPoints;
-
-	//====================================================================================================100
-	//	End
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	RIGHT TEMPLATE 	FROM 	TEMPLATE ARRAY
-	//======================================================================================================================================================150
-
-	int in_rows;
-	int in_cols;
-	int in_elem;
-	int in_mem;
-
-	//======================================================================================================================================================150
-	//	IN_POINTER
-	//======================================================================================================================================================150
-
-	int in_pointer_mem;
-
-	//======================================================================================================================================================150
-	// 	AREA AROUND POINT		FROM	FRAME
-	//======================================================================================================================================================150
-
-	int in2_rows;
-	int in2_cols;
-	int in2_elem;
-	int in2_mem;
-
-	//======================================================================================================================================================150
-	//	CONVOLUTION
-	//======================================================================================================================================================150
-
-	int conv_rows;
-	int conv_cols;
-	int conv_elem;
-	int conv_mem;
-	int ioffset;
-	int joffset;
-
-	//======================================================================================================================================================150
-	//	CUMULATIVE SUM 1
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	PAD ARRAY, VERTICAL CUMULATIVE SUM
-	//====================================================================================================100
-
-	int in2_pad_add_rows;
-	int in2_pad_add_cols;
-	int in2_pad_cumv_rows;
-	int in2_pad_cumv_cols;
-	int in2_pad_cumv_elem;
-	int in2_pad_cumv_mem;
-
-	//====================================================================================================100
-	//	SELECTION
-	//====================================================================================================100
-
-	int in2_pad_cumv_sel_rows;
-	int in2_pad_cumv_sel_cols;
-	int in2_pad_cumv_sel_elem;
-	int in2_pad_cumv_sel_mem;
-	int in2_pad_cumv_sel_rowlow;
-	int in2_pad_cumv_sel_rowhig;
-	int in2_pad_cumv_sel_collow;
-	int in2_pad_cumv_sel_colhig;
-
-	//====================================================================================================100
-	//	SELECTION 2, SUBTRACTION, HORIZONTAL CUMULATIVE SUM
-	//====================================================================================================100
-
-	int in2_pad_cumv_sel2_rowlow;
-	int in2_pad_cumv_sel2_rowhig;
-	int in2_pad_cumv_sel2_collow;
-	int in2_pad_cumv_sel2_colhig;
-	int in2_sub_cumh_rows;
-	int in2_sub_cumh_cols;
-	int in2_sub_cumh_elem;
-	int in2_sub_cumh_mem;
-
-	//====================================================================================================100
-	//	SELECTION
-	//====================================================================================================100
-
-	int in2_sub_cumh_sel_rows;
-	int in2_sub_cumh_sel_cols;
-	int in2_sub_cumh_sel_elem;
-	int in2_sub_cumh_sel_mem;
-	int in2_sub_cumh_sel_rowlow;
-	int in2_sub_cumh_sel_rowhig;
-	int in2_sub_cumh_sel_collow;
-	int in2_sub_cumh_sel_colhig;
-
-	//====================================================================================================100
-	//	SELECTION 2, SUBTRACTION
-	//====================================================================================================100
-
-	int in2_sub_cumh_sel2_rowlow;
-	int in2_sub_cumh_sel2_rowhig;
-	int in2_sub_cumh_sel2_collow;
-	int in2_sub_cumh_sel2_colhig;
-	int in2_sub2_rows;
-	int in2_sub2_cols;
-	int in2_sub2_elem;
-	int in2_sub2_mem;
-
-	//====================================================================================================100
-	//	End
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	CUMULATIVE SUM 2
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	MULTIPLICATION
-	//====================================================================================================100
-
-	int in2_sqr_rows;
-	int in2_sqr_cols;
-	int in2_sqr_elem;
-	int in2_sqr_mem;
-
-	//====================================================================================================100
-	//	SELECTION 2, SUBTRACTION
-	//====================================================================================================100
-
-	int in2_sqr_sub2_rows;
-	int in2_sqr_sub2_cols;
-	int in2_sqr_sub2_elem;
-	int in2_sqr_sub2_mem;
-
-	//====================================================================================================100
-	//	End
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	//	FINAL
-	//======================================================================================================================================================150
-
-	int in_sqr_rows;
-	int in_sqr_cols;
-	int in_sqr_elem;
-	int in_sqr_mem;
-
-	//======================================================================================================================================================150
-	//	TEMPLATE MASK CREATE
-	//======================================================================================================================================================150
-
-	int tMask_rows;
-	int tMask_cols;
-	int tMask_elem;
-	int tMask_mem;
-
-	//======================================================================================================================================================150
-	//	POINT MASK INITIALIZE
-	//======================================================================================================================================================150
-
-	int mask_rows;
-	int mask_cols;
-	int mask_elem;
-	int mask_mem;
-
-	//======================================================================================================================================================150
-	//	MASK CONVOLUTION
-	//======================================================================================================================================================150
-
-	int mask_conv_rows;
-	int mask_conv_cols;
-	int mask_conv_elem;
-	int mask_conv_mem;
-	int mask_conv_ioffset;
-	int mask_conv_joffset;
-
-	//======================================================================================================================================================150
-	//	End
-	//======================================================================================================================================================150
-
-} params_common;
-
-//========================================================================================================================================================================================================200
-//	END OF STRUCTURE
-//========================================================================================================================================================================================================200

+ 0 - 100
opencl/heartwall/makefile

@@ -1,100 +0,0 @@
-include ../../common/make.config
-
-ifdef OUTPUT
-override OUTPUT = -DOUTPUT
-endif
-
-OCL_INC_DIR = -I$(OPENCL_INC)
-OCL_LIB_DIR = -L$(OPENCL_LIB)
-
-C_C = gcc
-OCL_LIB = -lOpenCL
-
-./a.out:	./main.o \
-			./kernel/kernel_gpu_opencl_wrapper.o \
-			./util/avi/avilib.o \
-			./util/avi/avimod.o \
-			./util/file/file.o \
-			./util/timer/timer.o \
-			./util/opencl/opencl.o
-	$(C_C)	./main.o \
-			./kernel/kernel_gpu_opencl_wrapper.o \
-			./util/avi/avilib.o \
-			./util/avi/avimod.o \
-			./util/file/file.o \
-			./util/timer/timer.o \
-			./util/opencl/opencl.o \
-			-lm \
-			$(OCL_LIB_DIR) \
-			$(OCL_LIB) -o heartwall
-
-# ======================================================================================================================================================150
-#	MAIN FUNCTION
-# ======================================================================================================================================================150
-
-./main.o:	./main.h \
-			./main.c
-	$(C_C)	$(OUTPUT) $(KERNEL_DIM) ./main.c \
-			-c \
-			-o ./main.o \
-			-O3
-
-# ======================================================================================================================================================150
-#	KERNELS
-# ======================================================================================================================================================150
-
-./kernel/kernel_gpu_opencl_wrapper.o:	./kernel/kernel_gpu_opencl_wrapper.h \
-										./kernel/kernel_gpu_opencl_wrapper.c
-	$(C_C) $(KERNEL_DIM)	./kernel/kernel_gpu_opencl_wrapper.c \
-			-c \
-			-o ./kernel/kernel_gpu_opencl_wrapper.o \
-			-O3 \
-			$(OCL_INC_DIR)
-
-# ======================================================================================================================================================150
-#	UTILITIES
-# ======================================================================================================================================================150
-
-./util/avi/avilib.o:./util/avi/avilib.h \
-					./util/avi/avilib.c
-	$(C_C)	./util/avi/avilib.c \
-			-c \
-			-o ./util/avi/avilib.o \
-			-O3
-
-./util/avi/avimod.o:./util/avi/avilib.h \
-					./util/avi/avimod.c
-	$(C_C)	./util/avi/avimod.c \
-			-c \
-			-o ./util/avi/avimod.o \
-			-O3
-
-./util/file/file.o:	./util/file/file.h \
-					./util/file/file.c
-	$(C_C)	./util/file/file.c \
-			-c \
-			-o ./util/file/file.o \
-			-O3
-
-./util/timer/timer.o:	./util/timer/timer.h \
-						./util/timer/timer.c
-	$(C_C)	./util/timer/timer.c \
-			-c \
-			-o ./util/timer/timer.o \
-			-O3
-
-./util/opencl/opencl.o:	./util/opencl/opencl.h \
-						./util/opencl/opencl.c
-	$(C_C)	./util/opencl/opencl.c \
-			-c \
-			-o ./util/opencl/opencl.o \
-			-O3 \
-			$(OCL_INC_DIR)
-
-clean:
-	rm	*.o heartwall \
-		./kernel/*.o \
-		./util/avi/*.o \
-		./util/file/*.o \
-		./util/timer/*.o \
-		./util/opencl/*.o

+ 0 - 144
opencl/heartwall/result.txt

@@ -1,144 +0,0 @@
-Total AVI Frames: 104
-Frames Processed: 20
-endoPoints: 20
-epiPoints: 31
----Frame 0---
---endo--
-369	400	429	452	476	486	479	458	433	404	374	346	318	294	277	269	275	287	311	339	
-408	406	397	383	354	322	294	270	250	237	235	241	254	273	300	328	356	383	401	411	
---epi--
-390	419	448	474	501	519	535	542	543	538	528	511	491	466	438	406	376	347	318	291	275	259	256	252	252	257	266	283	305	331	360	
-457	454	446	431	411	388	361	331	301	273	243	218	196	178	166	157	155	165	177	197	218	248	276	304	333	361	391	415	434	448	455	
----Frame 1---
---endo--
-369	400	429	452	476	486	479	458	433	404	374	346	318	294	277	269	275	287	311	339	
-408	406	397	383	354	322	294	270	250	237	235	240	254	273	300	328	356	383	401	411	
---epi--
-390	419	448	474	501	519	535	542	543	538	528	511	491	466	438	406	376	347	318	291	275	259	256	252	252	257	266	283	305	331	360	
-457	454	446	431	411	388	361	331	301	273	243	218	196	178	166	157	155	165	177	197	218	248	276	304	333	361	391	415	434	448	455	
----Frame 2---
---endo--
-369	400	429	450	476	487	480	458	433	404	374	346	318	294	278	270	275	287	311	339	
-405	406	397	385	353	322	294	270	250	236	234	240	253	273	301	329	356	383	402	412	
---epi--
-390	419	448	474	501	519	535	543	544	538	528	511	491	466	438	406	376	347	318	291	275	259	256	253	253	257	266	283	305	331	360	
-457	454	446	431	411	388	361	331	301	273	243	218	196	178	165	158	155	164	176	197	217	247	276	305	334	362	391	416	435	448	456	
----Frame 3---
---endo--
-366	400	429	447	478	488	480	458	433	404	374	346	319	296	279	272	276	287	311	339	
-408	405	396	388	352	322	293	269	249	234	230	238	252	272	301	328	356	384	402	412	
---epi--
-390	419	448	474	501	519	536	543	544	539	528	511	491	466	438	405	375	346	317	290	275	260	258	255	254	258	266	283	305	331	360	
-457	454	446	431	411	388	360	331	302	274	243	218	196	178	165	158	154	163	176	198	217	248	277	306	335	362	392	416	435	449	455	
----Frame 4---
---endo--
-367	398	427	451	477	488	481	458	433	404	374	348	321	298	282	274	278	287	311	338	
-404	404	396	384	350	319	292	268	246	230	228	237	251	272	301	328	355	384	403	413	
---epi--
-389	417	446	472	501	519	535	543	544	538	528	511	491	466	438	405	375	345	316	290	275	261	261	257	257	260	266	283	304	330	359	
-457	453	446	431	411	388	359	331	302	273	243	218	196	177	165	155	154	163	175	197	218	250	279	307	331	361	393	416	436	449	455	
----Frame 5---
---endo--
-365	396	425	449	476	488	481	458	433	404	374	349	323	300	285	276	280	286	309	336	
-404	403	395	384	350	316	290	265	243	229	227	236	250	272	302	328	355	384	403	412	
---epi--
-387	415	444	470	500	518	536	543	543	538	528	511	492	466	438	404	374	346	316	286	275	265	264	261	259	262	266	281	302	328	357	
-455	452	445	430	410	387	361	330	300	273	242	218	195	176	164	154	149	162	172	198	217	248	279	305	332	361	394	417	436	449	454	
----Frame 6---
---endo--
-360	396	424	444	477	489	481	458	432	404	375	350	324	302	287	278	283	285	309	336	
-399	402	394	386	348	313	287	262	239	225	224	235	248	272	301	328	351	385	404	413	
---epi--
-386	414	443	469	498	517	535	545	544	538	528	511	492	467	438	404	374	345	311	286	271	269	266	263	261	265	265	281	301	327	356	
-453	450	443	428	410	384	359	333	302	274	242	217	194	173	162	152	151	160	172	198	218	252	279	306	332	356	394	417	436	449	453	
----Frame 7---
---endo--
-359	393	422	440	476	490	481	457	432	404	375	350	324	304	288	280	284	285	308	334	
-395	400	392	382	343	310	283	258	235	222	221	233	247	272	301	327	353	387	404	412	
---epi--
-384	413	442	467	497	516	533	544	544	538	528	512	493	467	438	404	375	340	309	285	270	271	268	264	262	267	266	281	300	326	354	
-452	449	441	427	409	383	354	333	306	274	242	217	190	172	160	151	150	159	167	199	218	256	278	305	332	354	395	421	436	450	452	
----Frame 8---
---endo--
-354	392	421	440	474	490	482	457	432	403	374	349	326	304	289	280	285	284	307	333	
-395	398	391	381	339	308	279	255	234	217	220	231	245	271	299	326	351	387	404	411	
---epi--
-383	412	441	467	496	515	533	542	544	538	529	512	495	468	435	404	374	337	308	285	268	272	269	265	263	268	265	279	298	324	353	
-450	447	440	425	407	382	358	331	305	273	242	215	189	170	156	146	145	158	168	199	219	260	277	304	330	353	394	421	436	449	450	
----Frame 9---
---endo--
-354	391	420	437	478	492	484	458	432	399	375	348	326	304	290	281	285	284	305	331	
-393	395	389	376	341	309	279	253	230	213	215	229	243	271	298	323	350	387	401	409	
---epi--
-382	411	440	466	495	514	532	542	545	539	530	512	494	469	437	404	373	337	307	282	267	273	269	266	264	268	263	279	297	323	352	
-449	445	439	424	406	386	358	331	309	272	242	212	185	170	155	145	142	156	165	196	216	260	275	302	325	353	393	419	435	448	449	
----Frame 10---
---endo--
-358	390	419	439	473	493	488	458	432	399	376	348	326	304	290	281	285	283	304	330	
-388	394	388	380	341	307	280	250	228	211	211	227	241	269	297	322	348	386	398	407	
---epi--
-381	409	439	465	495	513	532	543	545	539	530	513	489	466	439	404	374	337	306	280	266	274	270	266	265	268	262	278	296	322	350	
-446	442	438	423	406	387	356	331	304	270	238	213	181	166	153	142	142	154	166	193	213	255	274	301	320	352	392	419	433	447	446	
----Frame 11---
---endo--
-357	390	418	438	470	493	488	458	432	399	376	348	326	305	290	281	285	283	303	329	
-386	393	387	380	336	305	279	248	226	211	210	226	239	267	296	320	348	384	395	405	
---epi--
-379	408	438	463	494	512	532	542	545	539	531	514	488	467	440	405	378	338	306	281	266	275	270	267	265	268	262	278	295	321	349	
-444	441	437	423	405	387	356	331	302	268	237	213	178	166	152	139	139	152	166	192	211	253	273	299	319	351	390	417	432	446	445	
----Frame 12---
---endo--
-358	389	416	435	473	492	488	458	432	400	377	349	327	305	291	282	285	282	303	329	
-387	393	385	377	331	304	279	248	225	209	209	224	238	266	294	317	346	381	393	404	
---epi--
-377	406	436	461	492	511	531	542	543	538	531	514	488	467	440	408	381	339	306	283	268	275	271	267	266	268	261	277	294	320	347	
-442	440	437	422	404	384	355	331	299	263	234	212	179	163	151	139	139	149	162	191	211	251	270	297	316	348	387	415	430	444	442	
----Frame 13---
---endo--
-357	387	415	433	468	491	487	458	431	401	377	349	329	306	292	283	286	282	302	327	
-388	394	384	375	335	303	279	249	226	209	209	224	237	266	293	314	342	378	389	399	
---epi--
-375	405	434	459	490	509	530	541	543	540	532	515	485	467	440	410	381	340	307	284	269	276	271	268	267	269	261	276	294	319	345	
-439	439	435	421	405	386	352	326	299	265	234	213	179	164	150	139	138	149	159	186	210	250	269	295	314	345	384	413	427	442	440	
----Frame 14---
---endo--
-352	383	413	431	463	490	486	457	430	401	377	351	330	307	293	284	288	282	302	327	
-388	392	382	372	334	303	280	249	227	210	209	225	238	266	291	314	337	375	387	398	
---epi--
-373	403	432	457	488	506	529	540	544	540	532	515	484	469	442	407	383	340	308	286	270	277	272	269	267	270	261	276	293	318	344	
-438	438	434	421	405	388	351	327	301	262	231	210	179	160	148	139	140	149	159	183	206	249	268	294	314	341	380	411	426	441	436	
----Frame 15---
---endo--
-351	381	411	429	461	488	481	455	429	405	376	352	330	308	294	285	289	282	302	326	
-392	390	382	373	338	303	276	249	229	212	211	226	240	266	291	313	333	373	386	395	
---epi--
-371	401	431	456	486	504	529	540	543	539	532	515	484	470	442	408	380	340	309	286	272	281	273	270	268	272	261	275	293	318	343	
-436	437	433	421	404	388	346	328	302	260	229	205	174	161	147	140	138	150	161	184	203	244	267	294	313	337	379	409	424	439	432	
----Frame 16---
---endo--
-355	379	409	428	461	488	477	453	428	406	376	352	330	309	297	287	291	282	302	326	
-387	386	380	370	333	307	275	250	230	214	212	228	241	267	289	311	333	372	385	393	
---epi--
-370	399	430	455	484	502	529	539	542	538	533	515	479	469	441	408	381	340	310	289	275	284	273	271	270	273	261	275	293	318	342	
-435	436	432	419	403	388	341	329	302	259	232	204	172	165	147	139	138	150	161	181	200	242	267	294	311	337	378	409	422	438	431	
----Frame 17---
---endo--
-351	378	407	428	458	485	476	452	427	405	375	352	330	310	298	289	292	283	303	326	
-382	385	379	368	332	305	276	251	231	215	214	230	243	267	290	308	333	367	385	393	
---epi--
-369	397	429	453	482	500	527	539	542	538	534	515	474	469	440	408	382	341	310	288	274	285	275	273	272	274	261	276	293	319	341	
-433	435	431	419	402	388	341	330	302	259	236	204	167	166	145	142	141	151	163	183	202	245	270	294	310	338	377	404	420	433	431	
----Frame 18---
---endo--
-348	376	407	426	453	485	476	451	426	405	374	352	330	313	299	291	294	284	304	327	
-377	385	378	369	336	307	278	253	233	215	216	232	245	268	291	308	333	362	383	392	
---epi--
-368	396	426	452	480	497	527	538	542	537	534	515	474	469	438	408	382	341	306	287	275	286	279	275	274	276	262	277	294	319	340	
-431	434	429	416	400	389	341	330	301	259	240	205	169	168	141	142	142	152	165	184	201	245	267	293	309	338	377	404	419	432	431	
----Frame 19---
---endo--
-349	375	405	424	448	483	475	450	425	403	373	352	330	317	302	292	295	285	304	327	
-374	383	375	369	332	308	279	255	234	218	219	233	247	266	291	310	335	357	383	392	
---epi--
-366	394	425	451	480	495	525	538	541	536	533	515	475	467	437	408	380	341	306	287	274	287	282	277	276	278	262	277	294	319	338	
-431	432	427	414	395	388	341	331	300	258	242	206	173	163	142	142	142	151	166	184	201	245	267	292	309	337	377	404	418	432	431	

+ 0 - 1
opencl/heartwall/run

@@ -1 +0,0 @@
-./heartwall 20

+ 0 - 1
opencl/heartwall/run-cpu

@@ -1 +0,0 @@
-./heartwall 20 1 0 0

+ 0 - 1
opencl/heartwall/run-gpu

@@ -1 +0,0 @@
-./heartwall 20 0 0 1

+ 0 - 1839
opencl/heartwall/util/avi/avilib.c

@@ -1,1839 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- *  avilib.c
- *
- *  Copyright (C) Thomas Östreich - June 2001
- *  multiple audio track support Copyright (C) 2002 Thomas Östreich 
- *
- *  Original code:
- *  Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de> 
- *
- *  This file is part of transcode, a linux video stream processing tool
- *      
- *  transcode is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2, or (at your option)
- *  any later version.
- *   
- *  transcode 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 General Public License
- *  along with GNU Make; see the file COPYING.  If not, write to
- *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
- *
- */
-
-#include "avilib.h"
-//#include <time.h>
-
-#define INFO_LIST
-
-/* The following variable indicates the kind of error */
-
-long AVI_errno;
-
-#define MAX_INFO_STRLEN 64
-static char id_str[MAX_INFO_STRLEN];
-
-#define FRAME_RATE_SCALE 1000000
-
-#ifndef PACKAGE
-	#define PACKAGE "my"
-	#define VERSION "0.00"
-#endif
-
-#ifndef O_BINARY
-	/* win32 wants a binary flag to open(); this sets it to null
-	   on platforms that don't have it. */
-	#define O_BINARY 0
-#endif
-
-/*******************************************************************
- *                                                                 *
- *    Utilities for writing an AVI File                            *
- *                                                                 *
- *******************************************************************/
-
-static size_t avi_read(int fd, char *buf, size_t len)
-{
-   size_t n = 0;
-   size_t r = 0;
-
-   while (r < len) {
-      n = read (fd, buf + r, len - r);
-
-      if (n <= 0)
-	  return r;
-      r += n;
-   }
-
-   return r;
-}
-
-static size_t avi_write (int fd, char *buf, size_t len)
-{
-   size_t n = 0;
-   size_t r = 0;
-
-   while (r < len) {
-      n = write (fd, buf + r, len - r);
-      if (n < 0)
-         return n;
-      
-      r += n;
-   }
-   return r;
-}
-
-/* HEADERBYTES: The number of bytes to reserve for the header */
-
-#define HEADERBYTES 2048
-
-/* AVI_MAX_LEN: The maximum length of an AVI file, we stay a bit below
-    the 2GB limit (Remember: 2*10^9 is smaller than 2 GB) */
-
-#define AVI_MAX_LEN (UINT_MAX-(1<<20)*16-HEADERBYTES)
-
-#define PAD_EVEN(x) ( ((x)+1) & ~1 )
-
-
-/* Copy n into dst as a 4 byte, little endian number.
-   Should also work on big endian machines */
-
-static void long2str(unsigned char *dst, int n)
-{
-   dst[0] = (n    )&0xff;
-   dst[1] = (n>> 8)&0xff;
-   dst[2] = (n>>16)&0xff;
-   dst[3] = (n>>24)&0xff;
-}
-
-/* Convert a string of 4 or 2 bytes to a number,
-   also working on big endian machines */
-
-static unsigned long str2ulong(unsigned char *str)
-{
-   return ( str[0] | (str[1]<<8) | (str[2]<<16) | (str[3]<<24) );
-}
-static unsigned long str2ushort(unsigned char *str)
-{
-   return ( str[0] | (str[1]<<8) );
-}
-
-/* Calculate audio sample size from number of bits and number of channels.
-   This may have to be adjusted for eg. 12 bits and stereo */
-
-static int avi_sampsize(avi_t *AVI, int j)
-{
-   int s;
-   s = ((AVI->track[j].a_bits+7)/8)*AVI->track[j].a_chans;
-   //   if(s==0) s=1; /* avoid possible zero divisions */
-   if(s<4) s=4; /* avoid possible zero divisions */ 
-   return s;
-}
-
-/* Add a chunk (=tag and data) to the AVI file,
-   returns -1 on write error, 0 on success */
-
-static int avi_add_chunk(avi_t *AVI, unsigned char *tag, unsigned char *data, int length)
-{
-   unsigned char c[8];
-
-   /* Copy tag and length int c, so that we need only 1 write system call
-      for these two values */
-
-   memcpy(c,tag,4);
-   long2str(c+4,length);
-
-   /* Output tag, length and data, restore previous position
-      if the write fails */
-
-   length = PAD_EVEN(length);
-
-   if( avi_write(AVI->fdes,(char *)c,8) != 8 ||
-       avi_write(AVI->fdes,(char *)data,length) != length )
-   {
-      lseek(AVI->fdes,AVI->pos,SEEK_SET);
-      AVI_errno = AVI_ERR_WRITE;
-      return -1;
-   }
-
-   /* Update file position */
-
-   AVI->pos += 8 + length;
-
-   //fprintf(stderr, "pos=%lu %s\n", AVI->pos, tag);
-
-   return 0;
-}
-
-static int avi_add_index_entry(avi_t *AVI, unsigned char *tag, long flags, unsigned long pos, unsigned long len)
-{
-   void *ptr;
-
-   if(AVI->n_idx>=AVI->max_idx) {
-     ptr = realloc((void *)AVI->idx,(AVI->max_idx+4096)*16);
-     
-     if(ptr == 0) {
-       AVI_errno = AVI_ERR_NO_MEM;
-       return -1;
-     }
-     AVI->max_idx += 4096;
-     AVI->idx = (unsigned char((*)[16]) ) ptr;
-   }
-   
-   /* Add index entry */
-
-   //   fprintf(stderr, "INDEX %s %ld %lu %lu\n", tag, flags, pos, len);
-
-   memcpy(AVI->idx[AVI->n_idx],tag,4);
-   long2str(AVI->idx[AVI->n_idx]+ 4,flags);
-   long2str(AVI->idx[AVI->n_idx]+ 8, pos);
-   long2str(AVI->idx[AVI->n_idx]+12, len);
-   
-   /* Update counter */
-
-   AVI->n_idx++;
-
-   if(len>AVI->max_len) AVI->max_len=len;
-
-   return 0;
-}
-
-/*
-   AVI_open_output_file: Open an AVI File and write a bunch
-                         of zero bytes as space for the header.
-
-   returns a pointer to avi_t on success, a zero pointer on error
-*/
-
-avi_t* AVI_open_output_file(char * filename)
-{
-   avi_t *AVI;
-   int i;
-
-   int mask = 0;
-   
-   unsigned char AVI_header[HEADERBYTES];
-
-   /* Allocate the avi_t struct and zero it */
-
-   AVI = (avi_t *) malloc(sizeof(avi_t));
-   if(AVI==0)
-   {
-      AVI_errno = AVI_ERR_NO_MEM;
-      return 0;
-   }
-   memset((void *)AVI,0,sizeof(avi_t));
-
-   /* Since Linux needs a long time when deleting big files,
-      we do not truncate the file when we open it.
-      Instead it is truncated when the AVI file is closed */
-
-  /* mask = umask (0);
-   umask (mask);*/
-
-   AVI->fdes = open(filename, O_RDWR|O_CREAT|O_BINARY, 0644 &~ mask);
-   if (AVI->fdes < 0)
-   {
-      AVI_errno = AVI_ERR_OPEN;
-      free(AVI);
-      return 0;
-   }
-
-   /* Write out HEADERBYTES bytes, the header will go here
-      when we are finished with writing */
-
-   for (i=0;i<HEADERBYTES;i++) AVI_header[i] = 0;
-   i = avi_write(AVI->fdes,(char *)AVI_header,HEADERBYTES);
-   if (i != HEADERBYTES)
-   {
-      close(AVI->fdes);
-      AVI_errno = AVI_ERR_WRITE;
-      free(AVI);
-      return 0;
-   }
-
-   AVI->pos  = HEADERBYTES;
-   AVI->mode = AVI_MODE_WRITE; /* open for writing */
-
-   //init
-   AVI->anum = 0;
-   AVI->aptr = 0;
-
-   return AVI;
-}
-
-void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor)
-{
-   /* may only be called if file is open for writing */
-
-   if(AVI->mode==AVI_MODE_READ) return;
-
-   AVI->width  = width;
-   AVI->height = height;
-   AVI->fps    = fps;
-   
-   if(strncmp(compressor, "RGB", 3)==0) {
-     memset(AVI->compressor, 0, 4);
-   } else {
-     memcpy(AVI->compressor,compressor,4);
-   }     
-   
-   AVI->compressor[4] = 0;
-
-   avi_update_header(AVI);
-}
-
-void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format, long mp3rate)
-{
-   /* may only be called if file is open for writing */
-
-   if(AVI->mode==AVI_MODE_READ) return;
-
-   //inc audio tracks
-   AVI->aptr=AVI->anum;
-   ++AVI->anum;
-
-   if(AVI->anum > AVI_MAX_TRACKS) {
-     fprintf(stderr, "error - only %d audio tracks supported\n", AVI_MAX_TRACKS);
-     exit(1);
-   }
-
-   AVI->track[AVI->aptr].a_chans = channels;
-   AVI->track[AVI->aptr].a_rate  = rate;
-   AVI->track[AVI->aptr].a_bits  = bits;
-   AVI->track[AVI->aptr].a_fmt   = format;
-   AVI->track[AVI->aptr].mp3rate = mp3rate;
-
-   avi_update_header(AVI);
-}
-
-#define OUT4CC(s) \
-   if(nhb<=HEADERBYTES-4) memcpy(AVI_header+nhb,s,4); nhb += 4
-
-#define OUTLONG(n) \
-   if(nhb<=HEADERBYTES-4) long2str(AVI_header+nhb,n); nhb += 4
-
-#define OUTSHRT(n) \
-   if(nhb<=HEADERBYTES-2) { \
-      AVI_header[nhb  ] = (n   )&0xff; \
-      AVI_header[nhb+1] = (n>>8)&0xff; \
-   } \
-   nhb += 2
-
-
-//ThOe write preliminary AVI file header: 0 frames, max vid/aud size
-int avi_update_header(avi_t *AVI)
-{
-   int njunk, sampsize, hasIndex, ms_per_frame, frate, flag;
-   int movi_len, hdrl_start, strl_start, j;
-   unsigned char AVI_header[HEADERBYTES];
-   long nhb;
-
-   //assume max size
-   movi_len = AVI_MAX_LEN - HEADERBYTES + 4;
-
-   //assume index will be written
-   hasIndex=1;
-
-   if(AVI->fps < 0.001) {
-     frate=0;
-     ms_per_frame=0;
-   } else {
-     frate = (int) (FRAME_RATE_SCALE*AVI->fps + 0.5);
-     ms_per_frame=(int) (1000000/AVI->fps + 0.5);
-   }
-
-   /* Prepare the file header */
-
-   nhb = 0;
-
-   /* The RIFF header */
-
-   OUT4CC ("RIFF");
-   OUTLONG(movi_len);    // assume max size
-   OUT4CC ("AVI ");
-
-   /* Start the header list */
-
-   OUT4CC ("LIST");
-   OUTLONG(0);        /* Length of list in bytes, don't know yet */
-   hdrl_start = nhb;  /* Store start position */
-   OUT4CC ("hdrl");
-
-   /* The main AVI header */
-
-   /* The Flags in AVI File header */
-
-#define AVIF_HASINDEX           0x00000010      /* Index at end of file */
-#define AVIF_MUSTUSEINDEX       0x00000020
-#define AVIF_ISINTERLEAVED      0x00000100
-#define AVIF_TRUSTCKTYPE        0x00000800      /* Use CKType to find key frames */
-#define AVIF_WASCAPTUREFILE     0x00010000
-#define AVIF_COPYRIGHTED        0x00020000
-
-   OUT4CC ("avih");
-   OUTLONG(56);                 /* # of bytes to follow */
-   OUTLONG(ms_per_frame);       /* Microseconds per frame */
-   //ThOe ->0 
-   //   OUTLONG(10000000);           /* MaxBytesPerSec, I hope this will never be used */
-   OUTLONG(0);
-   OUTLONG(0);                  /* PaddingGranularity (whatever that might be) */
-                                /* Other sources call it 'reserved' */
-   flag = AVIF_ISINTERLEAVED;
-   if(hasIndex) flag |= AVIF_HASINDEX;
-   if(hasIndex && AVI->must_use_index) flag |= AVIF_MUSTUSEINDEX;
-   OUTLONG(flag);               /* Flags */
-   OUTLONG(0);                  // no frames yet
-   OUTLONG(0);                  /* InitialFrames */
-
-   OUTLONG(AVI->anum+1);
-
-   OUTLONG(0);                  /* SuggestedBufferSize */
-   OUTLONG(AVI->width);         /* Width */
-   OUTLONG(AVI->height);        /* Height */
-                                /* MS calls the following 'reserved': */
-   OUTLONG(0);                  /* TimeScale:  Unit used to measure time */
-   OUTLONG(0);                  /* DataRate:   Data rate of playback     */
-   OUTLONG(0);                  /* StartTime:  Starting time of AVI data */
-   OUTLONG(0);                  /* DataLength: Size of AVI data chunk    */
-
-
-   /* Start the video stream list ---------------------------------- */
-
-   OUT4CC ("LIST");
-   OUTLONG(0);        /* Length of list in bytes, don't know yet */
-   strl_start = nhb;  /* Store start position */
-   OUT4CC ("strl");
-
-   /* The video stream header */
-
-   OUT4CC ("strh");
-   OUTLONG(56);                 /* # of bytes to follow */
-   OUT4CC ("vids");             /* Type */
-   OUT4CC (AVI->compressor);    /* Handler */
-   OUTLONG(0);                  /* Flags */
-   OUTLONG(0);                  /* Reserved, MS says: wPriority, wLanguage */
-   OUTLONG(0);                  /* InitialFrames */
-   OUTLONG(FRAME_RATE_SCALE);              /* Scale */
-   OUTLONG(frate);              /* Rate: Rate/Scale == samples/second */
-   OUTLONG(0);                  /* Start */
-   OUTLONG(0);                  // no frames yet
-   OUTLONG(0);                  /* SuggestedBufferSize */
-   OUTLONG(-1);                 /* Quality */
-   OUTLONG(0);                  /* SampleSize */
-   OUTLONG(0);                  /* Frame */
-   OUTLONG(0);                  /* Frame */
-   //   OUTLONG(0);                  /* Frame */
-   //OUTLONG(0);                  /* Frame */
-
-   /* The video stream format */
-
-   OUT4CC ("strf");
-   OUTLONG(40);                 /* # of bytes to follow */
-   OUTLONG(40);                 /* Size */
-   OUTLONG(AVI->width);         /* Width */
-   OUTLONG(AVI->height);        /* Height */
-   OUTSHRT(1); OUTSHRT(24);     /* Planes, Count */
-   OUT4CC (AVI->compressor);    /* Compression */
-   // ThOe (*3)
-   OUTLONG(AVI->width*AVI->height*3);  /* SizeImage (in bytes?) */
-   OUTLONG(0);                  /* XPelsPerMeter */
-   OUTLONG(0);                  /* YPelsPerMeter */
-   OUTLONG(0);                  /* ClrUsed: Number of colors used */
-   OUTLONG(0);                  /* ClrImportant: Number of colors important */
-
-   /* Finish stream list, i.e. put number of bytes in the list to proper pos */
-
-   long2str(AVI_header+strl_start-4,nhb-strl_start);
-
-   
-   /* Start the audio stream list ---------------------------------- */
-   
-   for(j=0; j<AVI->anum; ++j) {
-       
-       sampsize = avi_sampsize(AVI, j);
-   
-       OUT4CC ("LIST");
-       OUTLONG(0);        /* Length of list in bytes, don't know yet */
-       strl_start = nhb;  /* Store start position */
-       OUT4CC ("strl");
-       
-       /* The audio stream header */
-       
-       OUT4CC ("strh");
-       OUTLONG(56);            /* # of bytes to follow */
-       OUT4CC ("auds");
-       
-       // -----------
-       // ThOe
-       OUTLONG(0);             /* Format (Optionally) */
-       // -----------
-       
-       OUTLONG(0);             /* Flags */
-       OUTLONG(0);             /* Reserved, MS says: wPriority, wLanguage */
-       OUTLONG(0);             /* InitialFrames */
-       
-       // ThOe /4
-       OUTLONG(sampsize/4);      /* Scale */
-       OUTLONG(1000*AVI->track[j].mp3rate/8);
-       OUTLONG(0);             /* Start */
-       OUTLONG(4*AVI->track[j].audio_bytes/sampsize);   /* Length */
-       OUTLONG(0);             /* SuggestedBufferSize */
-       OUTLONG(-1);            /* Quality */
-       
-       // ThOe /4
-       OUTLONG(sampsize/4);    /* SampleSize */
-       
-       OUTLONG(0);             /* Frame */
-       OUTLONG(0);             /* Frame */
-       //       OUTLONG(0);             /* Frame */
-       //OUTLONG(0);             /* Frame */
-       
-       /* The audio stream format */
-       
-       OUT4CC ("strf");
-       OUTLONG(16);                   /* # of bytes to follow */
-       OUTSHRT(AVI->track[j].a_fmt);           /* Format */
-       OUTSHRT(AVI->track[j].a_chans);         /* Number of channels */
-       OUTLONG(AVI->track[j].a_rate);          /* SamplesPerSec */
-       // ThOe
-       OUTLONG(1000*AVI->track[j].mp3rate/8);
-       //ThOe (/4)
-       
-       OUTSHRT(sampsize/4);           /* BlockAlign */
-       
-       
-       OUTSHRT(AVI->track[j].a_bits);          /* BitsPerSample */
-       
-       /* Finish stream list, i.e. put number of bytes in the list to proper pos */
-       
-       long2str(AVI_header+strl_start-4,nhb-strl_start);
-   }
-   
-   /* Finish header list */
-   
-   long2str(AVI_header+hdrl_start-4,nhb-hdrl_start);
-   
-   
-   /* Calculate the needed amount of junk bytes, output junk */
-   
-   njunk = HEADERBYTES - nhb - 8 - 12;
-   
-   /* Safety first: if njunk <= 0, somebody has played with
-      HEADERBYTES without knowing what (s)he did.
-      This is a fatal error */
-   
-   if(njunk<=0)
-     {
-       fprintf(stderr,"AVI_close_output_file: # of header bytes too small\n");
-       exit(1);
-     }
-   
-   OUT4CC ("JUNK");
-   OUTLONG(njunk);
-   memset(AVI_header+nhb,0,njunk);
-   
-   //11/14/01 added id string 
-
-   if(njunk > strlen(id_str)+8) {
-     sprintf(id_str, "%s-%s", PACKAGE, VERSION);
-     memcpy(AVI_header+nhb, id_str, strlen(id_str));
-   }
-   
-   nhb += njunk;
-
-   /* Start the movi list */
-
-   OUT4CC ("LIST");
-   OUTLONG(movi_len); /* Length of list in bytes */
-   OUT4CC ("movi");
-
-   /* Output the header, truncate the file to the number of bytes
-      actually written, report an error if someting goes wrong */
-
-   if ( lseek(AVI->fdes,0,SEEK_SET)<0 ||
-        avi_write(AVI->fdes,(char *)AVI_header,HEADERBYTES)!=HEADERBYTES ||
-	lseek(AVI->fdes,AVI->pos,SEEK_SET)<0)
-     {
-       AVI_errno = AVI_ERR_CLOSE;
-       return -1;
-     }
-
-   return 0;
-}
-
-/*
-  Write the header of an AVI file and close it.
-  returns 0 on success, -1 on write error.
-*/
-
-static int avi_close_output_file(avi_t *AVI)
-{
-
-   int ret, njunk, sampsize, hasIndex, ms_per_frame, frate, idxerror, flag;
-   unsigned long movi_len;
-   int hdrl_start, strl_start, j;
-   unsigned char AVI_header[HEADERBYTES];
-   long nhb;
-
-#ifdef INFO_LIST
-   long info_len;
-//   time_t calptr;
-#endif
-
-   /* Calculate length of movi list */
-
-   movi_len = AVI->pos - HEADERBYTES + 4;
-
-   /* Try to ouput the index entries. This may fail e.g. if no space
-      is left on device. We will report this as an error, but we still
-      try to write the header correctly (so that the file still may be
-      readable in the most cases */
-
-   idxerror = 0;
-   //   fprintf(stderr, "pos=%lu, index_len=%ld             \n", AVI->pos, AVI->n_idx*16);
-   ret = avi_add_chunk(AVI, (unsigned char *)"idx1", (unsigned char *)((void*)AVI->idx), AVI->n_idx*16);
-   hasIndex = (ret==0);
-   //fprintf(stderr, "pos=%lu, index_len=%d\n", AVI->pos, hasIndex);
-
-   if(ret) {
-     idxerror = 1;
-     AVI_errno = AVI_ERR_WRITE_INDEX;
-   }
-   
-   /* Calculate Microseconds per frame */
-
-   if(AVI->fps < 0.001) {
-     frate=0;
-     ms_per_frame=0;
-   } else {
-     frate = (int) (FRAME_RATE_SCALE*AVI->fps + 0.5);
-     ms_per_frame=(int) (1000000/AVI->fps + 0.5);
-   }
-
-   /* Prepare the file header */
-
-   nhb = 0;
-
-   /* The RIFF header */
-
-   OUT4CC ("RIFF");
-   OUTLONG(AVI->pos - 8);    /* # of bytes to follow */
-   OUT4CC ("AVI ");
-
-   /* Start the header list */
-
-   OUT4CC ("LIST");
-   OUTLONG(0);        /* Length of list in bytes, don't know yet */
-   hdrl_start = nhb;  /* Store start position */
-   OUT4CC ("hdrl");
-
-   /* The main AVI header */
-
-   /* The Flags in AVI File header */
-
-#define AVIF_HASINDEX           0x00000010      /* Index at end of file */
-#define AVIF_MUSTUSEINDEX       0x00000020
-#define AVIF_ISINTERLEAVED      0x00000100
-#define AVIF_TRUSTCKTYPE        0x00000800      /* Use CKType to find key frames */
-#define AVIF_WASCAPTUREFILE     0x00010000
-#define AVIF_COPYRIGHTED        0x00020000
-
-   OUT4CC ("avih");
-   OUTLONG(56);                 /* # of bytes to follow */
-   OUTLONG(ms_per_frame);       /* Microseconds per frame */
-   //ThOe ->0 
-   //   OUTLONG(10000000);           /* MaxBytesPerSec, I hope this will never be used */
-   OUTLONG(0);
-   OUTLONG(0);                  /* PaddingGranularity (whatever that might be) */
-                                /* Other sources call it 'reserved' */
-   flag = AVIF_ISINTERLEAVED;
-   if(hasIndex) flag |= AVIF_HASINDEX;
-   if(hasIndex && AVI->must_use_index) flag |= AVIF_MUSTUSEINDEX;
-   OUTLONG(flag);               /* Flags */
-   OUTLONG(AVI->video_frames);  /* TotalFrames */
-   OUTLONG(0);                  /* InitialFrames */
-
-   OUTLONG(AVI->anum+1);
-//   if (AVI->track[0].audio_bytes)
-//      { OUTLONG(2); }           /* Streams */
-//   else
-//      { OUTLONG(1); }           /* Streams */
-
-   OUTLONG(0);                  /* SuggestedBufferSize */
-   OUTLONG(AVI->width);         /* Width */
-   OUTLONG(AVI->height);        /* Height */
-                                /* MS calls the following 'reserved': */
-   OUTLONG(0);                  /* TimeScale:  Unit used to measure time */
-   OUTLONG(0);                  /* DataRate:   Data rate of playback     */
-   OUTLONG(0);                  /* StartTime:  Starting time of AVI data */
-   OUTLONG(0);                  /* DataLength: Size of AVI data chunk    */
-
-
-   /* Start the video stream list ---------------------------------- */
-
-   OUT4CC ("LIST");
-   OUTLONG(0);        /* Length of list in bytes, don't know yet */
-   strl_start = nhb;  /* Store start position */
-   OUT4CC ("strl");
-
-   /* The video stream header */
-
-   OUT4CC ("strh");
-   OUTLONG(56);                 /* # of bytes to follow */
-   OUT4CC ("vids");             /* Type */
-   OUT4CC (AVI->compressor);    /* Handler */
-   OUTLONG(0);                  /* Flags */
-   OUTLONG(0);                  /* Reserved, MS says: wPriority, wLanguage */
-   OUTLONG(0);                  /* InitialFrames */
-   OUTLONG(FRAME_RATE_SCALE);              /* Scale */
-   OUTLONG(frate);              /* Rate: Rate/Scale == samples/second */
-   OUTLONG(0);                  /* Start */
-   OUTLONG(AVI->video_frames);  /* Length */
-   OUTLONG(0);                  /* SuggestedBufferSize */
-   OUTLONG(-1);                 /* Quality */
-   OUTLONG(0);                  /* SampleSize */
-   OUTLONG(0);                  /* Frame */
-   OUTLONG(0);                  /* Frame */
-   //   OUTLONG(0);                  /* Frame */
-   //OUTLONG(0);                  /* Frame */
-
-   /* The video stream format */
-
-   OUT4CC ("strf");
-   OUTLONG(40);                 /* # of bytes to follow */
-   OUTLONG(40);                 /* Size */
-   OUTLONG(AVI->width);         /* Width */
-   OUTLONG(AVI->height);        /* Height */
-   OUTSHRT(1); OUTSHRT(24);     /* Planes, Count */
-   OUT4CC (AVI->compressor);    /* Compression */
-   // ThOe (*3)
-   OUTLONG(AVI->width*AVI->height*3);  /* SizeImage (in bytes?) */
-   OUTLONG(0);                  /* XPelsPerMeter */
-   OUTLONG(0);                  /* YPelsPerMeter */
-   OUTLONG(0);                  /* ClrUsed: Number of colors used */
-   OUTLONG(0);                  /* ClrImportant: Number of colors important */
-
-   /* Finish stream list, i.e. put number of bytes in the list to proper pos */
-
-   long2str(AVI_header+strl_start-4,nhb-strl_start);
-
-   /* Start the audio stream list ---------------------------------- */
-
-   for(j=0; j<AVI->anum; ++j) {
-     
-     //if (AVI->track[j].a_chans && AVI->track[j].audio_bytes)
-       {
-	   
-	 sampsize = avi_sampsize(AVI, j);
-	   
-	 OUT4CC ("LIST");
-	 OUTLONG(0);        /* Length of list in bytes, don't know yet */
-	 strl_start = nhb;  /* Store start position */
-	 OUT4CC ("strl");
-	   
-	 /* The audio stream header */
-	 
-	 OUT4CC ("strh");
-	 OUTLONG(56);            /* # of bytes to follow */
-	 OUT4CC ("auds");
-	 
-	 // -----------
-	 // ThOe
-	 OUTLONG(0);             /* Format (Optionally) */
-	   // -----------
-	   
-	 OUTLONG(0);             /* Flags */
-	 OUTLONG(0);             /* Reserved, MS says: wPriority, wLanguage */
-	 OUTLONG(0);             /* InitialFrames */
-	   
-	 // ThOe /4
-	 OUTLONG(sampsize/4);      /* Scale */
-	 OUTLONG(1000*AVI->track[j].mp3rate/8);
-	 OUTLONG(0);             /* Start */
-	 OUTLONG(4*AVI->track[j].audio_bytes/sampsize);   /* Length */
-	 OUTLONG(0);             /* SuggestedBufferSize */
-	 OUTLONG(-1);            /* Quality */
-	   
-	 // ThOe /4
-	 OUTLONG(sampsize/4);    /* SampleSize */
-	   
-	 OUTLONG(0);             /* Frame */
-	 OUTLONG(0);             /* Frame */
-	 //	 OUTLONG(0);             /* Frame */
-	 //OUTLONG(0);             /* Frame */
-	   
-	 /* The audio stream format */
-	 
-	 OUT4CC ("strf");
-	 OUTLONG(16);                   /* # of bytes to follow */
-	 OUTSHRT(AVI->track[j].a_fmt);           /* Format */
-	 OUTSHRT(AVI->track[j].a_chans);         /* Number of channels */
-	 OUTLONG(AVI->track[j].a_rate);          /* SamplesPerSec */
-	 // ThOe
-	 OUTLONG(1000*AVI->track[j].mp3rate/8);
-	 //ThOe (/4)
-	 
-	 OUTSHRT(sampsize/4);           /* BlockAlign */
-	 
-	 
-	 OUTSHRT(AVI->track[j].a_bits);          /* BitsPerSample */
-	 
-	 /* Finish stream list, i.e. put number of bytes in the list to proper pos */
-       }
-       long2str(AVI_header+strl_start-4,nhb-strl_start);
-   }
-   
-   /* Finish header list */
-   
-   long2str(AVI_header+hdrl_start-4,nhb-hdrl_start);
-
-
-   // add INFO list --- (0.6.0pre4)
-
-#ifdef INFO_LIST
-   OUT4CC ("LIST");
-   
-   //FIXME
-   info_len = MAX_INFO_STRLEN + 12;
-   OUTLONG(info_len);
-   OUT4CC ("INFO");
-
-//   OUT4CC ("INAM");
-//   OUTLONG(MAX_INFO_STRLEN);
-
-//   sprintf(id_str, "\t");
-//   memset(AVI_header+nhb, 0, MAX_INFO_STRLEN);
-//   memcpy(AVI_header+nhb, id_str, strlen(id_str));
-//   nhb += MAX_INFO_STRLEN;
-
-   OUT4CC ("ISFT");
-   OUTLONG(MAX_INFO_STRLEN);
-
-   sprintf(id_str, "%s-%s", PACKAGE, VERSION);
-   memset(AVI_header+nhb, 0, MAX_INFO_STRLEN);
-   memcpy(AVI_header+nhb, id_str, strlen(id_str));
-   nhb += MAX_INFO_STRLEN;
-
-//   OUT4CC ("ICMT");
-//   OUTLONG(MAX_INFO_STRLEN);
-
-//   calptr=time(NULL); 
-//   sprintf(id_str, "\t%s %s", ctime(&calptr), "");
-//   memset(AVI_header+nhb, 0, MAX_INFO_STRLEN);
-//   memcpy(AVI_header+nhb, id_str, 25);
-//   nhb += MAX_INFO_STRLEN;
-#endif
-
-   // ----------------------------
-   
-   /* Calculate the needed amount of junk bytes, output junk */
-   
-   njunk = HEADERBYTES - nhb - 8 - 12;
-   
-   /* Safety first: if njunk <= 0, somebody has played with
-      HEADERBYTES without knowing what (s)he did.
-      This is a fatal error */
-   
-   if(njunk<=0)
-   {
-      fprintf(stderr,"AVI_close_output_file: # of header bytes too small\n");
-      exit(1);
-   }
-
-   OUT4CC ("JUNK");
-   OUTLONG(njunk);
-   memset(AVI_header+nhb,0,njunk);
-   
-   nhb += njunk;
-
-   /* Start the movi list */
-
-   OUT4CC ("LIST");
-   OUTLONG(movi_len); /* Length of list in bytes */
-   OUT4CC ("movi");
-
-   /* Output the header, truncate the file to the number of bytes
-      actually written, report an error if someting goes wrong */
-
-   if ( lseek(AVI->fdes,0,SEEK_SET)<0 ||
-        avi_write(AVI->fdes,(char *)AVI_header,HEADERBYTES)!=HEADERBYTES 
-        //|| ftruncate(AVI->fdes,AVI->pos)<0 
-        )
-   {
-      AVI_errno = AVI_ERR_CLOSE;
-      return -1;
-   }
-
-   if(idxerror) return -1;
-
-   return 0;
-}
-
-/*
-   AVI_write_data:
-   Add video or audio data to the file;
-
-   Return values:
-    0    No error;
-   -1    Error, AVI_errno is set appropriatly;
-
-*/
-
-static int avi_write_data(avi_t *AVI, char *data, unsigned long length, int audio, int keyframe)
-{
-   int n;
-
-   unsigned char astr[5];
-
-   /* Check for maximum file length */
-   
-   if ( (AVI->pos + 8 + length + 8 + (AVI->n_idx+1)*16) > AVI_MAX_LEN ) {
-     AVI_errno = AVI_ERR_SIZELIM;
-     return -1;
-   }
-   
-   /* Add index entry */
-
-   //set tag for current audio track
-   sprintf((char *)astr, "0%1dwb", AVI->aptr+1);
-
-   if(audio)
-     n = avi_add_index_entry(AVI,astr,0x00,AVI->pos,length);
-   else
-     n = avi_add_index_entry(AVI,(unsigned char *) "00db",((keyframe)?0x10:0x0),AVI->pos,length);
-   
-   if(n) return -1;
-   
-   /* Output tag and data */
-   
-   if(audio)
-     n = avi_add_chunk(AVI,(unsigned char *) astr, (unsigned char *)data,length);
-   else
-     n = avi_add_chunk(AVI,(unsigned char *)"00db",(unsigned char *)data,length);
-   
-   if (n) return -1;
-   
-   return 0;
-}
-
-int AVI_write_frame(avi_t *AVI, char *data, long bytes, int keyframe)
-{
-  unsigned long pos;
-  
-  if(AVI->mode==AVI_MODE_READ) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-  
-  pos = AVI->pos;
-
-  if(avi_write_data(AVI,data,bytes,0,keyframe)) return -1;
-   
-  AVI->last_pos = pos;
-  AVI->last_len = bytes;
-  AVI->video_frames++;
-  return 0;
-}
-
-int AVI_dup_frame(avi_t *AVI)
-{
-   if(AVI->mode==AVI_MODE_READ) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-
-   if(AVI->last_pos==0) return 0; /* No previous real frame */
-   if(avi_add_index_entry(AVI,(unsigned char *)"00db",0x10,AVI->last_pos,AVI->last_len)) return -1;
-   AVI->video_frames++;
-   AVI->must_use_index = 1;
-   return 0;
-}
-
-int AVI_write_audio(avi_t *AVI, char *data, long bytes)
-{
-   if(AVI->mode==AVI_MODE_READ) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-
-   if( avi_write_data(AVI,data,bytes,1,0) ) return -1;
-   AVI->track[AVI->aptr].audio_bytes += bytes;
-   return 0;
-}
-
-
-int AVI_append_audio(avi_t *AVI, char *data, long bytes)
-{
-
-  long i, length, pos;
-  unsigned char c[4];
-
-  if(AVI->mode==AVI_MODE_READ) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-  
-  // update last index entry:
-  
-  --AVI->n_idx;
-  length = str2ulong(AVI->idx[AVI->n_idx]+12);
-  pos    = str2ulong(AVI->idx[AVI->n_idx]+8);
-
-  //update;
-  long2str(AVI->idx[AVI->n_idx]+12,length+bytes);   
-
-  ++AVI->n_idx;
-
-  AVI->track[AVI->aptr].audio_bytes += bytes;
-
-  //update chunk header
-  lseek(AVI->fdes, pos+4, SEEK_SET);
-  long2str(c, length+bytes);     
-  avi_write(AVI->fdes,(char *) c, 4);
-
-  lseek(AVI->fdes, pos+8+length, SEEK_SET);
-
-  i=PAD_EVEN(length + bytes);
-
-  bytes = i - length;
-  avi_write(AVI->fdes, data, bytes);
-  AVI->pos = pos + 8 + i;
-
-  return 0;
-}
-
-
-long AVI_bytes_remain(avi_t *AVI)
-{
-   if(AVI->mode==AVI_MODE_READ) return 0;
-
-   return ( AVI_MAX_LEN - (AVI->pos + 8 + 16*AVI->n_idx));
-}
-
-long AVI_bytes_written(avi_t *AVI)
-{
-   if(AVI->mode==AVI_MODE_READ) return 0;
-
-   return (AVI->pos + 8 + 16*AVI->n_idx);
-}
-
-int AVI_set_audio_track(avi_t *AVI, int track)
-{
-  
-  if(track < 0 || track + 1 > AVI->anum) return(-1);
-
-  //this info is not written to file anyway
-  AVI->aptr=track;
-  return 0;
-}
-
-int AVI_get_audio_track(avi_t *AVI)
-{
-    return(AVI->aptr);
-}
-
-
-/*******************************************************************
- *                                                                 *
- *    Utilities for reading video and audio from an AVI File       *
- *                                                                 *
- *******************************************************************/
-
-int AVI_close(avi_t *AVI)
-{
-   int ret;
-
-   /* If the file was open for writing, the header and index still have
-      to be written */
-
-   if(AVI->mode == AVI_MODE_WRITE)
-      ret = avi_close_output_file(AVI);
-   else
-      ret = 0;
-
-   /* Even if there happened an error, we first clean up */
-
-   close(AVI->fdes);
-   if(AVI->idx) free(AVI->idx);
-   if(AVI->video_index) free(AVI->video_index);
-   //FIXME
-   //if(AVI->audio_index) free(AVI->audio_index);
-   free(AVI);
-
-   return ret;
-}
-
-
-#define ERR_EXIT(x) \
-{ \
-   AVI_close(AVI); \
-   AVI_errno = x; \
-   return 0; \
-}
-
-avi_t *AVI_open_input_file(char *filename, int getIndex)
-{
-  avi_t *AVI=NULL;
-  
-  /* Create avi_t structure */
-  
-  AVI = (avi_t *) malloc(sizeof(avi_t));
-  if(AVI==NULL)
-    {
-      AVI_errno = AVI_ERR_NO_MEM;
-      return 0;
-    }
-  memset((void *)AVI,0,sizeof(avi_t));
-  
-  AVI->mode = AVI_MODE_READ; /* open for reading */
-  
-  /* Open the file */
-  
-  AVI->fdes = open(filename,O_RDONLY|O_BINARY);
-  if(AVI->fdes < 0)
-    {
-      AVI_errno = AVI_ERR_OPEN;
-      free(AVI);
-      return 0;
-    }
-  
-  avi_parse_input_file(AVI, getIndex);
-
-  AVI->aptr=0; //reset  
-
-  return AVI;
-}
-
-avi_t *AVI_open_fd(int fd, int getIndex)
-{
-  avi_t *AVI=NULL;
-  
-  /* Create avi_t structure */
-  
-  AVI = (avi_t *) malloc(sizeof(avi_t));
-  if(AVI==NULL)
-    {
-      AVI_errno = AVI_ERR_NO_MEM;
-      return 0;
-    }
-  memset((void *)AVI,0,sizeof(avi_t));
-  
-  AVI->mode = AVI_MODE_READ; /* open for reading */
-  
-  // file alread open
-  AVI->fdes = fd;
-  
-  avi_parse_input_file(AVI, getIndex);
-
-  AVI->aptr=0; //reset
-  
-  return AVI;
-}
-
-int avi_parse_input_file(avi_t *AVI, int getIndex)
-{
-  long i, n, rate, scale, idx_type;
-  unsigned char *hdrl_data;
-  long header_offset=0, hdrl_len=0;
-  long nvi, nai[AVI_MAX_TRACKS], ioff;
-  long tot[AVI_MAX_TRACKS];
-  int j;
-  int lasttag = 0;
-  int vids_strh_seen = 0;
-  int vids_strf_seen = 0;
-  int auds_strh_seen = 0;
-  //  int auds_strf_seen = 0;
-  int num_stream = 0;
-  char data[256];
-  
-  /* Read first 12 bytes and check that this is an AVI file */
-
-   if( avi_read(AVI->fdes,data,12) != 12 ) ERR_EXIT(AVI_ERR_READ)
-
-   if( strncasecmp(data  ,"RIFF",4) !=0 ||
-       strncasecmp(data+8,"AVI ",4) !=0 ) ERR_EXIT(AVI_ERR_NO_AVI)
-
-   /* Go through the AVI file and extract the header list,
-      the start position of the 'movi' list and an optionally
-      present idx1 tag */
-
-   hdrl_data = 0;
-
-   while(1)
-   {
-      if( avi_read(AVI->fdes,data,8) != 8 ) break; /* We assume it's EOF */
-
-      n = str2ulong((unsigned char *) data+4);
-      n = PAD_EVEN(n);
-
-      if(strncasecmp(data,"LIST",4) == 0)
-      {
-         if( avi_read(AVI->fdes,data,4) != 4 ) ERR_EXIT(AVI_ERR_READ)
-         n -= 4;
-         if(strncasecmp(data,"hdrl",4) == 0)
-         {
-            hdrl_len = n;
-            hdrl_data = (unsigned char *) malloc(n);
-            if(hdrl_data==0) ERR_EXIT(AVI_ERR_NO_MEM);
-				 
-	    // offset of header
-	    
-	    header_offset = lseek(AVI->fdes,0,SEEK_CUR);
-				 
-            if( avi_read(AVI->fdes,(char *)hdrl_data,n) != n ) ERR_EXIT(AVI_ERR_READ)
-         }
-         else if(strncasecmp(data,"movi",4) == 0)
-         {
-            AVI->movi_start = lseek(AVI->fdes,0,SEEK_CUR);
-            lseek(AVI->fdes,n,SEEK_CUR);
-         }
-         else
-            lseek(AVI->fdes,n,SEEK_CUR);
-      }
-      else if(strncasecmp(data,"idx1",4) == 0)
-      {
-         /* n must be a multiple of 16, but the reading does not
-            break if this is not the case */
-
-         AVI->n_idx = AVI->max_idx = n/16;
-         AVI->idx = (unsigned  char((*)[16]) ) malloc(n);
-         if(AVI->idx==0) ERR_EXIT(AVI_ERR_NO_MEM)
-         if(avi_read(AVI->fdes, (char *) AVI->idx, n) != n ) ERR_EXIT(AVI_ERR_READ)
-      }
-      else
-         lseek(AVI->fdes,n,SEEK_CUR);
-   }
-
-   if(!hdrl_data      ) ERR_EXIT(AVI_ERR_NO_HDRL)
-   if(!AVI->movi_start) ERR_EXIT(AVI_ERR_NO_MOVI)
-
-   /* Interpret the header list */
-
-   for(i=0;i<hdrl_len;)
-   {
-      /* List tags are completly ignored */
-
-      if(strncasecmp((char *) hdrl_data+i, "LIST",4)==0) { i+= 12; continue; }
-
-      n = str2ulong(hdrl_data+i+4);
-      n = PAD_EVEN(n);
-
-      /* Interpret the tag and its args */
-
-      if(strncasecmp((char *)hdrl_data+i,"strh",4)==0)
-      {
-         i += 8;
-         if(strncasecmp((char *)hdrl_data+i,"vids",4) == 0 && !vids_strh_seen)
-         {
-            memcpy(AVI->compressor,hdrl_data+i+4,4);
-            AVI->compressor[4] = 0;
-
-	    // ThOe
-	    AVI->v_codech_off = header_offset + i+4;
-
-            scale = str2ulong((unsigned char *)hdrl_data+i+20);
-            rate  = str2ulong(hdrl_data+i+24);
-            if(scale!=0) AVI->fps = (double)rate/(double)scale;
-            AVI->video_frames = str2ulong(hdrl_data+i+32);
-            AVI->video_strn = num_stream;
-	    AVI->max_len = 0;
-            vids_strh_seen = 1;
-            lasttag = 1; /* vids */
-         }
-         else if (strncasecmp ((char *) hdrl_data+i,"auds",4) ==0 && ! auds_strh_seen)
-         {
-
-	   //inc audio tracks
-	   AVI->aptr=AVI->anum;
-	   ++AVI->anum;
-	   
-	   if(AVI->anum > AVI_MAX_TRACKS) {
-	     fprintf(stderr, "error - only %d audio tracks supported\n", AVI_MAX_TRACKS);
-	     return(-1);
-	   }
-	   
-	   AVI->track[AVI->aptr].audio_bytes = str2ulong(hdrl_data+i+32)*avi_sampsize(AVI, 0);
-	   AVI->track[AVI->aptr].audio_strn = num_stream;
-	   //	   auds_strh_seen = 1;
-	   lasttag = 2; /* auds */
-	   
-	   // ThOe
-	   AVI->track[AVI->aptr].a_codech_off = header_offset + i;
-	   
-         }
-         else
-            lasttag = 0;
-         num_stream++;
-      }
-      else if(strncasecmp((char *) hdrl_data+i,"strf",4)==0)
-      {
-         i += 8;
-         if(lasttag == 1)
-         {
-            AVI->width  = str2ulong(hdrl_data+i+4);
-            AVI->height = str2ulong(hdrl_data+i+8);
-            vids_strf_seen = 1;
-	    //ThOe
-	    AVI->v_codecf_off = header_offset + i+16;
-
-	    memcpy(AVI->compressor2, hdrl_data+i+16, 4);
-            AVI->compressor2[4] = 0;
-
-         }
-         else if(lasttag == 2)
-         {
-            AVI->track[AVI->aptr].a_fmt   = str2ushort(hdrl_data+i  );
-
-	    //ThOe
-	    AVI->track[AVI->aptr].a_codecf_off = header_offset + i;
-	    
-            AVI->track[AVI->aptr].a_chans = str2ushort(hdrl_data+i+2);
-            AVI->track[AVI->aptr].a_rate  = str2ulong (hdrl_data+i+4);
-	    //ThOe: read mp3bitrate
-	    AVI->track[AVI->aptr].mp3rate = 8*str2ulong(hdrl_data+i+8)/1000;
-	    //:ThOe
-            AVI->track[AVI->aptr].a_bits  = str2ushort(hdrl_data+i+14);
-	    //            auds_strf_seen = 1;
-         }
-         lasttag = 0;
-      }
-      else
-      {
-         i += 8;
-         lasttag = 0;
-      }
-
-      i += n;
-   }
-
-   free(hdrl_data);
-
-   if(!vids_strh_seen || !vids_strf_seen) ERR_EXIT(AVI_ERR_NO_VIDS)
-
-   AVI->video_tag[0] = AVI->video_strn/10 + '0';
-   AVI->video_tag[1] = AVI->video_strn%10 + '0';
-   AVI->video_tag[2] = 'd';
-   AVI->video_tag[3] = 'b';
-
-   /* Audio tag is set to "99wb" if no audio present */
-   if(!AVI->track[0].a_chans) AVI->track[0].audio_strn = 99;
-
-   for(j=0; j<AVI->anum; ++j) {
-     AVI->track[j].audio_tag[0] = (j+1)/10 + '0';
-     AVI->track[j].audio_tag[1] = (j+1)%10 + '0';
-     AVI->track[j].audio_tag[2] = 'w';
-     AVI->track[j].audio_tag[3] = 'b';
-   }
-
-   lseek(AVI->fdes,AVI->movi_start,SEEK_SET);
-
-   /* get index if wanted */
-
-   if(!getIndex) return(0);
-
-   /* if the file has an idx1, check if this is relative
-      to the start of the file or to the start of the movi list */
-
-   idx_type = 0;
-
-   if(AVI->idx)
-   {
-      long pos, len;
-
-      /* Search the first videoframe in the idx1 and look where
-         it is in the file */
-
-      for(i=0;i<AVI->n_idx;i++)
-         if( strncasecmp((char *) AVI->idx[i],(char *) AVI->video_tag,3)==0 ) break;
-      if(i>=AVI->n_idx) ERR_EXIT(AVI_ERR_NO_VIDS)
-
-      pos = str2ulong(AVI->idx[i]+ 8);
-      len = str2ulong(AVI->idx[i]+12);
-
-      lseek(AVI->fdes,pos,SEEK_SET);
-      if(avi_read(AVI->fdes,data,8)!=8) ERR_EXIT(AVI_ERR_READ)
-      if( strncasecmp((char *)data,(char *)AVI->idx[i],4)==0 && 
-      str2ulong((unsigned char *)data+4)==len )
-      {
-         idx_type = 1; /* Index from start of file */
-      }
-      else
-      {
-         lseek(AVI->fdes,pos+AVI->movi_start-4,SEEK_SET);
-         if(avi_read(AVI->fdes,data,8)!=8) ERR_EXIT(AVI_ERR_READ)
-         if( strncasecmp((char *)data,(char *)AVI->idx[i],4)==0 && str2ulong((unsigned char *)data+4)==len )
-         {
-            idx_type = 2; /* Index from start of movi list */
-         }
-      }
-      /* idx_type remains 0 if neither of the two tests above succeeds */
-   }
-
-   if(idx_type == 0)
-   {
-      /* we must search through the file to get the index */
-
-      lseek(AVI->fdes, AVI->movi_start, SEEK_SET);
-
-      AVI->n_idx = 0;
-
-      while(1)
-      {
-         if( avi_read(AVI->fdes,data,8) != 8 ) break;
-         n = str2ulong((unsigned char *)data+4);
-
-         /* The movi list may contain sub-lists, ignore them */
-
-         if(strncasecmp(data,"LIST",4)==0)
-         {
-            lseek(AVI->fdes,4,SEEK_CUR);
-            continue;
-         }
-
-         /* Check if we got a tag ##db, ##dc or ##wb */
-	 
-         if( ( (data[2]=='d' || data[2]=='D') &&
-               (data[3]=='b' || data[3]=='B' || data[3]=='c' || data[3]=='C') )
-	     || ( (data[2]=='w' || data[2]=='W') &&
-		  (data[3]=='b' || data[3]=='B') ) )
-	   {
-	   avi_add_index_entry(AVI,(unsigned char *) data,0,lseek(AVI->fdes,0,SEEK_CUR)-8,n);
-         }
-	 
-         lseek(AVI->fdes,PAD_EVEN(n),SEEK_CUR);
-      }
-      idx_type = 1;
-   }
-
-   /* Now generate the video index and audio index arrays */
-
-   nvi = 0;
-   for(j=0; j<AVI->anum; ++j) nai[j] = 0;
-
-   for(i=0;i<AVI->n_idx;i++) {
-     
-     if(strncasecmp((char *)AVI->idx[i],(char *) AVI->video_tag,3) == 0) nvi++;
-     
-     for(j=0; j<AVI->anum; ++j) if(strncasecmp((char *)AVI->idx[i], AVI->track[j].audio_tag,4) == 0) nai[j]++;
-   }
-   
-   AVI->video_frames = nvi;
-   for(j=0; j<AVI->anum; ++j) AVI->track[j].audio_chunks = nai[j];
-
-//   fprintf(stderr, "chunks = %ld %d %s\n", AVI->track[0].audio_chunks, AVI->anum, AVI->track[0].audio_tag);
-
-   if(AVI->video_frames==0) ERR_EXIT(AVI_ERR_NO_VIDS);
-   AVI->video_index = (video_index_entry *) malloc(nvi*sizeof(video_index_entry));
-   if(AVI->video_index==0) ERR_EXIT(AVI_ERR_NO_MEM);
-   
-   for(j=0; j<AVI->anum; ++j) {
-       if(AVI->track[j].audio_chunks) {
-	   AVI->track[j].audio_index = (audio_index_entry *) malloc(nai[j]*sizeof(audio_index_entry));
-	   if(AVI->track[j].audio_index==0) ERR_EXIT(AVI_ERR_NO_MEM);
-       }
-   }   
-   
-   nvi = 0;
-   for(j=0; j<AVI->anum; ++j) nai[j] = tot[j] = 0;
-   
-   ioff = idx_type == 1 ? 8 : AVI->movi_start+4;
-   
-   for(i=0;i<AVI->n_idx;i++) {
-
-     //video
-     if(strncasecmp((char *)AVI->idx[i],(char *)AVI->video_tag,3) == 0) {
-       AVI->video_index[nvi].key = str2ulong(AVI->idx[i]+ 4);
-       AVI->video_index[nvi].pos = str2ulong(AVI->idx[i]+ 8)+ioff;
-       AVI->video_index[nvi].len = str2ulong(AVI->idx[i]+12);
-       nvi++;
-     }
-     
-     //audio
-     for(j=0; j<AVI->anum; ++j) {
-	 
-       if(strncasecmp((char *)AVI->idx[i],AVI->track[j].audio_tag,4) == 0) {
-	 AVI->track[j].audio_index[nai[j]].pos = str2ulong(AVI->idx[i]+ 8)+ioff;
-	 AVI->track[j].audio_index[nai[j]].len = str2ulong(AVI->idx[i]+12);
-	 AVI->track[j].audio_index[nai[j]].tot = tot[j];
-	 tot[j] += AVI->track[j].audio_index[nai[j]].len;
-	 nai[j]++;
-       }
-     }
-   }
-   
-   
-   for(j=0; j<AVI->anum; ++j) AVI->track[j].audio_bytes = tot[j];
-   
-   /* Reposition the file */
-   
-   lseek(AVI->fdes,AVI->movi_start,SEEK_SET);
-   AVI->video_pos = 0;
-
-   return(0);
-}
-
-long AVI_video_frames(avi_t *AVI)
-{
-   return AVI->video_frames;
-}
-int  AVI_video_width(avi_t *AVI)
-{
-   return AVI->width;
-}
-int  AVI_video_height(avi_t *AVI)
-{
-   return AVI->height;
-}
-double AVI_frame_rate(avi_t *AVI)
-{
-   return AVI->fps;
-}
-char* AVI_video_compressor(avi_t *AVI)
-{
-   return AVI->compressor2;
-}
-
-long AVI_max_video_chunk(avi_t *AVI)
-{
-   return AVI->max_len; 
-}
-
-int AVI_audio_tracks(avi_t *AVI)
-{
-    return(AVI->anum);
-}
-
-int AVI_audio_channels(avi_t *AVI)
-{
-   return AVI->track[AVI->aptr].a_chans;
-}
-
-long AVI_audio_mp3rate(avi_t *AVI)
-{
-   return AVI->track[AVI->aptr].mp3rate;
-}
-
-int AVI_audio_bits(avi_t *AVI)
-{
-   return AVI->track[AVI->aptr].a_bits;
-}
-
-int AVI_audio_format(avi_t *AVI)
-{
-   return AVI->track[AVI->aptr].a_fmt;
-}
-
-long AVI_audio_rate(avi_t *AVI)
-{
-   return AVI->track[AVI->aptr].a_rate;
-}
-
-long AVI_audio_bytes(avi_t *AVI)
-{
-   return AVI->track[AVI->aptr].audio_bytes;
-}
-
-long AVI_audio_chunks(avi_t *AVI)
-{
-   return AVI->track[AVI->aptr].audio_chunks;
-}
-
-long AVI_audio_codech_offset(avi_t *AVI)
-{
-   return AVI->track[AVI->aptr].a_codech_off;
-}
-
-long AVI_audio_codecf_offset(avi_t *AVI)
-{
-   return AVI->track[AVI->aptr].a_codecf_off;
-}
-
-long  AVI_video_codech_offset(avi_t *AVI)
-{
-    return AVI->v_codech_off;
-}
-
-long  AVI_video_codecf_offset(avi_t *AVI)
-{
-    return AVI->v_codecf_off;
-}
-
-long AVI_frame_size(avi_t *AVI, long frame)
-{
-   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-   if(!AVI->video_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }
-
-   if(frame < 0 || frame >= AVI->video_frames) return 0;
-   return(AVI->video_index[frame].len);
-}
-
-long AVI_audio_size(avi_t *AVI, long frame)
-{
-  if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-  if(!AVI->track[AVI->aptr].audio_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }
-  
-  if(frame < 0 || frame >= AVI->track[AVI->aptr].audio_chunks) return 0;
-  return(AVI->track[AVI->aptr].audio_index[frame].len);
-}
-
-long AVI_get_video_position(avi_t *AVI, long frame)
-{
-   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-   if(!AVI->video_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }
-
-   if(frame < 0 || frame >= AVI->video_frames) return 0;
-   return(AVI->video_index[frame].pos);
-}
-
-
-int AVI_seek_start(avi_t *AVI)
-{
-   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-
-   lseek(AVI->fdes,AVI->movi_start,SEEK_SET);
-   AVI->video_pos = 0;
-   return 0;
-}
-
-int AVI_set_video_position(avi_t *AVI, long frame)
-{
-   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-   if(!AVI->video_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }
-
-   if (frame < 0 ) frame = 0;
-   AVI->video_pos = frame;
-   return 0;
-}
-
-int AVI_set_audio_bitrate(avi_t *AVI, long bitrate)
-{
-   if(AVI->mode==AVI_MODE_READ) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-
-   AVI->track[AVI->aptr].mp3rate = bitrate;
-   return 0;
-}
-      
-
-long AVI_read_frame(avi_t *AVI, char *vidbuf, int *keyframe)
-{
-   long n;
-   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-   if(!AVI->video_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }
-   if(AVI->video_pos < 0 || AVI->video_pos >= AVI->video_frames) return -1;
-   n = AVI->video_index[AVI->video_pos].len;
-   *keyframe = (AVI->video_index[AVI->video_pos].key==0x10) ? 1:0;
-   lseek(AVI->fdes, AVI->video_index[AVI->video_pos].pos, SEEK_SET);
-   if (avi_read(AVI->fdes,vidbuf,n) != n)
-   {
-      AVI_errno = AVI_ERR_READ;
-      return -1;
-   }
-   AVI->video_pos++;
-   return n;
-}
-
-int AVI_set_audio_position(avi_t *AVI, long byte)
-{
-   long n0, n1, n;
-
-   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-   if(!AVI->track[AVI->aptr].audio_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }
-
-   if(byte < 0) byte = 0;
-
-   /* Binary search in the audio chunks */
-
-   n0 = 0;
-   n1 = AVI->track[AVI->aptr].audio_chunks;
-
-   while(n0<n1-1)
-   {
-      n = (n0+n1)/2;
-      if(AVI->track[AVI->aptr].audio_index[n].tot>byte)
-         n1 = n;
-      else
-         n0 = n;
-   }
-
-   AVI->track[AVI->aptr].audio_posc = n0;
-   AVI->track[AVI->aptr].audio_posb = byte - AVI->track[AVI->aptr].audio_index[n0].tot;
-
-   return 0;
-}
-
-long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes)
-{
-   long nr, pos, left, todo;
-
-   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
-   if(!AVI->track[AVI->aptr].audio_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }
-
-   nr = 0; /* total number of bytes read */
-
-   while(bytes>0)
-   {
-      left = AVI->track[AVI->aptr].audio_index[AVI->track[AVI->aptr].audio_posc].len - AVI->track[AVI->aptr].audio_posb;
-      if(left==0)
-      {
-         if(AVI->track[AVI->aptr].audio_posc>=AVI->track[AVI->aptr].audio_chunks-1) return nr;
-         AVI->track[AVI->aptr].audio_posc++;
-         AVI->track[AVI->aptr].audio_posb = 0;
-         continue;
-      }
-      if(bytes<left)
-         todo = bytes;
-      else
-         todo = left;
-      pos = AVI->track[AVI->aptr].audio_index[AVI->track[AVI->aptr].audio_posc].pos + AVI->track[AVI->aptr].audio_posb;
-      lseek(AVI->fdes, pos, SEEK_SET);
-      if (avi_read(AVI->fdes,audbuf+nr,todo) != todo)
-      {
-         AVI_errno = AVI_ERR_READ;
-         return -1;
-      }
-      bytes -= todo;
-      nr    += todo;
-      AVI->track[AVI->aptr].audio_posb += todo;
-   }
-
-   return nr;
-}
-
-/* AVI_read_data: Special routine for reading the next audio or video chunk
-                  without having an index of the file. */
-
-int AVI_read_data(avi_t *AVI, char *vidbuf, long max_vidbuf,
-                              char *audbuf, long max_audbuf,
-                              long *len)
-{
-
-/*
- * Return codes:
- *
- *    1 = video data read
- *    2 = audio data read
- *    0 = reached EOF
- *   -1 = video buffer too small
- *   -2 = audio buffer too small
- */
-
-   int n;
-   char data[8];
- 
-   if(AVI->mode==AVI_MODE_WRITE) return 0;
-
-   while(1)
-   {
-      /* Read tag and length */
-
-      if( avi_read(AVI->fdes,data,8) != 8 ) return 0;
-
-      /* if we got a list tag, ignore it */
-
-      if(strncasecmp(data,"LIST",4) == 0)
-      {
-         lseek(AVI->fdes,4,SEEK_CUR);
-         continue;
-      }
-
-      n = PAD_EVEN(str2ulong((unsigned char *)data+4));
-
-      if(strncasecmp(data,AVI->video_tag,3) == 0)
-      {
-         *len = n;
-         AVI->video_pos++;
-         if(n>max_vidbuf)
-         {
-            lseek(AVI->fdes,n,SEEK_CUR);
-            return -1;
-         }
-         if(avi_read(AVI->fdes,vidbuf,n) != n ) return 0;
-         return 1;
-      }
-      else if(strncasecmp(data,AVI->track[AVI->aptr].audio_tag,4) == 0)
-      {
-         *len = n;
-         if(n>max_audbuf)
-         {
-            lseek(AVI->fdes,n,SEEK_CUR);
-            return -2;
-         }
-         if(avi_read(AVI->fdes,audbuf,n) != n ) return 0;
-         return 2;
-         break;
-      }
-      else
-         if(lseek(AVI->fdes,n,SEEK_CUR)<0)  return 0;
-   }
-}
-
-/* AVI_print_error: Print most recent error (similar to perror) */
-
-char *(avi_errors[]) =
-{
-  /*  0 */ (char *) "avilib - No Error",
-  /*  1 */ (char *) "avilib - AVI file size limit reached",
-  /*  2 */ (char *) "avilib - Error opening AVI file",
-  /*  3 */ (char *) "avilib - Error reading from AVI file",
-  /*  4 */ (char *) "avilib - Error writing to AVI file",
-  /*  5 */ (char *) "avilib - Error writing index (file may still be useable)",
-  /*  6 */ (char *) "avilib - Error closing AVI file",
-  /*  7 */ (char *) "avilib - Operation (read/write) not permitted",
-  /*  8 */ (char *) "avilib - Out of memory (malloc failed)",
-  /*  9 */ (char *) "avilib - Not an AVI file",
-  /* 10 */ (char *) "avilib - AVI file has no header list (corrupted?)",
-  /* 11 */ (char *) "avilib - AVI file has no MOVI list (corrupted?)",
-  /* 12 */ (char *) "avilib - AVI file has no video data",
-  /* 13 */ (char *) "avilib - operation needs an index",
-  /* 14 */ (char *) "avilib - Unkown Error"
-};
-static int num_avi_errors = sizeof(avi_errors)/sizeof(char*);
-
-static char error_string[4096];
-
-void AVI_print_error(char *str)
-{
-   int aerrno;
-
-   aerrno = (AVI_errno>=0 && AVI_errno<num_avi_errors) ? AVI_errno : num_avi_errors-1;
-
-   fprintf(stderr,"%s: %s\n",str,avi_errors[aerrno]);
-
-   /* for the following errors, perror should report a more detailed reason: */
-
-   if(AVI_errno == AVI_ERR_OPEN ||
-      AVI_errno == AVI_ERR_READ ||
-      AVI_errno == AVI_ERR_WRITE ||
-      AVI_errno == AVI_ERR_WRITE_INDEX ||
-      AVI_errno == AVI_ERR_CLOSE )
-   {
-      perror("REASON");
-   }
-}
-
-char *AVI_strerror()
-{
-   int aerrno;
-
-   aerrno = (AVI_errno>=0 && AVI_errno<num_avi_errors) ? AVI_errno : num_avi_errors-1;
-
-   if(AVI_errno == AVI_ERR_OPEN ||
-      AVI_errno == AVI_ERR_READ ||
-      AVI_errno == AVI_ERR_WRITE ||
-      AVI_errno == AVI_ERR_WRITE_INDEX ||
-      AVI_errno == AVI_ERR_CLOSE )
-   {
-      sprintf(error_string,"%s - %s",avi_errors[aerrno],strerror(errno));
-      return error_string;
-   }
-   else
-   {
-      return avi_errors[aerrno];
-   }
-}
-
-uint64_t AVI_max_size()
-{
-  return((uint64_t) AVI_MAX_LEN);
-}
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 325
opencl/heartwall/util/avi/avilib.h

@@ -1,325 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//========================================================================================================================================================================================================200
-//
-//========================================================================================================================================================================================================200
-
-/*
- *  avilib.h
- *
- *  Copyright (C) Thomas Östreich - June 2001
- *  multiple audio track support Copyright (C) 2002 Thomas Östreich
- *
- *  Original code:
- *  Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de> 
- *
- *  This file is part of transcode, a linux video stream processing tool
- *      
- *  transcode is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2, or (at your option)
- *  any later version.
- *   
- *  transcode 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 General Public License
- *  along with GNU Make; see the file COPYING.  If not, write to
- *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
- *
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-// #include <windows.h>
-#include <inttypes.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#ifndef AVILIB_H
-	#define AVILIB_H
-
-	#define AVI_MAX_TRACKS 8
-
-	typedef struct
-	{
-	  unsigned long key;
-	  unsigned long pos;
-	  unsigned long len;
-	} video_index_entry;
-
-	typedef struct
-	{
-	   unsigned long pos;
-	   unsigned long len;
-	   unsigned long tot;
-	} audio_index_entry;
-
-	typedef struct track_s
-	{
-
-		long   a_fmt;             /* Audio format, see #defines below */
-		long   a_chans;           /* Audio channels, 0 for no audio */
-		long   a_rate;            /* Rate in Hz */
-		long   a_bits;            /* bits per audio sample */
-		long   mp3rate;           /* mp3 bitrate kbs*/
-
-		long   audio_strn;        /* Audio stream number */
-		long   audio_bytes;       /* Total number of bytes of audio data */
-		long   audio_chunks;      /* Chunks of audio data in the file */
-
-		char   audio_tag[4];      /* Tag of audio data */
-		long   audio_posc;        /* Audio position: chunk */
-		long   audio_posb;        /* Audio position: byte within chunk */
-	 
-		long  a_codech_off;       /* absolut offset of audio codec information */ 
-		long  a_codecf_off;       /* absolut offset of audio codec information */ 
-
-		audio_index_entry *audio_index;
-
-	} track_t;
-
-	typedef struct
-	{
-	  
-	  long   fdes;              /* File descriptor of AVI file */
-	  long   mode;              /* 0 for reading, 1 for writing */
-	  
-	  long   width;             /* Width  of a video frame */
-	  long   height;            /* Height of a video frame */
-	  double fps;               /* Frames per second */
-	  char   compressor[8];     /* Type of compressor, 4 bytes + padding for 0 byte */
-	  char   compressor2[8];     /* Type of compressor, 4 bytes + padding for 0 byte */
-	  long   video_strn;        /* Video stream number */
-	  long   video_frames;      /* Number of video frames */
-	  char   video_tag[4];      /* Tag of video data */
-	  long   video_pos;         /* Number of next frame to be read
-					   (if index present) */
-	  
-	  unsigned long max_len;    /* maximum video chunk present */
-	  
-	  track_t track[AVI_MAX_TRACKS];  // up to AVI_MAX_TRACKS audio tracks supported
-	  
-	  unsigned long pos;        /* position in file */
-	  long   n_idx;             /* number of index entries actually filled */
-	  long   max_idx;           /* number of index entries actually allocated */
-	  
-	  long  v_codech_off;       /* absolut offset of video codec (strh) info */ 
-	  long  v_codecf_off;       /* absolut offset of video codec (strf) info */ 
-	  
-	  unsigned char (*idx)[16]; /* index entries (AVI idx1 tag) */
-	  video_index_entry *video_index;
-	  
-	  unsigned long last_pos;          /* Position of last frame written */
-	  unsigned long last_len;          /* Length of last frame written */
-	  int must_use_index;              /* Flag if frames are duplicated */
-	  unsigned long   movi_start;
-	  
-	  int anum;            // total number of audio tracks 
-	  int aptr;            // current audio working track 
-	  
-	} avi_t;
-
-	#define AVI_MODE_WRITE  0
-	#define AVI_MODE_READ   1
-
-	/* The error codes delivered by avi_open_input_file */
-
-	#define AVI_ERR_SIZELIM      1     /* The write of the data would exceed
-										  the maximum size of the AVI file.
-										  This is more a warning than an error
-										  since the file may be closed safely */
-
-	#define AVI_ERR_OPEN         2     /* Error opening the AVI file - wrong path
-										  name or file nor readable/writable */
-
-	#define AVI_ERR_READ         3     /* Error reading from AVI File */
-
-	#define AVI_ERR_WRITE        4     /* Error writing to AVI File,
-										  disk full ??? */
-
-	#define AVI_ERR_WRITE_INDEX  5     /* Could not write index to AVI file
-										  during close, file may still be
-										  usable */
-
-	#define AVI_ERR_CLOSE        6     /* Could not write header to AVI file
-										  or not truncate the file during close,
-										  file is most probably corrupted */
-
-	#define AVI_ERR_NOT_PERM     7     /* Operation not permitted:
-										  trying to read from a file open
-										  for writing or vice versa */
-
-	#define AVI_ERR_NO_MEM       8     /* malloc failed */
-
-	#define AVI_ERR_NO_AVI       9     /* Not an AVI file */
-
-	#define AVI_ERR_NO_HDRL     10     /* AVI file has no has no header list,
-										  corrupted ??? */
-
-	#define AVI_ERR_NO_MOVI     11     /* AVI file has no has no MOVI list,
-										  corrupted ??? */
-
-	#define AVI_ERR_NO_VIDS     12     /* AVI file contains no video data */
-
-	#define AVI_ERR_NO_IDX      13     /* The file has been opened with
-										  getIndex==0, but an operation has been
-										  performed that needs an index */
-
-	/* Possible Audio formats */
-
-	#ifndef WAVE_FORMAT_PCM
-		#define WAVE_FORMAT_UNKNOWN             (0x0000)
-		#define WAVE_FORMAT_PCM                 (0x0001)
-		#define WAVE_FORMAT_ADPCM               (0x0002)
-		#define WAVE_FORMAT_IBM_CVSD            (0x0005)
-		#define WAVE_FORMAT_ALAW                (0x0006)
-		#define WAVE_FORMAT_MULAW               (0x0007)
-		#define WAVE_FORMAT_OKI_ADPCM           (0x0010)
-		#define WAVE_FORMAT_DVI_ADPCM           (0x0011)
-		#define WAVE_FORMAT_DIGISTD             (0x0015)
-		#define WAVE_FORMAT_DIGIFIX             (0x0016)
-		#define WAVE_FORMAT_YAMAHA_ADPCM        (0x0020)
-		#define WAVE_FORMAT_DSP_TRUESPEECH      (0x0022)
-		#define WAVE_FORMAT_GSM610              (0x0031)
-		#define IBM_FORMAT_MULAW                (0x0101)
-		#define IBM_FORMAT_ALAW                 (0x0102)
-		#define IBM_FORMAT_ADPCM                (0x0103)
-	#endif
-
-	avi_t* AVI_open_output_file(char * filename);
-	void AVI_set_video(avi_t *AVI, int width, int height, double fps, char *compressor);
-	void AVI_set_audio(avi_t *AVI, int channels, long rate, int bits, int format, long mp3rate);
-	int  AVI_write_frame(avi_t *AVI, char *data, long bytes, int keyframe);
-	int  AVI_dup_frame(avi_t *AVI);
-	int  AVI_write_audio(avi_t *AVI, char *data, long bytes);
-	int  AVI_append_audio(avi_t *AVI, char *data, long bytes);
-	long AVI_bytes_remain(avi_t *AVI);
-	int  AVI_close(avi_t *AVI);
-	long AVI_bytes_written(avi_t *AVI);
-
-	avi_t *AVI_open_input_file(char *filename, int getIndex);
-	avi_t *AVI_open_fd(int fd, int getIndex);
-	int avi_parse_input_file(avi_t *AVI, int getIndex);
-	long AVI_audio_mp3rate(avi_t *AVI);
-	long AVI_video_frames(avi_t *AVI);
-	int  AVI_video_width(avi_t *AVI);
-	int  AVI_video_height(avi_t *AVI);
-	double AVI_frame_rate(avi_t *AVI);
-	char* AVI_video_compressor(avi_t *AVI);
-
-	int  AVI_audio_channels(avi_t *AVI);
-	int  AVI_audio_bits(avi_t *AVI);
-	int  AVI_audio_format(avi_t *AVI);
-	long AVI_audio_rate(avi_t *AVI);
-	long AVI_audio_bytes(avi_t *AVI);
-	long AVI_audio_chunks(avi_t *AVI);
-
-	long AVI_max_video_chunk(avi_t *AVI);
-
-	long AVI_frame_size(avi_t *AVI, long frame);
-	long AVI_audio_size(avi_t *AVI, long frame);
-	int  AVI_seek_start(avi_t *AVI);
-	int  AVI_set_video_position(avi_t *AVI, long frame);
-	long AVI_get_video_position(avi_t *AVI, long frame);
-	long AVI_read_frame(avi_t *AVI, char *vidbuf, int *keyframe);
-
-	int  AVI_set_audio_position(avi_t *AVI, long byte);
-	int  AVI_set_audio_bitrate(avi_t *AVI, long bitrate);
-
-	long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes);
-
-	long AVI_audio_codech_offset(avi_t *AVI);
-	long AVI_audio_codecf_offset(avi_t *AVI);
-	long AVI_video_codech_offset(avi_t *AVI);
-	long AVI_video_codecf_offset(avi_t *AVI);
-
-	int  AVI_read_data(avi_t *AVI, char *vidbuf, long max_vidbuf,
-								   char *audbuf, long max_audbuf,
-								   long *len);
-
-	void AVI_print_error(char *str);
-	char *AVI_strerror();
-	char *AVI_syserror();
-
-	int AVI_scan(char *name);
-	int AVI_dump(char *name, int mode);
-
-	char *AVI_codec2str(short cc);
-	int AVI_file_check(char *import_file);
-
-	void AVI_info(avi_t *avifile);
-	uint64_t AVI_max_size();
-	int avi_update_header(avi_t *AVI);
-
-	int AVI_set_audio_track(avi_t *AVI, int track);
-	int AVI_get_audio_track(avi_t *AVI);
-	int AVI_audio_tracks(avi_t *AVI);
-
-	struct riff_struct 
-	{
-	  unsigned char id[4];   /* RIFF */
-	  unsigned long len;
-	  unsigned char wave_id[4]; /* WAVE */
-	};
-
-
-	struct chunk_struct 
-	{
-		unsigned char id[4];
-		unsigned long len;
-	};
-
-	struct common_struct 
-	{
-		unsigned short wFormatTag;
-		unsigned short wChannels;
-		unsigned long dwSamplesPerSec;
-		unsigned long dwAvgBytesPerSec;
-		unsigned short wBlockAlign;
-		unsigned short wBitsPerSample;  /* Only for PCM */
-	};
-
-	struct wave_header 
-	{
-		struct riff_struct   riff;
-		struct chunk_struct  format;
-		struct common_struct common;
-		struct chunk_struct  data;
-	};
-
-
-
-	struct AVIStreamHeader {
-	  long  fccType;
-	  long  fccHandler;
-	  long  dwFlags;
-	  long  dwPriority;
-	  long  dwInitialFrames;
-	  long  dwScale;
-	  long  dwRate;
-	  long  dwStart;
-	  long  dwLength;
-	  long  dwSuggestedBufferSize;
-	  long  dwQuality;
-	  long  dwSampleSize;
-	};
-
-#endif
-
-//========================================================================================================================================================================================================200
-//
-//========================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 144
opencl/heartwall/util/avi/avimod.c

@@ -1,144 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//===============================================================================================================================================================================================================
-//	DEFINE / INCLUDE
-//===============================================================================================================================================================================================================
-#include "avimod.h"
-
-//===============================================================================================================================================================================================================
-//	FUNCTIONS
-//===============================================================================================================================================================================================================
-
-// Flips the specified image and crops it to the specified dimensions
-// If scaled == true, all values are scaled to the range [0.0, 1.0
-fp* chop_flip_image(	char *image, 
-								int height, 
-								int width, 
-								int cropped,
-								int scaled,
-								int converted) {
-
-	// fixed dimensions for cropping or not cropping, square vertices starting from initial point in top left corner going down and right
-	int top;
-	int bottom;
-	int left;
-	int right;
-	if(cropped==1){
-		top = 0;
-		bottom = 0;
-		left = 0;
-		right = 0;
-	}
-	else{
-		top = 0;
-		bottom = height - 1;
-		left = 0;
-		right = width - 1;
-	}
-
-	// dimensions of new cropped image
-	int height_new = bottom - top + 1;
-	int width_new = right - left + 1;
-
-	// counters
-	int i, j;
-
-	// allocate memory for cropped/flipped frame
-	fp* result = (fp *) malloc(height_new * width_new * sizeof(fp));
-
-	// crop/flip and scale frame
-	fp temp;
-	if (scaled) {
-		fp scale = 1.0 / 255.0;
-		for(i = 0; i <height_new; i++){				// rows
-			for(j = 0; j <width_new; j++){			// colums
-				temp = (fp) image[((height - 1 - (i + top)) * width) + (j + left)] * scale;
-				if(temp<0){
-					result[i*width_new+j] = temp + 256;
-				}
-				else{
-					result[i*width_new+j] = temp;
-				}
-			}
-		}
-	} else {
-		for(i = 0; i <height_new; i++){				// rows
-			for(j = 0; j <width_new; j++){			// colums
-				temp = (fp) image[((height - 1 - (i + top)) * width) + (j + left)] ;
-				if(temp<0){
-					result[i*width_new+j] = temp + 256;
-				}
-				else{
-					result[i*width_new+j] = temp;
-				}
-			}
-		}
-	}
-
-// convert storage method (from row-major to column-major)
-	fp* result_converted = (fp *) malloc(height_new * width_new * sizeof(fp));
-	if(converted==1){
-		for(i = 0; i <width_new; i++){				// rows
-			for(j = 0; j <height_new; j++){			// colums
-				result_converted[i*height_new+j] = result[j*width_new+i];
-			}
-		}
-	}
-	else{
-		result_converted = result;
-	}
-	free(result);
-
-	// return
-	return result_converted;
-}
-
-// Returns the specified frame from the specified video file
-// If cropped == true, the frame is cropped to pre-determined dimensions
-//  (hardcoded to the boundaries of the blood vessel in the test video)
-// If scaled == true, all values are scaled to the range [0.0, 1.0]
-fp* get_frame(	avi_t* cell_file, 
-						int frame_num, 
-						int cropped, 
-						int scaled,
-						int converted) {
-
-	// variable
-	int dummy;
-	int width = AVI_video_width(cell_file);
-	int height = AVI_video_height(cell_file);
-	int status;
-
-	// There are 600 frames in this file (i.e. frame_num = 600 causes an error)
-	AVI_set_video_position(cell_file, frame_num);
-
-	//Read in the frame from the AVI
-	char* image_buf = (char*) malloc(width * height * sizeof(char));
-	status = AVI_read_frame(cell_file, image_buf, &dummy);
-	if(status == -1) {
-		AVI_print_error((char*) "Error with AVI_read_frame");
-		exit(-1);
-	}
-
-	// The image is read in upside-down, so we need to flip it
-	fp* image_chopped;
-	image_chopped = chop_flip_image(	image_buf, 
-														height, 
-														width, 
-														cropped,
-														scaled,
-														converted);
-
-	// free image buffer
-	free(image_buf);
-
-	// return
-	return image_chopped;
-
-} 
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 36
opencl/heartwall/util/avi/avimod.h

@@ -1,36 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE / INCLUDE
-//========================================================================================================================================================================================================200
-
-#define fp float
-
-#include "avilib.h"
-
-//========================================================================================================================================================================================================200
-//	DEFINE / INCLUDE
-//========================================================================================================================================================================================================200
-
-fp* chop_flip_image(	char *image, 
-								int height, 
-								int width, 
-								int cropped,
-								int scaled,
-								int converted) ;
-
-fp* get_frame(	avi_t* cell_file, 
-						int frame_num, 
-						int cropped, 
-						int scaled,
-						int converted) ;
-
-//========================================================================================================================================================================================================200
-//	End
-//========================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 264
opencl/heartwall/util/file/file.c

@@ -1,264 +0,0 @@
-//===============================================================================================================================================================================================================200
-//	INCLUDE/DEFINE
-//===============================================================================================================================================================================================================200
-
-#include <stdio.h>										// needed by types/functions related to file handling
-
-//===============================================================================================================================================================================================================200
-//	READ PARAMETERS FUNCTION
-//===============================================================================================================================================================================================================200
-
-#include "./../../main.h"								// needed for definition of fp
-
-//===============================================================================================================================================================================================================200
-//	INCLUDE HEADER
-//===============================================================================================================================================================================================================200
-
-#include "./file.h"
-
-//===============================================================================================================================================================================================================200
-//	READ PARAMETERS FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-read_parameters(char* filename,
-				int* tSize,
-				int* sSize,
-				int* maxMove,
-				fp* alpha){
-
-	//================================================================================80
-	//	VARIABLES
-	//================================================================================80
-
-	FILE* fid;
-
-	//================================================================================80
-	//	OPEN FILE FOR READING
-	//================================================================================80
-
-	fid = fopen(filename, "r");
-	if( fid == NULL ){
-		printf( "The file was not opened for reading\n" );
-		return;
-	}
-
-	//================================================================================80
-	//	READ VALUES FROM THE FILE
-	//================================================================================80
-
-	fscanf(fid, "%d", &tSize[0]);
-	fscanf(fid, "%d", &sSize[0]);
-	fscanf(fid, "%d", &maxMove[0]);
-	fscanf(fid, "%f", &alpha[0]);
-
-	//================================================================================80
-	//	CLOSE FILE
-	//================================================================================80
-
-	fclose(fid);
-
-}
-
-//===============================================================================================================================================================================================================200
-//	READ HEADER FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-read_header(char* filename,
-			int* size,
-			int* size_2){
-
-	//================================================================================80
-	//	VARIABLES
-	//================================================================================80
-
-	FILE* fid;
-	int i;
-	char c;
-
-	//================================================================================80
-	//	OPEN FILE FOR READING
-	//================================================================================80
-
-	fid = fopen(filename, "r");
-	if( fid == NULL ){
-		printf( "The file was not opened for reading\n" );
-		return;
-	}
-
-	//================================================================================80
-	//	SKIP LINES
-	//================================================================================80
-
-	i = 0;
-	while(i<1){
-		c = fgetc(fid);
-		if(c == '\n'){
-			i = i+1;
-		}
-	};
-
-	//================================================================================80
-	//	READ VALUES FROM THE FILE
-	//================================================================================80
-
-	fscanf(fid, "%d", &size[0]);
-
-	fscanf(fid, "%d", &size_2[0]);
-
-	//================================================================================80
-	//	CLOSE FILE
-	//================================================================================80
-
-	fclose(fid);
-
-}
-
-//===============================================================================================================================================================================================================200
-//	READ DATA FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-read_data(	char* filename,
-			int size,
-			int* input_a,
-			int* input_b,
-			int size_2,
-			int* input_2a,
-			int* input_2b){
-
-	//================================================================================80
-	//	VARIABLES
-	//================================================================================80
-
-	FILE* fid;
-	int i;
-	char c;
-
-	//================================================================================80
-	//	OPEN FILE FOR READING
-	//================================================================================80
-
-	fid = fopen(filename, "r");
-	if( fid == NULL ){
-		printf( "The file was not opened for reading\n" );
-		return;
-	}
-
-	//================================================================================80
-	//	SKIP LINES
-	//================================================================================80
-
-	i = 0;
-	while(i<2){
-		c = fgetc(fid);
-		if(c == '\n'){
-			i = i+1;
-		}
-	};
-
-	//================================================================================80
-	//	READ VALUES FROM THE FILE
-	//================================================================================80
-
-	for(i=0; i<size; i++){
-		fscanf(fid, "%d", &input_a[i]);
-	}
-	for(i=0; i<size; i++){
-		fscanf(fid, "%d", &input_b[i]);
-	}
-
-	for(i=0; i<size_2; i++){
-		fscanf(fid, "%d", &input_2a[i]);
-	}
-	for(i=0; i<size_2; i++){
-		fscanf(fid, "%d", &input_2b[i]);
-	}
-
-	//================================================================================80
-	//	CLOSE FILE
-	//================================================================================80
-
-	fclose(fid);
-
-}
-
-
-//===============================================================================================================================================================================================================200
-//	WRITE DATA FUNCTION
-//===============================================================================================================================================================================================================200
-
-void write_data(	char* filename,
-			int frameNo,
-			int frames_processed,
-			int endoPoints,
-			int* input_a,
-			int* input_b,
-			int epiPoints,
-			int* input_2a,
-			int* input_2b){
-
-	//================================================================================80
-	//	VARIABLES
-	//================================================================================80
-
-	FILE* fid;
-	int i,j;
-	char c;
-
-	//================================================================================80
-	//	OPEN FILE FOR READING
-	//================================================================================80
-
-	fid = fopen(filename, "w+");
-	if( fid == NULL ){
-		printf( "The file was not opened for writing\n" );
-		return;
-	}
-
-
-	//================================================================================80
-	//	WRITE VALUES TO THE FILE
-	//================================================================================80
-      fprintf(fid, "Total AVI Frames: %d\n", frameNo);	
-      fprintf(fid, "Frames Processed: %d\n", frames_processed);	
-      fprintf(fid, "endoPoints: %d\n", endoPoints);
-      fprintf(fid, "epiPoints: %d", epiPoints);
-	for(j=0; j<frames_processed;j++)
-	  {
-	    fprintf(fid, "\n---Frame %d---",j);
-	    fprintf(fid, "\n--endo--\n",j);
-	    for(i=0; i<endoPoints; i++){
-	      fprintf(fid, "%d\t", input_a[j+i*frameNo]);
-	    }
-	    fprintf(fid, "\n");
-	    for(i=0; i<endoPoints; i++){
-	      // if(input_b[j*size+i] > 2000) input_b[j*size+i]=0;
-	      fprintf(fid, "%d\t", input_b[j+i*frameNo]);
-	    }
-	    fprintf(fid, "\n--epi--\n",j);
-	    for(i=0; i<epiPoints; i++){
-	      //if(input_2a[j*size_2+i] > 2000) input_2a[j*size_2+i]=0;
-	      fprintf(fid, "%d\t", input_2a[j+i*frameNo]);
-	    }
-	    fprintf(fid, "\n");
-	    for(i=0; i<epiPoints; i++){
-	      //if(input_2b[j*size_2+i] > 2000) input_2b[j*size_2+i]=0;
-	      fprintf(fid, "%d\t", input_2b[j+i*frameNo]);
-	    }
-	  }
-	// 	================================================================================80
-	//		CLOSE FILE
-		  //	================================================================================80
-
-	fclose(fid);
-
-}
-
-
-
-//===============================================================================================================================================================================================================200
-//	End
-//===============================================================================================================================================================================================================200
-

+ 0 - 58
opencl/heartwall/util/file/file.h

@@ -1,58 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	READ PARAMETERS FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-read_parameters(char* filename,
-				int* tSize,
-				int* sSize,
-				int* maxMove,
-				fp* alpha);
-
-//===============================================================================================================================================================================================================200
-//	READ HEADER FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-read_header(char* filename,
-			int* size,
-			int* size_2);
-
-//===============================================================================================================================================================================================================200
-//	READ DATA FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-read_data(	char* filename,
-			int size,
-			int* input_a,
-			int* input_b,
-			int size_2,
-			int* input_2a,
-			int* input_2b);
-
-//===============================================================================================================================================================================================================200
-//	READ DATA FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-write_data(	char* filename,
-		int frameNo,
-                int frames_processed,
-		int endoPoints,
-		int* input_a,
-		int* input_b,
-		int epiPoints,
-		int* input_2a,
-		int* input_2b);
-
-//	End
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 146
opencl/heartwall/util/opencl/opencl.c

@@ -1,146 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	INCLUDE/DEFINE
-//===============================================================================================================================================================================================================200
-
-#include <stdio.h>					// (in path known to compiler)		needed by printf
-
-#include <CL/cl.h>					// (in path specified to compiler)	needed by OpenCL types
-
-//===============================================================================================================================================================================================================200
-//	INCLUDE/DEFINE
-//===============================================================================================================================================================================================================200
-
-#include "opencl.h"					// (in directory)	function headers
-
-//===============================================================================================================================================================================================================200
-//	LOAD KERNEL SOURCE CODE FUNCTION
-//===============================================================================================================================================================================================================200
-
-char *
-load_kernel_source(const char *filename)
-{
-	// Open the source file
-	FILE *file = fopen(filename, "r");
-	if (file == NULL){
-		fatal("Error opening kernel source file\n");
-	}
-
-	// Determine the size of the file
-	if (fseek(file, 0, SEEK_END)){
-		fatal("Error reading kernel source file\n");
-	}
-	size_t size = ftell(file);
-
-	// Allocate space for the source code (plus one for null-terminator)
-	char *source = (char *) malloc(size + 1);
-
-	// Read the source code into the string
-	fseek(file, 0, SEEK_SET);
-	// printf("Number of elements: %lu\nSize = %lu", fread(source, 1, size, file), size);
-	// exit(1);
-	if (fread(source, 1, size, file) != size){
-		fatal("Error reading kernel source file\n");
-	}
-
-	// Null-terminate the string
-	source[size] = '\0';
-
-	// Return the pointer to the string
-	return source;
-}
-
-//===============================================================================================================================================================================================================200
-//	PRINT ERROR FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-fatal(const char *s)
-{
-	fprintf(stderr, "Error: %s\n", s);
-	exit(1);
-}
-
-//===============================================================================================================================================================================================================200
-//	PRINT OPENCL ERROR FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-fatal_CL(cl_int error, int line_no) {
-
-	printf("Error at line %d: ", line_no);
-
-	switch(error) {
-
-		case CL_SUCCESS: 									printf("CL_SUCCESS\n"); break;
-		case CL_DEVICE_NOT_FOUND: 							printf("CL_DEVICE_NOT_FOUND\n"); break;
-		case CL_DEVICE_NOT_AVAILABLE: 						printf("CL_DEVICE_NOT_AVAILABLE\n"); break;
-		case CL_COMPILER_NOT_AVAILABLE: 					printf("CL_COMPILER_NOT_AVAILABLE\n"); break;
-		case CL_MEM_OBJECT_ALLOCATION_FAILURE: 				printf("CL_MEM_OBJECT_ALLOCATION_FAILURE\n"); break;
-		case CL_OUT_OF_RESOURCES: 							printf("CL_OUT_OF_RESOURCES\n"); break;
-		case CL_OUT_OF_HOST_MEMORY: 						printf("CL_OUT_OF_HOST_MEMORY\n"); break;
-		case CL_PROFILING_INFO_NOT_AVAILABLE: 				printf("CL_PROFILING_INFO_NOT_AVAILABLE\n"); break;
-		case CL_MEM_COPY_OVERLAP: 							printf("CL_MEM_COPY_OVERLAP\n"); break;
-		case CL_IMAGE_FORMAT_MISMATCH: 						printf("CL_IMAGE_FORMAT_MISMATCH\n"); break;
-		case CL_IMAGE_FORMAT_NOT_SUPPORTED: 				printf("CL_IMAGE_FORMAT_NOT_SUPPORTED\n"); break;
-		case CL_BUILD_PROGRAM_FAILURE: 						printf("CL_BUILD_PROGRAM_FAILURE\n"); break;
-		case CL_MAP_FAILURE: 								printf("CL_MAP_FAILURE\n"); break;
-		case CL_INVALID_VALUE: 								printf("CL_INVALID_VALUE\n"); break;
-		case CL_INVALID_DEVICE_TYPE: 						printf("CL_INVALID_DEVICE_TYPE\n"); break;
-		case CL_INVALID_PLATFORM: 							printf("CL_INVALID_PLATFORM\n"); break;
-		case CL_INVALID_DEVICE: 							printf("CL_INVALID_DEVICE\n"); break;
-		case CL_INVALID_CONTEXT: 							printf("CL_INVALID_CONTEXT\n"); break;
-		case CL_INVALID_QUEUE_PROPERTIES: 					printf("CL_INVALID_QUEUE_PROPERTIES\n"); break;
-		case CL_INVALID_COMMAND_QUEUE: 						printf("CL_INVALID_COMMAND_QUEUE\n"); break;
-		case CL_INVALID_HOST_PTR: 							printf("CL_INVALID_HOST_PTR\n"); break;
-		case CL_INVALID_MEM_OBJECT: 						printf("CL_INVALID_MEM_OBJECT\n"); break;
-		case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: 			printf("CL_INVALID_IMAGE_FORMAT_DESCRIPTOR\n"); break;
-		case CL_INVALID_IMAGE_SIZE: 						printf("CL_INVALID_IMAGE_SIZE\n"); break;
-		case CL_INVALID_SAMPLER: 							printf("CL_INVALID_SAMPLER\n"); break;
-		case CL_INVALID_BINARY: 							printf("CL_INVALID_BINARY\n"); break;
-		case CL_INVALID_BUILD_OPTIONS: 						printf("CL_INVALID_BUILD_OPTIONS\n"); break;
-		case CL_INVALID_PROGRAM: 							printf("CL_INVALID_PROGRAM\n"); break;
-		case CL_INVALID_PROGRAM_EXECUTABLE: 				printf("CL_INVALID_PROGRAM_EXECUTABLE\n"); break;
-		case CL_INVALID_KERNEL_NAME: 						printf("CL_INVALID_KERNEL_NAME\n"); break;
-		case CL_INVALID_KERNEL_DEFINITION: 					printf("CL_INVALID_KERNEL_DEFINITION\n"); break;
-		case CL_INVALID_KERNEL: 							printf("CL_INVALID_KERNEL\n"); break;
-		case CL_INVALID_ARG_INDEX: 							printf("CL_INVALID_ARG_INDEX\n"); break;
-		case CL_INVALID_ARG_VALUE: 							printf("CL_INVALID_ARG_VALUE\n"); break;
-		case CL_INVALID_ARG_SIZE: 							printf("CL_INVALID_ARG_SIZE\n"); break;
-		case CL_INVALID_KERNEL_ARGS: 						printf("CL_INVALID_KERNEL_ARGS\n"); break;
-		case CL_INVALID_WORK_DIMENSION: 					printf("CL_INVALID_WORK_DIMENSION\n"); break;
-		case CL_INVALID_WORK_GROUP_SIZE: 					printf("CL_INVALID_WORK_GROUP_SIZE\n"); break;
-		case CL_INVALID_WORK_ITEM_SIZE: 					printf("CL_INVALID_WORK_ITEM_SIZE\n"); break;
-		case CL_INVALID_GLOBAL_OFFSET: 						printf("CL_INVALID_GLOBAL_OFFSET\n"); break;
-		case CL_INVALID_EVENT_WAIT_LIST: 					printf("CL_INVALID_EVENT_WAIT_LIST\n"); break;
-		case CL_INVALID_EVENT: 								printf("CL_INVALID_EVENT\n"); break;
-		case CL_INVALID_OPERATION: 							printf("CL_INVALID_OPERATION\n"); break;
-		case CL_INVALID_GL_OBJECT: 							printf("CL_INVALID_GL_OBJECT\n"); break;
-		case CL_INVALID_BUFFER_SIZE: 						printf("CL_INVALID_BUFFER_SIZE\n"); break;
-		case CL_INVALID_MIP_LEVEL: 							printf("CL_INVALID_MIP_LEVEL\n"); break;
-		case CL_INVALID_GLOBAL_WORK_SIZE: 					printf("CL_INVALID_GLOBAL_WORK_SIZE\n"); break;
-
-		#ifdef CL_VERSION_1_1
-		case CL_MISALIGNED_SUB_BUFFER_OFFSET: 				printf("CL_MISALIGNED_SUB_BUFFER_OFFSET\n"); break;
-		case CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST:	printf("CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST\n"); break;
-		/* case CL_INVALID_PROPERTY: 							printf("CL_INVALID_PROPERTY\n"); break; */
-		#endif
-
-		default:											printf("Invalid OpenCL error code\n");
-
-	}
-
-	exit(error);
-
-}
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 32
opencl/heartwall/util/opencl/opencl.h

@@ -1,32 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	LOAD KERNEL SOURCE CODE FUNCTION HEADER
-//===============================================================================================================================================================================================================200
-
-char *
-load_kernel_source(const char *filename);
-
-//===============================================================================================================================================================================================================200
-//	PRINT ERROR FUNCTION HEADER
-//===============================================================================================================================================================================================================200
-
-void 
-fatal(const char *s);
-
-//===============================================================================================================================================================================================================200
-//	PRINT OPENCL ERROR FUNCTION HEADER
-//===============================================================================================================================================================================================================200
-
-void 
-fatal_CL(cl_int error, int line_no);
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 34
opencl/heartwall/util/timer/timer.c

@@ -1,34 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	INCLUDE/DEFINE
-//===============================================================================================================================================================================================================200
-
-#include <stdlib.h>
-
-//===============================================================================================================================================================================================================200
-//	INCLUDE HEADER
-//===============================================================================================================================================================================================================200
-
-#include "./timer.h"
-
-//===============================================================================================================================================================================================================200
-//	TIMER FUNCTION
-//===============================================================================================================================================================================================================200
-
- // Returns the current system time in microseconds
-long long get_time() {
-	struct timeval tv;
-	gettimeofday(&tv, NULL);
-	return (tv.tv_sec * 1000000) + tv.tv_usec;
-}
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 18
opencl/heartwall/util/timer/timer.h

@@ -1,18 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-//===============================================================================================================================================================================================================200
-//	TIMER HEADER
-//===============================================================================================================================================================================================================200
-
-long long 
-get_time();
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-#ifdef __cplusplus
-}
-#endif

BIN
opencl/hotspot3D/3D


+ 0 - 284
opencl/hotspot3D/3D.c

@@ -1,284 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <CL/cl.h>
-#include "CL_helper.h"
-
-#ifndef DEVICE
-#define DEVICE CL_DEVICE_TYPE_DEFAULT
-#endif
-
-#define TOL      (0.001)
-#define STR_SIZE (256)
-#define MAX_PD   (3.0e6)
-
-/* required precision in degrees	*/
-#define PRECISION    0.001
-#define SPEC_HEAT_SI 1.75e6
-#define K_SI         100
-
-/* capacitance fitting factor	*/
-#define FACTOR_CHIP	0.5
-
-#define WG_SIZE_X (64)
-#define WG_SIZE_Y (4)
-float t_chip      = 0.0005;
-float chip_height = 0.016;
-float chip_width  = 0.016;
-float amb_temp    = 80.0;
-
-void usage(int argc, char **argv)
-{
-  fprintf(stderr, "Usage: %s <rows/cols> <layers> <iterations> <powerFile> <tempFile> <outputFile>\n", argv[0]);
-  fprintf(stderr, "\t<rows/cols>  - number of rows/cols in the grid (positive integer)\n");
-  fprintf(stderr, "\t<layers>  - number of layers in the grid (positive integer)\n");
-
-  fprintf(stderr, "\t<iteration> - number of iterations\n");
-  fprintf(stderr, "\t<powerFile>  - name of the file containing the initial power values of each cell\n");
-  fprintf(stderr, "\t<tempFile>  - name of the file containing the initial temperature values of each cell\n");
-  fprintf(stderr, "\t<outputFile - output file\n");
-  exit(1);
-}
-
-
-
-int main(int argc, char** argv)
-{
-  if (argc != 7)
-    {
-      usage(argc,argv);
-    }
-
-  char *pfile, *tfile, *ofile;
-  int iterations = atoi(argv[3]);
-
-  pfile            = argv[4];
-  tfile            = argv[5];
-  ofile            = argv[6];
-  int numCols      = atoi(argv[1]);
-  int numRows      = atoi(argv[1]);
-  int layers       = atoi(argv[2]);
-
-  /* calculating parameters*/
-
-  float dx         = chip_height/numRows;
-  float dy         = chip_width/numCols;
-  float dz         = t_chip/layers;
-
-  float Cap        = FACTOR_CHIP * SPEC_HEAT_SI * t_chip * dx * dy;
-  float Rx         = dy / (2.0 * K_SI * t_chip * dx);
-  float Ry         = dx / (2.0 * K_SI * t_chip * dy);
-  float Rz         = dz / (K_SI * dx * dy);
-
-  float max_slope  = MAX_PD / (FACTOR_CHIP * t_chip * SPEC_HEAT_SI);
-  float dt         = PRECISION / max_slope;
-
-  float ce, cw, cn, cs, ct, cb, cc;
-  float stepDivCap = dt / Cap;
-  ce               = cw                                              = stepDivCap/ Rx;
-  cn               = cs                                              = stepDivCap/ Ry;
-  ct               = cb                                              = stepDivCap/ Rz;
-
-  cc               = 1.0 - (2.0*ce + 2.0*cn + 3.0*ct);
-
-
-  int          err;           
-  int size = numCols * numRows * layers;
-  float*        tIn      = (float*) calloc(size,sizeof(float));
-  float*        pIn      = (float*) calloc(size,sizeof(float));
-  float*        tempCopy = (float*)malloc(size * sizeof(float));
-  float*        tempOut  = (float*) calloc(size,sizeof(float));
-  int i                 = 0;
-  int count = size;
-  readinput(tIn,numRows, numCols, layers, tfile);
-  readinput(pIn,numRows, numCols, layers, pfile);
-
-  size_t global[2];                   
-  size_t local[2];
-  memcpy(tempCopy,tIn, size * sizeof(float));
-
-  cl_device_id     device_id;     
-  cl_context       context;       
-  cl_command_queue commands;      
-  cl_program       program;       
-  cl_kernel        ko_vadd;       
-
-  cl_mem d_a;                     
-  cl_mem d_b;                     
-  cl_mem d_c;                     
-  const char *KernelSource = load_kernel_source("hotspotKernel.cl"); 
-  cl_uint numPlatforms;
-
-  err = clGetPlatformIDs(0, NULL, &numPlatforms);
-  if (err != CL_SUCCESS || numPlatforms <= 0)
-    {
-      printf("Error: Failed to find a platform!\n%s\n",err_code(err));
-      return EXIT_FAILURE;
-    }
-
-  cl_platform_id Platform[numPlatforms];
-  err = clGetPlatformIDs(numPlatforms, Platform, NULL);
-  if (err != CL_SUCCESS || numPlatforms <= 0)
-    {
-      printf("Error: Failed to get the platform!\n%s\n",err_code(err));
-      return EXIT_FAILURE;
-    }
-
-  for (i = 0; i < numPlatforms; i++)
-    {
-      err = clGetDeviceIDs(Platform[i], DEVICE, 1, &device_id, NULL);
-      if (err == CL_SUCCESS)
-        {
-          break;
-        } 
-    }
-
-  if (device_id == NULL)
-    {
-      printf("Error: Failed to create a device group!\n%s\n",err_code(err));
-      return EXIT_FAILURE;
-    }
-
-  err = output_device_info(device_id);
-
-  context = clCreateContext(0, 1, &device_id, NULL, NULL, &err);
-  if (!context)
-    {
-      printf("Error: Failed to create a compute context!\n%s\n", err_code(err));
-      return EXIT_FAILURE;
-    }
-
-  commands = clCreateCommandQueue(context, device_id, 0, &err);
-  if (!commands)
-    {
-      printf("Error: Failed to create a command commands!\n%s\n", err_code(err));
-      return EXIT_FAILURE;
-    }
-
-  program = clCreateProgramWithSource(context, 1, (const char **) & KernelSource, NULL, &err);
-  if (!program)
-    {
-      printf("Error: Failed to create compute program!\n%s\n", err_code(err));
-      return EXIT_FAILURE;
-    }
-
-  err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
-  if (err != CL_SUCCESS)
-    {
-      size_t len;
-      char buffer[2048];
-
-      printf("Error: Failed to build program executable!\n%s\n", err_code(err));
-      clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
-      printf("%s\n", buffer);
-      return EXIT_FAILURE;
-    }
-
-  ko_vadd = clCreateKernel(program, "hotspotOpt1", &err);
-  if (!ko_vadd || err != CL_SUCCESS)
-    {
-      printf("Error: Failed to create compute kernel!\n%s\n", err_code(err));
-      return EXIT_FAILURE;
-    }
-
-  d_a  = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float) * count, NULL, NULL);
-  d_b  = clCreateBuffer(context, CL_MEM_READ_ONLY , sizeof(float) * count, NULL, NULL);
-  d_c  = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(float) * count, NULL, NULL);
-
-  if (!d_a || !d_b || !d_c) 
-    {
-      printf("Error: Failed to allocate device memory!\n");
-      exit(1);
-    }    
-
-  err = clEnqueueWriteBuffer(commands, d_a, CL_TRUE, 0, sizeof(float) * count, tIn, 0, NULL, NULL);
-  if (err != CL_SUCCESS)
-    {
-      printf("Error: Failed to write tIn to source array!\n%s\n", err_code(err));
-      exit(1);
-    }
-
-  err = clEnqueueWriteBuffer(commands, d_b, CL_TRUE, 0, sizeof(float) * count, pIn, 0, NULL, NULL);
-  if (err != CL_SUCCESS)
-    {
-      printf("Error: Failed to write pIn to source array!\n%s\n", err_code(err));
-      exit(1);
-    }
-
-  err = clEnqueueWriteBuffer(commands, d_c, CL_TRUE, 0, sizeof(float) * count, tempOut, 0, NULL, NULL);
-  if (err != CL_SUCCESS)
-    {
-      printf("Error: Failed to write tempOut to source array!\n%s\n", err_code(err));
-      exit(1);
-    }
-  long long start = get_time();
-  int j;
-  for(j = 0; j < iterations; j++)
-    {
-      err  = clSetKernelArg(ko_vadd, 0, sizeof(cl_mem), &d_b);
-      err |= clSetKernelArg(ko_vadd, 1, sizeof(cl_mem), &d_a);
-      err |= clSetKernelArg(ko_vadd, 2, sizeof(cl_mem), &d_c);
-      err |= clSetKernelArg(ko_vadd, 3, sizeof(float), &stepDivCap);
-      err |= clSetKernelArg(ko_vadd, 4, sizeof(int), &numCols);
-      err |= clSetKernelArg(ko_vadd, 5, sizeof(int), &numRows);
-      err |= clSetKernelArg(ko_vadd, 6, sizeof(int), &layers);
-      err |= clSetKernelArg(ko_vadd, 7, sizeof(float), &ce);
-      err |= clSetKernelArg(ko_vadd, 8, sizeof(float), &cw);
-      err |= clSetKernelArg(ko_vadd, 9, sizeof(float), &cn);
-      err |= clSetKernelArg(ko_vadd, 10, sizeof(float), &cs);
-      err |= clSetKernelArg(ko_vadd, 11, sizeof(float), &ct);
-      err |= clSetKernelArg(ko_vadd, 12, sizeof(float), &cb);      
-      err |= clSetKernelArg(ko_vadd, 13, sizeof(float), &cc);
-      if (err != CL_SUCCESS)
-        {
-          printf("Error: Failed to set kernel arguments!\n");
-          exit(1);
-        }
-
-      global[0] = numCols;
-      global[1] = numRows;
-
-      local[0] = WG_SIZE_X;
-      local[1] = WG_SIZE_Y;
-
-      err = clEnqueueNDRangeKernel(commands, ko_vadd, 2, NULL, global, local, 0, NULL, NULL);
-      if (err)
-        {
-          printf("Error: Failed to execute kernel!\n%s\n", err_code(err));
-          return EXIT_FAILURE;
-        }
-
-      cl_mem temp = d_a;
-      d_a         = d_c;
-      d_c         = temp;
-    }
-
-  clFinish(commands);
-  long long stop = get_time();
-  err = clEnqueueReadBuffer( commands, d_c, CL_TRUE, 0, sizeof(float) * count, tempOut, 0, NULL, NULL );  
-  if (err != CL_SUCCESS)
-    {
-      printf("Error: Failed to read output array!\n%s\n", err_code(err));
-      exit(1);
-    }
-
-  float* answer = (float*)calloc(size, sizeof(float));
-  computeTempCPU(pIn, tempCopy, answer, numCols, numRows, layers, Cap, Rx, Ry, Rz, dt, amb_temp, iterations);
-
-  float acc = accuracy(tempOut,answer,numRows*numCols*layers);
-  float time = (float)((stop - start)/(1000.0 * 1000.0));
-  printf("Time: %.3f (s)\n",time);
-  printf("Accuracy: %e\n",acc);
-
-  writeoutput(tempOut,numRows,numCols,layers,ofile);
-  clReleaseMemObject(d_a);
-  clReleaseMemObject(d_b);
-  clReleaseMemObject(d_c);
-  clReleaseProgram(program);
-  clReleaseKernel(ko_vadd);
-  clReleaseCommandQueue(commands);
-  clReleaseContext(context);
-
-  return 0;
-}
-

+ 0 - 342
opencl/hotspot3D/CL_helper.c

@@ -1,342 +0,0 @@
-#include "CL_helper.h"
-
-#define STR_SIZE 256
-
-long long get_time() {
-	struct timeval tv;
-	gettimeofday(&tv, NULL);
-	return (tv.tv_sec * 1000000) + tv.tv_usec;
-}
-
-char *err_code (cl_int err_in)
-{
-    switch (err_in) {
-
-        case CL_SUCCESS :
-            return (char*)" CL_SUCCESS ";
-        case CL_DEVICE_NOT_FOUND :
-            return (char*)" CL_DEVICE_NOT_FOUND ";
-        case CL_DEVICE_NOT_AVAILABLE :
-            return (char*)" CL_DEVICE_NOT_AVAILABLE ";
-        case CL_COMPILER_NOT_AVAILABLE :
-            return (char*)" CL_COMPILER_NOT_AVAILABLE ";
-        case CL_MEM_OBJECT_ALLOCATION_FAILURE :
-            return (char*)" CL_MEM_OBJECT_ALLOCATION_FAILURE ";
-        case CL_OUT_OF_RESOURCES :
-            return (char*)" CL_OUT_OF_RESOURCES ";
-        case CL_OUT_OF_HOST_MEMORY :
-            return (char*)" CL_OUT_OF_HOST_MEMORY ";
-        case CL_PROFILING_INFO_NOT_AVAILABLE :
-            return (char*)" CL_PROFILING_INFO_NOT_AVAILABLE ";
-        case CL_MEM_COPY_OVERLAP :
-            return (char*)" CL_MEM_COPY_OVERLAP ";
-        case CL_IMAGE_FORMAT_MISMATCH :
-            return (char*)" CL_IMAGE_FORMAT_MISMATCH ";
-        case CL_IMAGE_FORMAT_NOT_SUPPORTED :
-            return (char*)" CL_IMAGE_FORMAT_NOT_SUPPORTED ";
-        case CL_BUILD_PROGRAM_FAILURE :
-            return (char*)" CL_BUILD_PROGRAM_FAILURE ";
-        case CL_MAP_FAILURE :
-            return (char*)" CL_MAP_FAILURE ";
-        case CL_MISALIGNED_SUB_BUFFER_OFFSET :
-            return (char*)" CL_MISALIGNED_SUB_BUFFER_OFFSET ";
-        case CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST :
-            return (char*)" CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST ";
-        case CL_INVALID_VALUE :
-            return (char*)" CL_INVALID_VALUE ";
-        case CL_INVALID_DEVICE_TYPE :
-            return (char*)" CL_INVALID_DEVICE_TYPE ";
-        case CL_INVALID_PLATFORM :
-            return (char*)" CL_INVALID_PLATFORM ";
-        case CL_INVALID_DEVICE :
-            return (char*)" CL_INVALID_DEVICE ";
-        case CL_INVALID_CONTEXT :
-            return (char*)" CL_INVALID_CONTEXT ";
-        case CL_INVALID_QUEUE_PROPERTIES :
-            return (char*)" CL_INVALID_QUEUE_PROPERTIES ";
-        case CL_INVALID_COMMAND_QUEUE :
-            return (char*)" CL_INVALID_COMMAND_QUEUE ";
-        case CL_INVALID_HOST_PTR :
-            return (char*)" CL_INVALID_HOST_PTR ";
-        case CL_INVALID_MEM_OBJECT :
-            return (char*)" CL_INVALID_MEM_OBJECT ";
-        case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR :
-            return (char*)" CL_INVALID_IMAGE_FORMAT_DESCRIPTOR ";
-        case CL_INVALID_IMAGE_SIZE :
-            return (char*)" CL_INVALID_IMAGE_SIZE ";
-        case CL_INVALID_SAMPLER :
-            return (char*)" CL_INVALID_SAMPLER ";
-        case CL_INVALID_BINARY :
-            return (char*)" CL_INVALID_BINARY ";
-        case CL_INVALID_BUILD_OPTIONS :
-            return (char*)" CL_INVALID_BUILD_OPTIONS ";
-        case CL_INVALID_PROGRAM :
-            return (char*)" CL_INVALID_PROGRAM ";
-        case CL_INVALID_PROGRAM_EXECUTABLE :
-            return (char*)" CL_INVALID_PROGRAM_EXECUTABLE ";
-        case CL_INVALID_KERNEL_NAME :
-            return (char*)" CL_INVALID_KERNEL_NAME ";
-        case CL_INVALID_KERNEL_DEFINITION :
-            return (char*)" CL_INVALID_KERNEL_DEFINITION ";
-        case CL_INVALID_KERNEL :
-            return (char*)" CL_INVALID_KERNEL ";
-        case CL_INVALID_ARG_INDEX :
-            return (char*)" CL_INVALID_ARG_INDEX ";
-        case CL_INVALID_ARG_VALUE :
-            return (char*)" CL_INVALID_ARG_VALUE ";
-        case CL_INVALID_ARG_SIZE :
-            return (char*)" CL_INVALID_ARG_SIZE ";
-        case CL_INVALID_KERNEL_ARGS :
-            return (char*)" CL_INVALID_KERNEL_ARGS ";
-        case CL_INVALID_WORK_DIMENSION :
-            return (char*)" CL_INVALID_WORK_DIMENSION ";
-        case CL_INVALID_WORK_GROUP_SIZE :
-            return (char*)" CL_INVALID_WORK_GROUP_SIZE ";
-        case CL_INVALID_WORK_ITEM_SIZE :
-            return (char*)" CL_INVALID_WORK_ITEM_SIZE ";
-        case CL_INVALID_GLOBAL_OFFSET :
-            return (char*)" CL_INVALID_GLOBAL_OFFSET ";
-        case CL_INVALID_EVENT_WAIT_LIST :
-            return (char*)" CL_INVALID_EVENT_WAIT_LIST ";
-        case CL_INVALID_EVENT :
-            return (char*)" CL_INVALID_EVENT ";
-        case CL_INVALID_OPERATION :
-            return (char*)" CL_INVALID_OPERATION ";
-        case CL_INVALID_GL_OBJECT :
-            return (char*)" CL_INVALID_GL_OBJECT ";
-        case CL_INVALID_BUFFER_SIZE :
-            return (char*)" CL_INVALID_BUFFER_SIZE ";
-        case CL_INVALID_MIP_LEVEL :
-            return (char*)" CL_INVALID_MIP_LEVEL ";
-        case CL_INVALID_GLOBAL_WORK_SIZE :
-            return (char*)" CL_INVALID_GLOBAL_WORK_SIZE ";
-        case CL_INVALID_PROPERTY :
-            return (char*)" CL_INVALID_PROPERTY ";
-        default:
-            return (char*)"UNKNOWN ERROR";
-
-    }
-}
-
-int output_device_info(cl_device_id device_id)
-{
-    int err;                            
-    cl_device_type device_type;         
-    cl_uint comp_units;                 
-    cl_char vendor_name[1024] = {0};    
-    cl_char device_name[1024] = {0};    
-#ifdef VERBOSE
-    cl_uint          max_work_itm_dims;
-    size_t           max_wrkgrp_size;
-    size_t          *max_loc_size;
-#endif
-
-
-    err = clGetDeviceInfo(device_id, CL_DEVICE_NAME, sizeof(device_name), &device_name, NULL);
-    if (err != CL_SUCCESS)
-    {
-        printf("Error: Failed to access device name!\n");
-        return EXIT_FAILURE;
-    }
-    printf(" \n Device is  %s \n",device_name);
-
-    err = clGetDeviceInfo(device_id, CL_DEVICE_TYPE, sizeof(device_type), &device_type, NULL);
-    if (err != CL_SUCCESS)
-    {
-        printf("Error: Failed to access device type information!\n");
-        return EXIT_FAILURE;
-    }
-    err = clGetDeviceInfo(device_id, CL_DEVICE_VENDOR, sizeof(vendor_name), &vendor_name, NULL);
-    if (err != CL_SUCCESS)
-    {
-        printf("Error: Failed to access device vendor name!\n");
-        return EXIT_FAILURE;
-    }
-    printf(" %s \n",vendor_name);
-
-    err = clGetDeviceInfo(device_id, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &comp_units, NULL);
-    if (err != CL_SUCCESS)
-    {
-        printf("Error: Failed to access device number of compute units !\n");
-        return EXIT_FAILURE;
-    }
-
-#ifdef VERBOSE
-    err = clGetDeviceInfo( device_id, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), 
-                               &max_work_itm_dims, NULL);
-    if (err != CL_SUCCESS)
-    {
-        printf("Error: Failed to get device Info (CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS)!\n",
-                                                                            err_code(err));
-        return EXIT_FAILURE;
-    }
-    
-    max_loc_size = (size_t*)malloc(max_work_itm_dims * sizeof(size_t));
-    if(max_loc_size == NULL){
-       printf(" malloc failed\n");
-       return EXIT_FAILURE;
-    }
-    err = clGetDeviceInfo( device_id, CL_DEVICE_MAX_WORK_ITEM_SIZES, max_work_itm_dims* sizeof(size_t), 
-                               max_loc_size, NULL);
-    if (err != CL_SUCCESS)
-    {
-        printf("Error: Failed to get device Info (CL_DEVICE_MAX_WORK_ITEM_SIZES)!\n",err_code(err));
-        return EXIT_FAILURE;
-    }
-    err = clGetDeviceInfo( device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), 
-                               &max_wrkgrp_size, NULL);
-    if (err != CL_SUCCESS)
-    {
-        printf("Error: Failed to get device Info (CL_DEVICE_MAX_WORK_GROUP_SIZE)!\n",err_code(err));
-        return EXIT_FAILURE;
-    }
-   printf("work group, work item information");
-   printf("\n max loc dim ");
-   for(int i=0; i< max_work_itm_dims; i++)
-     printf(" %d ",(int)(*(max_loc_size+i)));
-   printf("\n");
-   printf(" Max work group size = %d\n",(int)max_wrkgrp_size);
-#endif
-
-    return CL_SUCCESS;
-
-}
-
-
-void fatal(char *s)
-{
-  fprintf(stderr, "Error: %s\n", s);
-}
-
-char *load_kernel_source(const char *filename) {
-    // Open the source file
-    FILE *file = fopen(filename, "r");
-    if (file == NULL) fatal("Error opening kernel source file\n");
-
-    // Determine the size of the file
-    if (fseek(file, 0, SEEK_END)) fatal("Error reading kernel source file\n");
-    size_t size = ftell(file);
-
-    // Allocate space for the source code (plus one for null-terminator)
-    char *source = (char *) malloc(size + 1);
-
-    // Read the source code into the string
-    fseek(file, 0, SEEK_SET);
-    // printf("Number of elements: %lu\nSize = %lu", fread(source, 1, size, file), size);
-    // exit(1);
-    if (fread(source, 1, size, file) != size) fatal("Error reading kernel source file\n");
-
-    // Null-terminate the string
-    source[size] = '\0';
-
-    // Return the pointer to the string
-    return source;
-}
-
-void readinput(float *vect, int grid_rows, int grid_cols, int layers, char *file) {
-
-    int i,j,k;
-    FILE *fp;
-    char str[STR_SIZE];
-    float val;
-
-    if( (fp  = fopen(file, "r" )) ==0 )
-      fatal( "The file was not opened" );
-
-
-    for (i=0; i <= grid_rows-1; i++) 
-      for (j=0; j <= grid_cols-1; j++)
-        for (k=0; k <= layers-1; k++)
-          {
-            if (fgets(str, STR_SIZE, fp) == NULL) fatal("Error reading file\n");
-            if (feof(fp))
-              fatal("not enough lines in file");
-            //if ((sscanf(str, "%d%f", &index, &val) != 2) || (index != ((i-1)*(grid_cols-2)+j-1)))
-            if ((sscanf(str, "%f", &val) != 1))
-              fatal("invalid file format");
-            vect[i*grid_cols+j+k*grid_rows*grid_cols] = val;
-          }
-
-    fclose(fp);	
-
-}
-
-
-void writeoutput(float *vect, int grid_rows, int grid_cols, int layers, char *file) {
-
-    int i,j,k, index=0;
-    FILE *fp;
-    char str[STR_SIZE];
-
-    if( (fp = fopen(file, "w" )) == 0 )
-      printf( "The file was not opened\n" );
-
-
-    for (i=0; i < grid_rows; i++) 
-      for (j=0; j < grid_cols; j++)
-        for (k=0; k < layers; k++)
-
-          {
-            sprintf(str, "%d\t%g\n", index, vect[i*grid_cols+j+k*grid_rows*grid_cols]);
-            fputs(str,fp);
-            index++;
-          }
-
-    fclose(fp);	
-}
-
-void computeTempCPU(float *pIn, float* tIn, float *tOut, 
-        int nx, int ny, int nz, float Cap, 
-        float Rx, float Ry, float Rz, 
-        float dt, float amb_temp, int numiter) 
-{   float ce, cw, cn, cs, ct, cb, cc;
-    float stepDivCap = dt / Cap;
-    ce = cw =stepDivCap/ Rx;
-    cn = cs =stepDivCap/ Ry;
-    ct = cb =stepDivCap/ Rz;
-
-    cc = 1.0 - (2.0*ce + 2.0*cn + 3.0*ct);
-
-    int c,w,e,n,s,b,t;
-    int x,y,z;
-    int i = 0;
-    do{
-        for(z = 0; z < nz; z++)
-            for(y = 0; y < ny; y++)
-                for(x = 0; x < nx; x++)
-                {
-                    c = x + y * nx + z * nx * ny;
-
-                    w = (x == 0) ? c : c - 1;
-                    e = (x == nx - 1) ? c : c + 1;
-                    n = (y == 0) ? c : c - nx;
-                    s = (y == ny - 1) ? c : c + nx;
-                    b = (z == 0) ? c : c - nx * ny;
-                    t = (z == nz - 1) ? c : c + nx * ny;
-
-
-                    tOut[c] = tIn[c]*cc + tIn[n]*cn + tIn[s]*cs + tIn[e]*ce + tIn[w]*cw + tIn[t]*ct + tIn[b]*cb + (dt/Cap) * pIn[c] + ct*amb_temp;
-                }
-        float *temp = tIn;
-        tIn = tOut;
-        tOut = temp; 
-        i++;
-    }
-    while(i < numiter);
-
-}
-
-float accuracy(float *arr1, float *arr2, int len)
-{
-    float err = 0.0; 
-    int i;
-    for(i = 0; i < len; i++)
-    {
-        err += (arr1[i]-arr2[i]) * (arr1[i]-arr2[i]);
-    }
-
-    return (float)sqrt(err/len);
-}
- 
-
-

+ 0 - 18
opencl/hotspot3D/CL_helper.h

@@ -1,18 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <CL/cl.h>
-
-char  *err_code(cl_int err_in);
-int   output_device_info(cl_device_id device_id);
-void  fatal(char* s);
-void  readinput(float* v, int r, int c,int l,char*);
-void  writeoutput(float* v,int r,int c,int l,char*);
-char* load_kernel_source(const char* filename);
-long long get_time(); 
-float accuracy(float* arr1, float* arr2, int len);
-void computeTempCPU(float* pIn, float *tIn, float *tOut, 
-               int nx, int ny, int nz, float Cap,
-               float Rx, float Ry, float Rz, 
-               float dt, float amb_temp, int numiter); 

+ 0 - 17
opencl/hotspot3D/Makefile

@@ -1,17 +0,0 @@
-ifndef CC
-	CC = gcc
-endif
-
-OUTPUT = *.out
-CCFLAGS=-O3 -lm 
-
-LIBS = -lOpenCL 
-OPENCL_DIR = /if10/kw5na/Packages/AMD-APP-SDK-v2.8-RC-lnx64
-OPENCL_INC = $(OPENCL_DIR)/include/ 
-OPENCL_LIB = $(OPENCL_DIR)/lib/x86_64/ -lOpenCL
-
-3D: 3D.c CL_helper.c
-	$(CC) $^ $(CCFLAGS) $(LIBS) -I$(OPENCL_INC) -L$(OPENCL_LIB) -o $@
-
-clean:
-	rm -f 3D $(OUTPUT) 

+ 0 - 50
opencl/hotspot3D/hotspotKernel.cl

@@ -1,50 +0,0 @@
-__kernel void hotspotOpt1(__global float *p, __global float* tIn, __global float *tOut, float sdc,
-                            int nx, int ny, int nz,
-                            float ce, float cw, 
-                            float cn, float cs,
-                            float ct, float cb, 
-                            float cc) 
-{
-  float amb_temp = 80.0;
-
-  int i = get_global_id(0);
-  int j = get_global_id(1);
-  int c = i + j * nx;
-  int xy = nx * ny;
-
-  int W = (i == 0)        ? c : c - 1;
-  int E = (i == nx-1)     ? c : c + 1;
-  int N = (j == 0)        ? c : c - nx;
-  int S = (j == ny-1)     ? c : c + nx;
-
-  float temp1, temp2, temp3;
-  temp1 = temp2 = tIn[c];
-  temp3 = tIn[c+xy];
-  tOut[c] = cc * temp2 + cw * tIn[W] + ce * tIn[E] + cs * tIn[S]
-    + cn * tIn[N] + cb * temp1 + ct * temp3 + sdc * p[c] + ct * amb_temp;
-  c += xy;
-  W += xy;
-  E += xy;
-  N += xy;
-  S += xy;
-
-  for (int k = 1; k < nz-1; ++k) {
-      temp1 = temp2;
-      temp2 = temp3;
-      temp3 = tIn[c+xy];
-      tOut[c] = cc * temp2 + cw * tIn[W] + ce * tIn[E] + cs * tIn[S]
-        + cn * tIn[N] + cb * temp1 + ct * temp3 + sdc * p[c] + ct * amb_temp;
-      c += xy;
-      W += xy;
-      E += xy;
-      N += xy;
-      S += xy;
-  }
-  temp1 = temp2;
-  temp2 = temp3;
-  tOut[c] = cc * temp2 + cw * tIn[W] + ce * tIn[E] + cs * tIn[S]
-    + cn * tIn[N] + cb * temp1 + ct * temp3 + sdc * p[c] + ct * amb_temp;
-  return;
-}
-
-

+ 0 - 1
opencl/hotspot3D/run

@@ -1 +0,0 @@
-./3D 512 8 100 ../../data/hotspot3D/power_512x8 ../../data/hotspot3D/temp_512x8 output.out

+ 0 - 121
opencl/myocyte/Makefile

@@ -1,121 +0,0 @@
-include ../../common/make.config
-#	COMPILER
-# ======================================================================================================================================================150
-C_C = gcc
-OCL_LIB = -lOpenCL
-
-# ======================================================================================================================================================150
-#	END
-# ======================================================================================================================================================150
-
-# ========================================================================================================================================================================================================200
-#	EXECUTABLES (LINK OBJECTS TOGETHER INTO BINARY)
-# ========================================================================================================================================================================================================200
-
-./myocyte.out:	./main.o \
-			./kernel/kernel_gpu_opencl_wrapper.o \
-			./util/file/file.o \
-			./util/num/num.o \
-			./util/timer/timer.o \
-			./util/opencl/opencl.o
-	$(C_C)	./main.o \
-			./kernel/kernel_gpu_opencl_wrapper.o \
-			./util/file/file.o \
-			./util/num/num.o \
-			./util/timer/timer.o \
-			./util/opencl/opencl.o \
-			-I$(OPENCL_INC) \
-			-lm \
-			-L$(OPENCL_LIB) \
-                        $(OCL_LIB) \
-                        -o myocyte.out
-# ========================================================================================================================================================================================================200
-#	OBJECTS (COMPILE SOURCE FILES INTO OBJECTS)
-# ========================================================================================================================================================================================================200
-
-# ======================================================================================================================================================150
-#	MAIN FUNCTION
-# ======================================================================================================================================================150
-
-./main.o:	./common.h \
-			./main.h \
-			./main.c
-	$(C_C)	./main.c \
-			-c \
-			-o ./main.o \
-			-O3 \
-			-g
-
-# ======================================================================================================================================================150
-#	KERNELS
-# ======================================================================================================================================================150
-
-./kernel/kernel_gpu_opencl_wrapper.o:	./common.h \
-										./kernel/kernel_gpu_opencl_wrapper.h \
-										./kernel/kernel_gpu_opencl_wrapper.c \
-										./kernel/solver.c \
-										./kernel/embedded_fehlberg_7_8.c \
-										./kernel/master.c \
-										./kernel/kernel_gpu_opencl.cl
-	$(C_C)	./kernel/kernel_gpu_opencl_wrapper.c \
-			-c \
-			-o ./kernel/kernel_gpu_opencl_wrapper.o \
-			-I$(OPENCL_INC) \
-			-O3
-
-# ======================================================================================================================================================150
-#	UTILITIES
-# ======================================================================================================================================================150
-
-./util/file/file.o:	./common.h \
-					./util/file/file.h \
-					./util/file/file.c
-	$(C_C)	./util/file/file.c \
-			-c \
-			-o ./util/file/file.o \
-			-O3
-
-./util/num/num.o:	./common.h \
-					./util/num/num.h \
-					./util/num/num.c
-	$(C_C)	./util/num/num.c \
-			-c \
-			-o ./util/num/num.o \
-			-O3
-
-./util/timer/timer.o:	./common.h \
-						./util/timer/timer.h \
-						./util/timer/timer.c
-	$(C_C)	./util/timer/timer.c \
-			-c \
-			-o ./util/timer/timer.o \
-			-O3
-
-./util/opencl/opencl.o:	./common.h \
-						./util/opencl/opencl.h \
-						./util/opencl/opencl.c
-	$(C_C)	-I$(OPENCL_INC) \
-		./util/opencl/opencl.c \
-			-c \
-			-o ./util/opencl/opencl.o \
-			-O3
-
-# ======================================================================================================================================================150
-#	END
-# ======================================================================================================================================================150
-
-# ========================================================================================================================================================================================================200
-#	DELETE
-# ========================================================================================================================================================================================================200
-
-clean:
-	rm	*.o *.out \
-		./kernel/*.o \
-		./util/file/*.o \
-		./util/timer/*.o \
-		./util/opencl/*.o \
-                ./util/num/*.o \
-                ./output.txt
-# ========================================================================================================================================================================================================200
-#	END
-# ========================================================================================================================================================================================================200

+ 0 - 78
opencl/myocyte/README

@@ -1,78 +0,0 @@
-//========================================================================================================================================================================================================200
-//	UPDATE
-//========================================================================================================================================================================================================200
-
-// Lukasz G. Szafaryn 24 JAN 09
-
-//========================================================================================================================================================================================================200
-//	DESCRIPTION
-//========================================================================================================================================================================================================200
-
-// Myocyte application models cardiac myocyte (heart muscle cell) and simulates its behavior according to the work by Saucerman and Bers [8]. The model integrates 
-// cardiac myocyte electrical activity with the calcineurin pathway, which is a key aspect of the development of heart failure. The model spans large number of temporal 
-// scales to reflect how changes in heart rate as observed during exercise or stress contribute to calcineurin pathway activation, which ultimately leads to the expression 
-// of numerous genes that remodel the heart’s structure. It can be used to identify potential therapeutic targets that may be useful for the treatment of heart failure. 
-// Biochemical reactions, ion transport and electrical activity in the cell are modeled with 91 ordinary differential equations (ODEs) that are determined by more than 200 
-// experimentally validated parameters. The model is simulated by solving this group of ODEs for a specified time interval. The process of ODE solving is based on the 
-// causal relationship between values of ODEs at different time steps, thus it is mostly sequential. At every dynamically determined time step, the solver evaluates the 
-// model consisting of a set of 91 ODEs and 480 supporting equations to determine behavior of the system at that particular time instance. If evaluation results are not 
-// within the expected tolerance at a given time step (usually as a result of incorrect determination of the time step), another calculation attempt is made at a modified 
-// (usually reduced) time step. Since the ODEs are stiff (exhibit fast rate of change within short time intervals), they need to be simulated at small time scales with an 
-// adaptive step size solver. 
-
-//	1) The original version of the current solver code was obtained from: Mathematics Source Library (http://mymathlib.webtrellis.net/index.html). The solver has been 
-//      somewhat modified to tailor it to our needs. However, it can be reverted back to original form or modified to suit other simulations.
-// 2) This solver and particular solving algorithm used with it (embedded_fehlberg_7_8) were adapted to work with a set of equations, not just one like in original version.
-//	3) In order for solver to provide deterministic number of steps (needed for particular amount of memore previousely allocated for results), every next step is 
-//      incremented by 1 time unit (h_init).
-//	4) Function assumes that simulation starts at some point of time (whatever time the initial values are provided for) and runs for the number of miliseconds (xmax) 
-//      specified by the uses as a parameter on command line.
-// 5) The appropriate amount of memory is previousely allocated for that range (y).
-//	6) This setup in 3) - 5) allows solver to adjust the step ony from current time instance to current time instance + 0.9. The next time instance is current time instance + 1;
-//	7) The original solver cannot handle cases when equations return NAN and INF values due to discontinuities and /0. That is why equations provided by user need to 
-//      make sure that no NAN and INF are returned.
-// 8) Application reads initial data and parameters from text files: y.txt and params.txt respectively that need to be located in the same folder as source files. 
-//     For simplicity and testing purposes only, when multiple number of simulation instances is specified, application still reads initial data from the same input files. That 
-//     can be modified in this source code.
-
-//========================================================================================================================================================================================================200
-//	IMPLEMENTATION-SPECIFIC DESCRIPTION (CUDA)
-//========================================================================================================================================================================================================200
-
-// This is the CUDA version of Myocyte code.
-
-// The original single-threaded code was written in MATLAB and used MATLAB ode45 ODE solver. In the process of accelerating this code, we arrived with the 
-// intermediate versions that used single-threaded Sundials CVODE solver which evaluated model parallelized with CUDA at each time step. In order to convert entire 
-// solver to CUDA code (to remove some of the operational overheads such as kernel launches and data transfer in CUDA) we used a simpler solver, from Mathematics 
-// Source Library, and tailored it to our needs. The parallelism in the cardiac myocyte model is on a very fine-grained level, close to that of ILP, therefore it is very hard 
-// to exploit as DLP or TLB in CUDA code. We were able to divide the model into 4 individual groups that run in parallel. However, even that is not enough work to 
-// compensate for some of the CUDA thread launch and data transfer overheads which resulted in performance worse than that of single-threaded C code. Speedup in 
-// this code could be achieved only if a customizable accelerator such as FPGA was used for evaluation of the model itself. We also approached the application from 
-// another angle and allowed it to run several concurrent simulations, thus turning it into an embarrassingly parallel problem. This version of the code is also useful for 
-// scientists who want to run the same simulation with different sets of input parameters. Speedup achieved with CUDA code is variable on the other hand. It depends on 
-// the number of concurrent simulations and it saturates around 300 simulations with the speedup of about 10x.
-
-// Speedup numbers reported in the description of this application were obtained on the machine with: Intel Quad Core CPU, 4GB of RAM, Nvidia GTX280 GPU.  
-
-// 1) When running with parallelization inside each simulation instance (value of 3rd command line parameter equal to 0), performance is bad because:
-// a) underutilization of GPU (only 1 out of 32 threads in each block)
-// b) significant CPU-GPU memory copy overhead
-// c) kernel launch overhead (kernel needs to be finished every time model is evaluated as it is the only way to synchronize threads in different blocks)
-// 2) When running with parallelization across simulation instances, code gets continues speedup with the increasing number of simulation insances which saturates
-//     around 240 instances on GTX280 (roughly corresponding to the number of multiprocessorsXprocessors in GTX280), with the speedup of around 10x compared
-//     to serial C version of code. Limited performance is explained mainly by:
-// a) significant CPU-GPU memory copy overhead
-// b) increasingly uncoalesced memory accesses with the increasing number of workloads
-// c) lack of cache compared to CPU, or no use of shared memory to compensate
-// d) frequency of GPU shader being lower than that of CPU core
-// 3) GPU version has an issue with memory allocation that has not been resolved yet. For certain simulation ranges memory allocation fails, or pointers incorrectly overlap 
-//     causeing value trashing.
-
-// The following are the command parameters to the application:
-// 1) Simulation time interval which is the number of miliseconds to simulate. Needs to be integer > 0
-// Example:
-// ./a.out -time 100
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200

+ 0 - 22
opencl/myocyte/common.h

@@ -1,22 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE
-//========================================================================================================================================================================================================200
-
-#define fp float
-
-#define NUMBER_THREADS 2
-
-#define EQUATIONS 91
-#define PARAMETERS 18
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 612
opencl/myocyte/kernel/embedded_fehlberg_7_8.c

@@ -1,612 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DESCRIPTION
-//========================================================================================================================================================================================================200
-
-////////////////////////////////////////////////////////////////////////////////
-// File: embedded_fehlberg_7_8.c                                              //
-// Routines:                                                                  //
-//    Embedded_Fehlberg_7_8                                                   //
-////////////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////////////
-//                                                                            //
-//  Description:                                                              //
-//     The Runge-Kutta-Fehlberg method is an adaptive procedure for approxi-  //
-//     mating the solution of the differential equation y'(x) = f(x,y) with   //
-//     initial condition y(x0) = c.  This implementation evaluates f(x,y)     //
-//     thirteen times per step using embedded seventh order and eight order   //
-//     Runge-Kutta estimates to estimate the not only the solution but also   //
-//     the error.                                                             //
-//     The next step size is then calculated using the preassigned tolerance  //
-//     and error estimate.                                                    //
-//     For step i+1,                                                          //
-//        y[i+1] = y[i] +  h * (41/840 * k1 + 34/105 * finavalu_temp[5] + 9/35 * finavalu_temp[6]         //
-//                        + 9/35 * finavalu_temp[7] + 9/280 * finavalu_temp[8] + 9/280 finavalu_temp[9] + 41/840 finavalu_temp[10] ) //
-//     where                                                                  //
-//     k1 = f( x[i],y[i] ),                                                   //
-//     finavalu_temp[1] = f( x[i]+2h/27, y[i] + 2h*k1/27),                                  //
-//     finavalu_temp[2] = f( x[i]+h/9, y[i]+h/36*( k1 + 3 finavalu_temp[1]) ),                            //
-//     finavalu_temp[3] = f( x[i]+h/6, y[i]+h/24*( k1 + 3 finavalu_temp[2]) ),                            //
-//     finavalu_temp[4] = f( x[i]+5h/12, y[i]+h/48*(20 k1 - 75 finavalu_temp[2] + 75 finavalu_temp[3])),                //
-//     finavalu_temp[5] = f( x[i]+h/2, y[i]+h/20*( k1 + 5 finavalu_temp[3] + 4 finavalu_temp[4] ) ),                    //
-//     finavalu_temp[6] = f( x[i]+5h/6, y[i]+h/108*( -25 k1 + 125 finavalu_temp[3] - 260 finavalu_temp[4] + 250 finavalu_temp[5] ) ), //
-//     finavalu_temp[7] = f( x[i]+h/6, y[i]+h*( 31/300 k1 + 61/225 finavalu_temp[4] - 2/9 finavalu_temp[5]              //
-//                                                            + 13/900 finavalu_temp[6]) )  //
-//     finavalu_temp[8] = f( x[i]+2h/3, y[i]+h*( 2 k1 - 53/6 finavalu_temp[3] + 704/45 finavalu_temp[4] - 107/9 finavalu_temp[5]      //
-//                                                      + 67/90 finavalu_temp[6] + 3 finavalu_temp[7]) ), //
-//     finavalu_temp[9] = f( x[i]+h/3, y[i]+h*( -91/108 k1 + 23/108 finavalu_temp[3] - 976/135 finavalu_temp[4]        //
-//                             + 311/54 finavalu_temp[5] - 19/60 finavalu_temp[6] + 17/6 finavalu_temp[7] - 1/12 finavalu_temp[8]) ), //
-//     finavalu_temp[10] = f( x[i]+h, y[i]+h*( 2383/4100 k1 - 341/164 finavalu_temp[3] + 4496/1025 finavalu_temp[4]     //
-//          - 301/82 finavalu_temp[5] + 2133/4100 finavalu_temp[6] + 45/82 finavalu_temp[7] + 45/164 finavalu_temp[8] + 18/41 finavalu_temp[9]) )  //
-//     finavalu_temp[11] = f( x[i], y[i]+h*( 3/205 k1 - 6/41 finavalu_temp[5] - 3/205 finavalu_temp[6] - 3/41 finavalu_temp[7]        //
-//                                                   + 3/41 finavalu_temp[8] + 6/41 finavalu_temp[9]) )  //
-//     finavalu_temp[12] = f( x[i]+h, y[i]+h*( -1777/4100 k1 - 341/164 finavalu_temp[3] + 4496/1025 finavalu_temp[4]    //
-//                      - 289/82 finavalu_temp[5] + 2193/4100 finavalu_temp[6] + 51/82 finavalu_temp[7] + 33/164 finavalu_temp[8] +   //
-//                                                        12/41 finavalu_temp[9] + finavalu_temp[11]) )  //
-//     x[i+1] = x[i] + h.                                                     //
-//                                                                            //
-//     The error is estimated to be                                           //
-//        err = -41/840 * h * ( k1 + finavalu_temp[10] - finavalu_temp[11] - finavalu_temp[12])                         //
-//     The step size h is then scaled by the scale factor                     //
-//         scale = 0.8 * | epsilon * y[i] / [err * (xmax - x[0])] | ^ 1/7     //
-//     The scale factor is further constrained 0.125 < scale < 4.0.           //
-//     The new step size is h := scale * h.                                   //
-////////////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////////////
-//  static fp Runge_Kutta(fp (*f)(fp,fp), fp *y, fp x0, fp h)                 //
-//                                                                            //
-//  Description:                                                              //
-//     This routine uses Fehlberg's embedded 7th and 8th order methods to     //
-//     approximate the solution of the differential equation y'=f(x,y) with   //
-//     the initial condition y = y[0] at x = x0.  The value at x + h is       //
-//     returned in y[1].  The function returns err / h ( the absolute error   //
-//     per step size ).                                                       //
-//                                                                            //
-//  Arguments:                                                                //
-//     fp *f  Pointer to the function which returns the slope at (x,y) of     //
-//                integral curve of the differential equation y' = f(x,y)     //
-//                which passes through the point (x0,y[0]).                   //
-//     fp y[] On input y[0] is the initial value of y at x, on output         //
-//                y[1] is the solution at x + h.                              //
-//     fp x   Initial value of x.                                             //
-//     fp h   Step size                                                       //
-//                                                                            //
-//  Return Values:                                                            //
-//     This routine returns the err / h.  The solution of y(x) at x + h is    //
-//     returned in y[1].                                                      //
-//                                                                            //
-////////////////////////////////////////////////////////////////////////////////
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	KERNEL
-//======================================================================================================================================================150
-
-#include "master.c"															// (in directory)
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <math.h>															// (in path provided to compiler)	needed by pow, fabs
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	PARTICULAR SOLVER FUNCTION
-//========================================================================================================================================================================================================200
-
-void 
-embedded_fehlberg_7_8(	fp timeinst,
-						fp h,
-						fp *initvalu,
-						fp *finavalu,
-						fp *error,
-						fp *parameter,
-						fp *com,
-
-						cl_mem d_initvalu,
-						cl_mem d_finavalu,
-						cl_mem d_params,
-						cl_mem d_com,
-
-						cl_command_queue command_queue,
-						cl_kernel kernel,
-
-						long long *timecopyin,
-						long long *timecopykernel,
-						long long *timecopyout) 
-{
-
-	//======================================================================================================================================================
-	//	VARIABLES
-	//======================================================================================================================================================
-
-	static const fp c_1_11 = 41.0 / 840.0;
-	static const fp c6 = 34.0 / 105.0;
-	static const fp c_7_8= 9.0 / 35.0;
-	static const fp c_9_10 = 9.0 / 280.0;
-
-	static const fp a2 = 2.0 / 27.0;
-	static const fp a3 = 1.0 / 9.0;
-	static const fp a4 = 1.0 / 6.0;
-	static const fp a5 = 5.0 / 12.0;
-	static const fp a6 = 1.0 / 2.0;
-	static const fp a7 = 5.0 / 6.0;
-	static const fp a8 = 1.0 / 6.0;
-	static const fp a9 = 2.0 / 3.0;
-	static const fp a10 = 1.0 / 3.0;
-
-	static const fp b31 = 1.0 / 36.0;
-	static const fp b32 = 3.0 / 36.0;
-	static const fp b41 = 1.0 / 24.0;
-	static const fp b43 = 3.0 / 24.0;
-	static const fp b51 = 20.0 / 48.0;
-	static const fp b53 = -75.0 / 48.0;
-	static const fp b54 = 75.0 / 48.0;
-	static const fp b61 = 1.0 / 20.0;
-	static const fp b64 = 5.0 / 20.0;
-	static const fp b65 = 4.0 / 20.0;
-	static const fp b71 = -25.0 / 108.0;
-	static const fp b74 =  125.0 / 108.0;
-	static const fp b75 = -260.0 / 108.0;
-	static const fp b76 =  250.0 / 108.0;
-	static const fp b81 = 31.0/300.0;
-	static const fp b85 = 61.0/225.0;
-	static const fp b86 = -2.0/9.0;
-	static const fp b87 = 13.0/900.0;
-	static const fp b91 = 2.0;
-	static const fp b94 = -53.0/6.0;
-	static const fp b95 = 704.0 / 45.0;
-	static const fp b96 = -107.0 / 9.0;
-	static const fp b97 = 67.0 / 90.0;
-	static const fp b98 = 3.0;
-	static const fp b10_1 = -91.0 / 108.0;
-	static const fp b10_4 = 23.0 / 108.0;
-	static const fp b10_5 = -976.0 / 135.0;
-	static const fp b10_6 = 311.0 / 54.0;
-	static const fp b10_7 = -19.0 / 60.0;
-	static const fp b10_8 = 17.0 / 6.0;
-	static const fp b10_9 = -1.0 / 12.0;
-	static const fp b11_1 = 2383.0 / 4100.0;
-	static const fp b11_4 = -341.0 / 164.0;
-	static const fp b11_5 = 4496.0 / 1025.0;
-	static const fp b11_6 = -301.0 / 82.0;
-	static const fp b11_7 = 2133.0 / 4100.0;
-	static const fp b11_8 = 45.0 / 82.0;
-	static const fp b11_9 = 45.0 / 164.0;
-	static const fp b11_10 = 18.0 / 41.0;
-	static const fp b12_1 = 3.0 / 205.0;
-	static const fp b12_6 = - 6.0 / 41.0;
-	static const fp b12_7 = - 3.0 / 205.0;
-	static const fp b12_8 = - 3.0 / 41.0;
-	static const fp b12_9 = 3.0 / 41.0;
-	static const fp b12_10 = 6.0 / 41.0;
-	static const fp b13_1 = -1777.0 / 4100.0;
-	static const fp b13_4 = -341.0 / 164.0;
-	static const fp b13_5 = 4496.0 / 1025.0;
-	static const fp b13_6 = -289.0 / 82.0;
-	static const fp b13_7 = 2193.0 / 4100.0;
-	static const fp b13_8 = 51.0 / 82.0;
-	static const fp b13_9 = 33.0 / 164.0;
-	static const fp b13_10 = 12.0 / 41.0;
-
-	static const fp err_factor  = -41.0 / 840.0;
-
-	fp h2_7 = a2 * h;
-
-	fp timeinst_temp;
-	fp* initvalu_temp;
-	fp** finavalu_temp;
-
-	int i;
-
-	//======================================================================================================================================================
-	//		TEMPORARY STORAGE ALLOCATION
-	//======================================================================================================================================================
-
-	initvalu_temp= (fp *) malloc(EQUATIONS* sizeof(fp));
-
-	finavalu_temp= (fp **) malloc(13* sizeof(fp *));
-	for (i= 0; i<13; i++){
-		finavalu_temp[i]= (fp *) malloc(EQUATIONS* sizeof(fp));
-	}
-
-	//======================================================================================================================================================
-	//		EVALUATIONS	[UNROLLED LOOP] [SEQUENTIAL DEPENDENCY]
-	//======================================================================================================================================================
-
-	//===================================================================================================
-	//		1
-	//===================================================================================================
-
-	timeinst_temp = timeinst;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] ;
-		// printf("initvalu[%d] = %f\n", i, initvalu[i]);
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[0],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		2
-	//===================================================================================================
-
-	timeinst_temp = timeinst+h2_7;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h2_7 * (finavalu_temp[0][i]);
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[1],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,\
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		3
-	//===================================================================================================
-
-	timeinst_temp = timeinst+a3*h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b31*finavalu_temp[0][i] + b32*finavalu_temp[1][i]);
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[2],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		4
-	//===================================================================================================
-
-	timeinst_temp = timeinst+a4*h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b41*finavalu_temp[0][i] + b43*finavalu_temp[2][i]) ;
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[3],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		5
-	//===================================================================================================
-
-	timeinst_temp = timeinst+a5*h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b51*finavalu_temp[0][i] + b53*finavalu_temp[2][i] + b54*finavalu_temp[3][i]) ;
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[4],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		6
-	//===================================================================================================
-
-	timeinst_temp = timeinst+a6*h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b61*finavalu_temp[0][i] + b64*finavalu_temp[3][i] + b65*finavalu_temp[4][i]) ;
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[5],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		7
-	//===================================================================================================
-
-	timeinst_temp = timeinst+a7*h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b71*finavalu_temp[0][i] + b74*finavalu_temp[3][i] + b75*finavalu_temp[4][i] + b76*finavalu_temp[5][i]);
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[6],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		8
-	//===================================================================================================
-
-	timeinst_temp = timeinst+a8*h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b81*finavalu_temp[0][i] + b85*finavalu_temp[4][i] + b86*finavalu_temp[5][i] + b87*finavalu_temp[6][i]);
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[7],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		9
-	//===================================================================================================
-
-	timeinst_temp = timeinst+a9*h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b91*finavalu_temp[0][i] + b94*finavalu_temp[3][i] + b95*finavalu_temp[4][i] + b96*finavalu_temp[5][i] + b97*finavalu_temp[6][i]+ b98*finavalu_temp[7][i]) ;
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[8],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		10
-	//===================================================================================================
-
-	timeinst_temp = timeinst+a10*h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b10_1*finavalu_temp[0][i] + b10_4*finavalu_temp[3][i] + b10_5*finavalu_temp[4][i] + b10_6*finavalu_temp[5][i] + b10_7*finavalu_temp[6][i] + b10_8*finavalu_temp[7][i] + b10_9*finavalu_temp[8] [i]) ;
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[9],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		11
-	//===================================================================================================
-
-	timeinst_temp = timeinst+h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b11_1*finavalu_temp[0][i] + b11_4*finavalu_temp[3][i] + b11_5*finavalu_temp[4][i] + b11_6*finavalu_temp[5][i] + b11_7*finavalu_temp[6][i] + b11_8*finavalu_temp[7][i] + b11_9*finavalu_temp[8][i]+ b11_10 * finavalu_temp[9][i]);
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[10],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		12
-	//===================================================================================================
-
-	timeinst_temp = timeinst;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b12_1*finavalu_temp[0][i] + b12_6*finavalu_temp[5][i] + b12_7*finavalu_temp[6][i] + b12_8*finavalu_temp[7][i] + b12_9*finavalu_temp[8][i] + b12_10 * finavalu_temp[9][i]) ;
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[11],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//===================================================================================================
-	//		13
-	//===================================================================================================
-
-	timeinst_temp = timeinst+h;
-	for(i=0; i<EQUATIONS; i++){
-		initvalu_temp[i] = initvalu[i] + h * ( b13_1*finavalu_temp[0][i] + b13_4*finavalu_temp[3][i] + b13_5*finavalu_temp[4][i] + b13_6*finavalu_temp[5][i] + b13_7*finavalu_temp[6][i] + b13_8*finavalu_temp[7][i] + b13_9*finavalu_temp[8][i] + b13_10*finavalu_temp[9][i] + finavalu_temp[11][i]) ;
-	}
-
-	master(	timeinst_temp,
-					initvalu_temp,
-					parameter,
-					finavalu_temp[12],
-					com,
-
-					d_initvalu,
-					d_finavalu,
-					d_params,
-					d_com,
-
-					command_queue,
-					kernel,
-
-					timecopyin,
-					timecopykernel,
-					timecopyout);
-
-	//======================================================================================================================================================
-	//		FINAL VALUE
-	//======================================================================================================================================================
-
-	for(i=0; i<EQUATIONS; i++){
-		finavalu[i]= initvalu[i] +  h * (c_1_11 * (finavalu_temp[0][i] + finavalu_temp[10][i])  + c6 * finavalu_temp[5][i] + c_7_8 * (finavalu_temp[6][i] + finavalu_temp[7][i]) + c_9_10 * (finavalu_temp[8][i] + finavalu_temp[9][i]) );
-	}
-
-	//======================================================================================================================================================
-	//		RETURN
-	//======================================================================================================================================================
-
-	for(i=0; i<EQUATIONS; i++){
-		error[i] = fabs(err_factor * (finavalu_temp[0][i] + finavalu_temp[10][i] - finavalu_temp[11][i] - finavalu_temp[12][i]));
-	}
-
-	//======================================================================================================================================================
-	//		DEALLOCATION
-	//======================================================================================================================================================
-
-	free(initvalu_temp);
-	free(finavalu_temp);
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 136
opencl/myocyte/kernel/kernel_fin.c

@@ -1,136 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	COMMON
-//======================================================================================================================================================150
-
-#include "../common.h"											// (in directory)
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	KERNEL FIN
-//========================================================================================================================================================================================================200
-
-void 
-kernel_fin(	fp *initvalu,
-			int initvalu_offset_ecc,
-			int initvalu_offset_Dyad,
-			int initvalu_offset_SL,
-			int initvalu_offset_Cyt,
-			fp *parameter,
-			fp *finavalu,
-			fp JCaDyad,
-			fp JCaSL,
-			fp JCaCyt){
-
-//=====================================================================
-//	VARIABLES
-//=====================================================================
-
-	// decoded input parameters
-	fp BtotDyad;																		//
-	fp CaMKIItotDyad;																	//
-
-	// compute variables
-	fp Vmyo;																			// [L]
-	fp Vdyad;																			// [L]
-	fp VSL;																				// [L]
-	// fp kDyadSL;																			// [L/msec]
-	fp kSLmyo;																			// [L/msec]
-	fp k0Boff;																			// [s^-1] 
-	fp k0Bon;																			// [uM^-1 s^-1] kon = koff/Kd
-	fp k2Boff;																			// [s^-1] 
-	fp k2Bon;																			// [uM^-1 s^-1]
-	// fp k4Boff;																			// [s^-1]
-	fp k4Bon;																			// [uM^-1 s^-1]
-	fp CaMtotDyad;
-	fp Bdyad;																			// [uM dyad]
-	fp J_cam_dyadSL;																	// [uM/msec dyad]
-	fp J_ca2cam_dyadSL;																	// [uM/msec dyad]
-	fp J_ca4cam_dyadSL;																	// [uM/msec dyad]
-	fp J_cam_SLmyo;																		// [umol/msec]
-	fp J_ca2cam_SLmyo;																	// [umol/msec]
-	fp J_ca4cam_SLmyo;																	// [umol/msec]
-
-//=====================================================================
-//	COMPUTATION
-//=====================================================================
-
-	// decoded input parameters
-	BtotDyad      = parameter[2];														//
-	CaMKIItotDyad = parameter[3];														//
-
-	// set variables
-	Vmyo = 2.1454e-11;																	// [L]
-	Vdyad = 1.7790e-14;																	// [L]
-	VSL = 6.6013e-13;																	// [L]
-	// kDyadSL = 3.6363e-16;																// [L/msec]
-	kSLmyo = 8.587e-15;																	// [L/msec]
-	k0Boff = 0.0014;																	// [s^-1] 
-	k0Bon = k0Boff/0.2;																	// [uM^-1 s^-1] kon = koff/Kd
-	k2Boff = k0Boff/100;																// [s^-1] 
-	k2Bon = k0Bon;																		// [uM^-1 s^-1]
-	// k4Boff = k2Boff;																	// [s^-1]
-	k4Bon = k0Bon;																		// [uM^-1 s^-1]
-
-	// ADJUST ECC incorporate Ca buffering from CaM, convert JCaCyt from uM/msec to mM/msec
-	finavalu[initvalu_offset_ecc+35] = finavalu[initvalu_offset_ecc+35] + 1e-3*JCaDyad;
-	finavalu[initvalu_offset_ecc+36] = finavalu[initvalu_offset_ecc+36] + 1e-3*JCaSL;
-	finavalu[initvalu_offset_ecc+37] = finavalu[initvalu_offset_ecc+37] + 1e-3*JCaCyt; 
-
-	// incorporate CaM diffusion between compartments
-	CaMtotDyad = initvalu[initvalu_offset_Dyad+0]
-			   + initvalu[initvalu_offset_Dyad+1]
-			   + initvalu[initvalu_offset_Dyad+2]
-			   + initvalu[initvalu_offset_Dyad+3]
-			   + initvalu[initvalu_offset_Dyad+4]
-			   + initvalu[initvalu_offset_Dyad+5]
-			   + CaMKIItotDyad * (  initvalu[initvalu_offset_Dyad+6]
-								  + initvalu[initvalu_offset_Dyad+7]
-								  + initvalu[initvalu_offset_Dyad+8]
-								  + initvalu[initvalu_offset_Dyad+9])
-			   + initvalu[initvalu_offset_Dyad+12]
-			   + initvalu[initvalu_offset_Dyad+13]
-			   + initvalu[initvalu_offset_Dyad+14];
-	Bdyad = BtotDyad - CaMtotDyad;																				// [uM dyad]
-	J_cam_dyadSL = 1e-3 * (  k0Boff*initvalu[initvalu_offset_Dyad+0] - k0Bon*Bdyad*initvalu[initvalu_offset_SL+0]);			// [uM/msec dyad]
-	J_ca2cam_dyadSL = 1e-3 * (  k2Boff*initvalu[initvalu_offset_Dyad+1] - k2Bon*Bdyad*initvalu[initvalu_offset_SL+1]);		// [uM/msec dyad]
-	J_ca4cam_dyadSL = 1e-3 * (  k2Boff*initvalu[initvalu_offset_Dyad+2] - k4Bon*Bdyad*initvalu[initvalu_offset_SL+2]);		// [uM/msec dyad]
-	
-	J_cam_SLmyo = kSLmyo * (  initvalu[initvalu_offset_SL+0] - initvalu[initvalu_offset_Cyt+0]);								// [umol/msec]
-	J_ca2cam_SLmyo = kSLmyo * (  initvalu[initvalu_offset_SL+1] - initvalu[initvalu_offset_Cyt+1]);							// [umol/msec]
-	J_ca4cam_SLmyo = kSLmyo * (  initvalu[initvalu_offset_SL+2] - initvalu[initvalu_offset_Cyt+2]);							// [umol/msec]
-	
-	// ADJUST CAM Dyad 
-	finavalu[initvalu_offset_Dyad+0] = finavalu[initvalu_offset_Dyad+0] - J_cam_dyadSL;
-	finavalu[initvalu_offset_Dyad+1] = finavalu[initvalu_offset_Dyad+1] - J_ca2cam_dyadSL;
-	finavalu[initvalu_offset_Dyad+2] = finavalu[initvalu_offset_Dyad+2] - J_ca4cam_dyadSL;
-	
-	// ADJUST CAM Sl
-	finavalu[initvalu_offset_SL+0] = finavalu[initvalu_offset_SL+0] + J_cam_dyadSL*Vdyad/VSL - J_cam_SLmyo/VSL;
-	finavalu[initvalu_offset_SL+1] = finavalu[initvalu_offset_SL+1] + J_ca2cam_dyadSL*Vdyad/VSL - J_ca2cam_SLmyo/VSL;
-	finavalu[initvalu_offset_SL+2] = finavalu[initvalu_offset_SL+2] + J_ca4cam_dyadSL*Vdyad/VSL - J_ca4cam_SLmyo/VSL;
-
-	// ADJUST CAM Cyt 
-	finavalu[initvalu_offset_Cyt+0] = finavalu[initvalu_offset_Cyt+0] + J_cam_SLmyo/Vmyo;
-	finavalu[initvalu_offset_Cyt+1] = finavalu[initvalu_offset_Cyt+1] + J_ca2cam_SLmyo/Vmyo;
-	finavalu[initvalu_offset_Cyt+2] = finavalu[initvalu_offset_Cyt+2] + J_ca4cam_SLmyo/Vmyo;
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 1445
opencl/myocyte/kernel/kernel_gpu_opencl.cl

@@ -1,1445 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	DEFINE (need to define because cannot include ../common.h file for some reason
-//======================================================================================================================================================150
-
-#define fp float
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	KERNEL_ECC
-//========================================================================================================================================================================================================200
-
-void 
-kernel_ecc(	fp timeinst,
-			__global fp *d_initvalu,
-			__global fp *d_finavalu,
-			int valu_offset,
-			__global fp *d_params){
-
-	//=====================================================================
-	//	VARIABLES														
-	//=====================================================================
-
-	// input parameters
-	fp cycleLength;
-
-	// variable references				// GET VARIABLES FROM MEMORY AND SAVE LOCALLY !!!!!!!!!!!!!!!!!!
-	int offset_1;
-	int offset_2;
-	int offset_3;
-	int offset_4;
-	int offset_5;
-	int offset_6;
-	int offset_7;
-	int offset_8;
-	int offset_9;
-	int offset_10;
-	int offset_11;
-	int offset_12;
-	int offset_13;
-	int offset_14;
-	int offset_15;
-	int offset_16;
-	int offset_17;
-	int offset_18;
-	int offset_19;
-	int offset_20;
-	int offset_21;
-	int offset_22;
-	int offset_23;
-	int offset_24;
-	int offset_25;
-	int offset_26;
-	int offset_27;
-	int offset_28;
-	int offset_29;
-	int offset_30;
-	int offset_31;
-	int offset_32;
-	int offset_33;
-	int offset_34;
-	int offset_35;
-	int offset_36;
-	int offset_37;
-	int offset_38;
-	int offset_39;
-	int offset_40;
-	int offset_41;
-	int offset_42;
-	int offset_43;
-	int offset_44;
-	int offset_45;
-	int offset_46;
-
-	// stored input array
-	fp d_initvalu_1;
-	fp d_initvalu_2;
-	fp d_initvalu_3;
-	fp d_initvalu_4;
-	fp d_initvalu_5;
-	fp d_initvalu_6;
-	fp d_initvalu_7;
-	fp d_initvalu_8;
-	fp d_initvalu_9;
-	fp d_initvalu_10;
-	fp d_initvalu_11;
-	fp d_initvalu_12;
-	fp d_initvalu_13;
-	fp d_initvalu_14;
-	fp d_initvalu_15;
-	fp d_initvalu_16;
-	fp d_initvalu_17;
-	fp d_initvalu_18;
-	fp d_initvalu_19;
-	fp d_initvalu_20;
-	fp d_initvalu_21;
-	// fp d_initvalu_22;
-	fp d_initvalu_23;
-	fp d_initvalu_24;
-	fp d_initvalu_25;
-	fp d_initvalu_26;
-	fp d_initvalu_27;
-	fp d_initvalu_28;
-	fp d_initvalu_29;
-	fp d_initvalu_30;
-	fp d_initvalu_31;
-	fp d_initvalu_32;
-	fp d_initvalu_33;
-	fp d_initvalu_34;
-	fp d_initvalu_35;
-	fp d_initvalu_36;
-	fp d_initvalu_37;
-	fp d_initvalu_38;
-	fp d_initvalu_39;
-	fp d_initvalu_40;
-	// fp d_initvalu_41;
-	// fp d_initvalu_42;
-	// fp d_initvalu_43;
-	// fp d_initvalu_44;
-	// fp d_initvalu_45;
-	// fp d_initvalu_46;
-
-	// matlab constants undefined in c
-	fp pi;
-
-	// Constants
-	fp R;																			// [J/kmol*K]  
-	fp Frdy;																		// [C/mol]  
-	fp Temp;																		// [K] 310
-	fp FoRT;																		//
-	fp Cmem;																		// [F] membrane capacitance
-	fp Qpow;
-
-	// Cell geometry
-	fp cellLength;																	// cell length [um]
-	fp cellRadius;																	// cell radius [um]
-	// fp junctionLength;																// junc length [um]
-	// fp junctionRadius;																// junc radius [um]
-	// fp distSLcyto;																	// dist. SL to cytosol [um]
-	// fp distJuncSL;																	// dist. junc to SL [um]
-	// fp DcaJuncSL;																	// Dca junc to SL [cm^2/sec]
-	// fp DcaSLcyto;																	// Dca SL to cyto [cm^2/sec]
-	// fp DnaJuncSL;																	// Dna junc to SL [cm^2/sec]
-	// fp DnaSLcyto;																	// Dna SL to cyto [cm^2/sec] 
-	fp Vcell;																		// [L]
-	fp Vmyo; 
-	fp Vsr; 
-	fp Vsl; 
-	fp Vjunc; 
-	// fp SAjunc;																		// [um^2]
-	// fp SAsl;																		// [um^2]
-	fp J_ca_juncsl;																	// [L/msec]
-	fp J_ca_slmyo;																	// [L/msec]
-	fp J_na_juncsl;																	// [L/msec] 
-	fp J_na_slmyo;																	// [L/msec] 
-
-	// Fractional currents in compartments
-	fp Fjunc;   
-	fp Fsl;
-	fp Fjunc_CaL; 
-	fp Fsl_CaL;
-
-	// Fixed ion concentrations     
-	fp Cli;																			// Intracellular Cl  [mM]
-	fp Clo;																			// Extracellular Cl  [mM]
-	fp Ko;																			// Extracellular K   [mM]
-	fp Nao;																			// Extracellular Na  [mM]
-	fp Cao;																			// Extracellular Ca  [mM]
-	fp Mgi;																			// Intracellular Mg  [mM]
-
-	// Nernst Potentials
-	fp ena_junc;																	// [mV]
-	fp ena_sl;																		// [mV]
-	fp ek;																			// [mV]
-	fp eca_junc;																	// [mV]
-	fp eca_sl;																		// [mV]
-	fp ecl;																			// [mV]
-
-	// Na transport parameters
-	fp GNa;																			// [mS/uF]
-	fp GNaB;																		// [mS/uF] 
-	fp IbarNaK;																		// [uA/uF]
-	fp KmNaip;																		// [mM]
-	fp KmKo;																		// [mM]
-	// fp Q10NaK;  
-	// fp Q10KmNai;
-
-	// K current parameters
-	fp pNaK;      
-	fp GtoSlow;																		// [mS/uF] 
-	fp GtoFast;																		// [mS/uF] 
-	fp gkp;
-
-	// Cl current parameters
-	fp GClCa;																		// [mS/uF]
-	fp GClB;																		// [mS/uF]
-	fp KdClCa;																		// [mM]																// [mM]
-
-	// I_Ca parameters
-	fp pNa;																			// [cm/sec]
-	fp pCa;																			// [cm/sec]
-	fp pK;																			// [cm/sec]
-	// fp KmCa;																		// [mM]
-	fp Q10CaL;       
-
-	// Ca transport parameters
-	fp IbarNCX;																		// [uA/uF]
-	fp KmCai;																		// [mM]
-	fp KmCao;																		// [mM]
-	fp KmNai;																		// [mM]
-	fp KmNao;																		// [mM]
-	fp ksat;																			// [none]  
-	fp nu;																			// [none]
-	fp Kdact;																		// [mM] 
-	fp Q10NCX;																		// [none]
-	fp IbarSLCaP;																	// [uA/uF]
-	fp KmPCa;																		// [mM] 
-	fp GCaB;																		// [uA/uF] 
-	fp Q10SLCaP;																	// [none]																	// [none]
-
-	// SR flux parameters
-	fp Q10SRCaP;																	// [none]
-	fp Vmax_SRCaP;																	// [mM/msec] (mmol/L cytosol/msec)
-	fp Kmf;																			// [mM]
-	fp Kmr;																			// [mM]L cytosol
-	fp hillSRCaP;																	// [mM]
-	fp ks;																			// [1/ms]      
-	fp koCa;																		// [mM^-2 1/ms]      
-	fp kom;																			// [1/ms]     
-	fp kiCa;																		// [1/mM/ms]
-	fp kim;																			// [1/ms]
-	fp ec50SR;																		// [mM]
-
-	// Buffering parameters
-	fp Bmax_Naj;																	// [mM] 
-	fp Bmax_Nasl;																	// [mM]
-	fp koff_na;																		// [1/ms]
-	fp kon_na;																		// [1/mM/ms]
-	fp Bmax_TnClow;																	// [mM], TnC low affinity
-	fp koff_tncl;																	// [1/ms] 
-	fp kon_tncl;																	// [1/mM/ms]
-	fp Bmax_TnChigh;																// [mM], TnC high affinity 
-	fp koff_tnchca;																	// [1/ms] 
-	fp kon_tnchca;																	// [1/mM/ms]
-	fp koff_tnchmg;																	// [1/ms] 
-	fp kon_tnchmg;																	// [1/mM/ms]
-	// fp Bmax_CaM;																	// [mM], CaM buffering
-	// fp koff_cam;																	// [1/ms] 
-	// fp kon_cam;																		// [1/mM/ms]
-	fp Bmax_myosin;																	// [mM], Myosin buffering
-	fp koff_myoca;																	// [1/ms]
-	fp kon_myoca;																	// [1/mM/ms]
-	fp koff_myomg;																	// [1/ms]
-	fp kon_myomg;																	// [1/mM/ms]
-	fp Bmax_SR;																		// [mM] 
-	fp koff_sr;																		// [1/ms]
-	fp kon_sr;																		// [1/mM/ms]
-	fp Bmax_SLlowsl;																// [mM], SL buffering
-	fp Bmax_SLlowj;																	// [mM]    
-	fp koff_sll;																	// [1/ms]
-	fp kon_sll;																		// [1/mM/ms]
-	fp Bmax_SLhighsl;																// [mM] 
-	fp Bmax_SLhighj;																// [mM] 
-	fp koff_slh;																	// [1/ms]
-	fp kon_slh;																		// [1/mM/ms]
-	fp Bmax_Csqn;																	// 140e-3*Vmyo/Vsr; [mM] 
-	fp koff_csqn;																	// [1/ms] 
-	fp kon_csqn;																	// [1/mM/ms] 
-
-	// I_Na: Fast Na Current
-	fp am;
-	fp bm;
-	fp ah;
-	fp bh;
-	fp aj;
-	fp bj;
-	fp I_Na_junc;
-	fp I_Na_sl;
-	// fp I_Na;
-
-	// I_nabk: Na Background Current
-	fp I_nabk_junc;
-	fp I_nabk_sl;
-	// fp I_nabk;
-
-	// I_nak: Na/K Pump Current
-	fp sigma;
-	fp fnak;
-	fp I_nak_junc;
-	fp I_nak_sl;
-	fp I_nak;
-
-	// I_kr: Rapidly Activating K Current
-	fp gkr;
-	fp xrss;
-	fp tauxr;
-	fp rkr;
-	fp I_kr;
-
-	// I_ks: Slowly Activating K Current
-	fp pcaks_junc; 
-	fp pcaks_sl;  
-	fp gks_junc;
-	fp gks_sl; 
-	fp eks;	
-	fp xsss;
-	fp tauxs; 
-	fp I_ks_junc;
-	fp I_ks_sl;
-	fp I_ks;
-
-	// I_kp: Plateau K current
-	fp kp_kp;
-	fp I_kp_junc;
-	fp I_kp_sl;
-	fp I_kp;
-
-	// I_to: Transient Outward K Current (slow and fast components)
-	fp xtoss;
-	fp ytoss;
-	fp rtoss;
-	fp tauxtos;
-	fp tauytos;
-	fp taurtos; 
-	fp I_tos;	
-
-	//
-	fp tauxtof;
-	fp tauytof;
-	fp I_tof;
-	fp I_to;
-
-	// I_ki: Time-Independent K Current
-	fp aki;
-	fp bki;
-	fp kiss;
-	fp I_ki;
-
-	// I_ClCa: Ca-activated Cl Current, I_Clbk: background Cl Current
-	fp I_ClCa_junc;
-	fp I_ClCa_sl;
-	fp I_ClCa;
-	fp I_Clbk;
-
-	// I_Ca: L-type Calcium Current
-	fp dss;
-	fp taud;
-	fp fss;
-	fp tauf;
-
-	//
-	fp ibarca_j;
-	fp ibarca_sl;
-	fp ibark;
-	fp ibarna_j;
-	fp ibarna_sl;
-	fp I_Ca_junc;
-	fp I_Ca_sl;
-	fp I_Ca;
-	fp I_CaK;
-	fp I_CaNa_junc;
-	fp I_CaNa_sl;
-	// fp I_CaNa;
-	// fp I_Catot;
-
-	// I_ncx: Na/Ca Exchanger flux
-	fp Ka_junc;
-	fp Ka_sl;
-	fp s1_junc;
-	fp s1_sl;
-	fp s2_junc;
-	fp s3_junc;
-	fp s2_sl;
-	fp s3_sl;
-	fp I_ncx_junc;
-	fp I_ncx_sl;
-	fp I_ncx;
-
-	// I_pca: Sarcolemmal Ca Pump Current
-	fp I_pca_junc;
-	fp I_pca_sl;
-	fp I_pca;
-
-	// I_cabk: Ca Background Current
-	fp I_cabk_junc;
-	fp I_cabk_sl;
-	fp I_cabk;
-	
-	// SR fluxes: Calcium Release, SR Ca pump, SR Ca leak														
-	fp MaxSR;
-	fp MinSR;
-	fp kCaSR;
-	fp koSRCa;
-	fp kiSRCa;
-	fp RI;
-	fp J_SRCarel;																	// [mM/ms]
-	fp J_serca;
-	fp J_SRleak;																		//   [mM/ms]
-
-	// Cytosolic Ca Buffers
-	fp J_CaB_cytosol;
-
-	// Junctional and SL Ca Buffers
-	fp J_CaB_junction;
-	fp J_CaB_sl;
-
-	// SR Ca Concentrations
-	fp oneovervsr;
-
-	// Sodium Concentrations
-	fp I_Na_tot_junc;																// [uA/uF]
-	fp I_Na_tot_sl;																	// [uA/uF]
-	fp oneovervsl;
-
-	// Potassium Concentration
-	fp I_K_tot;
-
-	// Calcium Concentrations
-	fp I_Ca_tot_junc;																// [uA/uF]
-	fp I_Ca_tot_sl;																	// [uA/uF]
-	// fp junc_sl;
-	// fp sl_junc;
-	// fp sl_myo;
-	// fp myo_sl;
-
-	//	Simulation type													
-	int state;																			// 0-none; 1-pace; 2-vclamp
-	fp I_app;
-	fp V_hold;
-	fp V_test;
-	fp V_clamp;
-	fp R_clamp;
-	
-	//	Membrane Potential												
-	fp I_Na_tot;																		// [uA/uF]
-	fp I_Cl_tot;																		// [uA/uF]
-	fp I_Ca_tot;
-	fp I_tot;
-
-	//=====================================================================
-	//	EXECUTION														
-	//=====================================================================
-
-	// input parameters
-	cycleLength = d_params[15];
-
-	// variable references
-	offset_1 = valu_offset;
-	offset_2 = valu_offset+1;
-	offset_3 = valu_offset+2;
-	offset_4 = valu_offset+3;
-	offset_5 = valu_offset+4;
-	offset_6 = valu_offset+5;
-	offset_7 = valu_offset+6;
-	offset_8 = valu_offset+7;
-	offset_9 = valu_offset+8;
-	offset_10 = valu_offset+9;
-	offset_11 = valu_offset+10;
-	offset_12 = valu_offset+11;
-	offset_13 = valu_offset+12;
-	offset_14 = valu_offset+13;
-	offset_15 = valu_offset+14;
-	offset_16 = valu_offset+15;
-	offset_17 = valu_offset+16;
-	offset_18 = valu_offset+17;
-	offset_19 = valu_offset+18;
-	offset_20 = valu_offset+19;
-	offset_21 = valu_offset+20;
-	offset_22 = valu_offset+21;
-	offset_23 = valu_offset+22;
-	offset_24 = valu_offset+23;
-	offset_25 = valu_offset+24;
-	offset_26 = valu_offset+25;
-	offset_27 = valu_offset+26;
-	offset_28 = valu_offset+27;
-	offset_29 = valu_offset+28;
-	offset_30 = valu_offset+29;
-	offset_31 = valu_offset+30;
-	offset_32 = valu_offset+31;
-	offset_33 = valu_offset+32;
-	offset_34 = valu_offset+33;
-	offset_35 = valu_offset+34;
-	offset_36 = valu_offset+35;
-	offset_37 = valu_offset+36;
-	offset_38 = valu_offset+37;
-	offset_39 = valu_offset+38;
-	offset_40 = valu_offset+39;
-	offset_41 = valu_offset+40;
-	offset_42 = valu_offset+41;
-	offset_43 = valu_offset+42;
-	offset_44 = valu_offset+43;
-	offset_45 = valu_offset+44;
-	offset_46 = valu_offset+45;
-
-	// stored input array
-	d_initvalu_1 = d_initvalu[offset_1];
-	d_initvalu_2 = d_initvalu[offset_2];
-	d_initvalu_3 = d_initvalu[offset_3];
-	d_initvalu_4 = d_initvalu[offset_4];
-	d_initvalu_5 = d_initvalu[offset_5];
-	d_initvalu_6 = d_initvalu[offset_6];
-	d_initvalu_7 = d_initvalu[offset_7];
-	d_initvalu_8 = d_initvalu[offset_8];
-	d_initvalu_9 = d_initvalu[offset_9];
-	d_initvalu_10 = d_initvalu[offset_10];
-	d_initvalu_11 = d_initvalu[offset_11];
-	d_initvalu_12 = d_initvalu[offset_12];
-	d_initvalu_13 = d_initvalu[offset_13];
-	d_initvalu_14 = d_initvalu[offset_14];
-	d_initvalu_15 = d_initvalu[offset_15];
-	d_initvalu_16 = d_initvalu[offset_16];
-	d_initvalu_17 = d_initvalu[offset_17];
-	d_initvalu_18 = d_initvalu[offset_18];
-	d_initvalu_19 = d_initvalu[offset_19];
-	d_initvalu_20 = d_initvalu[offset_20];
-	d_initvalu_21 = d_initvalu[offset_21];
-	// d_initvalu_22 = d_initvalu[offset_22];
-	d_initvalu_23 = d_initvalu[offset_23];
-	d_initvalu_24 = d_initvalu[offset_24];
-	d_initvalu_25 = d_initvalu[offset_25];
-	d_initvalu_26 = d_initvalu[offset_26];
-	d_initvalu_27 = d_initvalu[offset_27];
-	d_initvalu_28 = d_initvalu[offset_28];
-	d_initvalu_29 = d_initvalu[offset_29];
-	d_initvalu_30 = d_initvalu[offset_30];
-	d_initvalu_31 = d_initvalu[offset_31];
-	d_initvalu_32 = d_initvalu[offset_32];
-	d_initvalu_33 = d_initvalu[offset_33];
-	d_initvalu_34 = d_initvalu[offset_34];
-	d_initvalu_35 = d_initvalu[offset_35];
-	d_initvalu_36 = d_initvalu[offset_36];
-	d_initvalu_37 = d_initvalu[offset_37];
-	d_initvalu_38 = d_initvalu[offset_38];
-	d_initvalu_39 = d_initvalu[offset_39];
-	d_initvalu_40 = d_initvalu[offset_40];
-	// d_initvalu_41 = d_initvalu[offset_41];
-	// d_initvalu_42 = d_initvalu[offset_42];
-	// d_initvalu_43 = d_initvalu[offset_43];
-	// d_initvalu_44 = d_initvalu[offset_44];
-	// d_initvalu_45 = d_initvalu[offset_45];
-	// d_initvalu_46 = d_initvalu[offset_46];
-
-	// matlab constants undefined in c
-	pi = 3.1416;
-
-	// Constants
-	R = 8314;																			// [J/kmol*K]  
-	Frdy = 96485;																		// [C/mol]  
-	Temp = 310;																			// [K] 310
-	FoRT = Frdy/R/Temp;																	//
-	Cmem = 1.3810e-10;																	// [F] membrane capacitance
-	Qpow = (Temp-310)/10;
-
-	// Cell geometry
-	cellLength = 100;																	// cell length [um]
-	cellRadius = 10.25;																	// cell radius [um]
-	// junctionLength = 160e-3;															// junc length [um]
-	// junctionRadius = 15e-3;																// junc radius [um]
-	// distSLcyto = 0.45;																	// dist. SL to cytosol [um]
-	// distJuncSL = 0.5;																	// dist. junc to SL [um]
-	// DcaJuncSL = 1.64e-6;																// Dca junc to SL [cm^2/sec]
-	// DcaSLcyto = 1.22e-6;																// Dca SL to cyto [cm^2/sec]
-	// DnaJuncSL = 1.09e-5;																// Dna junc to SL [cm^2/sec]
-	// DnaSLcyto = 1.79e-5;																// Dna SL to cyto [cm^2/sec] 
-	Vcell = pi*pow(cellRadius,2)*cellLength*1e-15;											// [L]
-	Vmyo = 0.65*Vcell; 
-	Vsr = 0.035*Vcell; 
-	Vsl = 0.02*Vcell; 
-	Vjunc = 0.0539*0.01*Vcell; 
-	// SAjunc = 20150*pi*2*junctionLength*junctionRadius;									// [um^2]
-	// SAsl = pi*2*cellRadius*cellLength;													// [um^2]
-	J_ca_juncsl = 1/1.2134e12;															// [L/msec]
-	J_ca_slmyo = 1/2.68510e11;															// [L/msec]
-	J_na_juncsl = 1/(1.6382e12/3*100);													// [L/msec] 
-	J_na_slmyo = 1/(1.8308e10/3*100);													// [L/msec] 
-
-	// Fractional currents in compartments
-	Fjunc = 0.11;   
-	Fsl = 1-Fjunc;
-	Fjunc_CaL = 0.9; 
-	Fsl_CaL = 1-Fjunc_CaL;
-
-	// Fixed ion concentrations     
-	Cli = 15;																			// Intracellular Cl  [mM]
-	Clo = 150;																			// Extracellular Cl  [mM]
-	Ko = 5.4;																			// Extracellular K   [mM]
-	Nao = 140;																			// Extracellular Na  [mM]
-	Cao = 1.8;																			// Extracellular Ca  [mM]
-	Mgi = 1;																			// Intracellular Mg  [mM]
-
-	// Nernst Potentials
-	ena_junc = (1/FoRT)*log(Nao/d_initvalu_32);													// [mV]
-	ena_sl = (1/FoRT)*log(Nao/d_initvalu_33);													// [mV]
-	ek = (1/FoRT)*log(Ko/d_initvalu_35);														// [mV]
-	eca_junc = (1/FoRT/2)*log(Cao/d_initvalu_36);												// [mV]
-	eca_sl = (1/FoRT/2)*log(Cao/d_initvalu_37);													// [mV]
-	ecl = (1/FoRT)*log(Cli/Clo);														// [mV]
-
-	// Na transport parameters
-	GNa =  16.0;																		// [mS/uF]
-	GNaB = 0.297e-3;																	// [mS/uF] 
-	IbarNaK = 1.90719;																	// [uA/uF]
-	KmNaip = 11;																		// [mM]
-	KmKo = 1.5;																			// [mM]
-	// Q10NaK = 1.63;  
-	// Q10KmNai = 1.39;
-
-	// K current parameters
-	pNaK = 0.01833;      
-	GtoSlow = 0.06;																		// [mS/uF] 
-	GtoFast = 0.02;																		// [mS/uF] 
-	gkp = 0.001;
-
-	// Cl current parameters
-	GClCa = 0.109625;																	// [mS/uF]
-	GClB = 9e-3;																		// [mS/uF]
-	KdClCa = 100e-3;																	// [mM]
-
-	// I_Ca parameters
-	pNa = 1.5e-8;																		// [cm/sec]
-	pCa = 5.4e-4;																		// [cm/sec]
-	pK = 2.7e-7;																		// [cm/sec]
-	// KmCa = 0.6e-3;																		// [mM]
-	Q10CaL = 1.8;       
-
-	// Ca transport parameters
-	IbarNCX = 9.0;																		// [uA/uF]
-	KmCai = 3.59e-3;																	// [mM]
-	KmCao = 1.3;																		// [mM]
-	KmNai = 12.29;																		// [mM]
-	KmNao = 87.5;																		// [mM]
-	ksat = 0.27;																		// [none]  
-	nu = 0.35;																			// [none]
-	Kdact = 0.256e-3;																	// [mM] 
-	Q10NCX = 1.57;																		// [none]
-	IbarSLCaP = 0.0673;																	// [uA/uF]
-	KmPCa = 0.5e-3;																		// [mM] 
-	GCaB = 2.513e-4;																	// [uA/uF] 
-	Q10SLCaP = 2.35;																	// [none]
-
-	// SR flux parameters
-	Q10SRCaP = 2.6;																		// [none]
-	Vmax_SRCaP = 2.86e-4;																// [mM/msec] (mmol/L cytosol/msec)
-	Kmf = 0.246e-3;																		// [mM]
-	Kmr = 1.7;																			// [mM]L cytosol
-	hillSRCaP = 1.787;																	// [mM]
-	ks = 25;																			// [1/ms]      
-	koCa = 10;																			// [mM^-2 1/ms]      
-	kom = 0.06;																			// [1/ms]     
-	kiCa = 0.5;																			// [1/mM/ms]
-	kim = 0.005;																		// [1/ms]
-	ec50SR = 0.45;																		// [mM]
-
-	// Buffering parameters
-	Bmax_Naj = 7.561;																	// [mM] 
-	Bmax_Nasl = 1.65;																	// [mM]
-	koff_na = 1e-3;																		// [1/ms]
-	kon_na = 0.1e-3;																	// [1/mM/ms]
-	Bmax_TnClow = 70e-3;																// [mM], TnC low affinity
-	koff_tncl = 19.6e-3;																// [1/ms] 
-	kon_tncl = 32.7;																	// [1/mM/ms]
-	Bmax_TnChigh = 140e-3;																// [mM], TnC high affinity 
-	koff_tnchca = 0.032e-3;																// [1/ms] 
-	kon_tnchca = 2.37;																	// [1/mM/ms]
-	koff_tnchmg = 3.33e-3;																// [1/ms] 
-	kon_tnchmg = 3e-3;																	// [1/mM/ms]
-	// Bmax_CaM = 24e-3;																	// [mM], CaM buffering
-	// koff_cam = 238e-3;																	// [1/ms] 
-	// kon_cam = 34;																		// [1/mM/ms]
-	Bmax_myosin = 140e-3;																// [mM], Myosin buffering
-	koff_myoca = 0.46e-3;																// [1/ms]
-	kon_myoca = 13.8;																	// [1/mM/ms]
-	koff_myomg = 0.057e-3;																// [1/ms]
-	kon_myomg = 0.0157;																	// [1/mM/ms]
-	Bmax_SR = 19*0.9e-3;																	// [mM] 
-	koff_sr = 60e-3;																	// [1/ms]
-	kon_sr = 100;																		// [1/mM/ms]
-	Bmax_SLlowsl = 37.38e-3*Vmyo/Vsl;													// [mM], SL buffering
-	Bmax_SLlowj = 4.62e-3*Vmyo/Vjunc*0.1;												// [mM]    
-	koff_sll = 1300e-3;																	// [1/ms]
-	kon_sll = 100;																		// [1/mM/ms]
-	Bmax_SLhighsl = 13.35e-3*Vmyo/Vsl;													// [mM] 
-	Bmax_SLhighj = 1.65e-3*Vmyo/Vjunc*0.1;												// [mM] 
-	koff_slh = 30e-3;																	// [1/ms]
-	kon_slh = 100;																		// [1/mM/ms]
-	Bmax_Csqn = 2.7;																	// 140e-3*Vmyo/Vsr; [mM] 
-	koff_csqn = 65;																		// [1/ms] 
-	kon_csqn = 100;																		// [1/mM/ms] 
-
-	// I_Na: Fast Na Current
-	am = 0.32*(d_initvalu_39+47.13)/(1-exp(-0.1*(d_initvalu_39+47.13)));
-	bm = 0.08*exp(-d_initvalu_39/11);
-	if(d_initvalu_39 >= -40){
-		ah = 0; aj = 0;
-		bh = 1/(0.13*(1+exp(-(d_initvalu_39+10.66)/11.1)));
-		bj = 0.3*exp(-2.535e-7*d_initvalu_39)/(1+exp(-0.1*(d_initvalu_39+32)));
-	}
-	else{
-		ah = 0.135*exp((80+d_initvalu_39)/-6.8);
-		bh = 3.56*exp(0.079*d_initvalu_39)+3.1e5*exp(0.35*d_initvalu_39);
-		aj = (-127140*exp(0.2444*d_initvalu_39)-3.474e-5*exp(-0.04391*d_initvalu_39))*(d_initvalu_39+37.78)/(1+exp(0.311*(d_initvalu_39+79.23)));
-		bj = 0.1212*exp(-0.01052*d_initvalu_39)/(1+exp(-0.1378*(d_initvalu_39+40.14)));
-	}
-	d_finavalu[offset_1] = am*(1-d_initvalu_1)-bm*d_initvalu_1;
-	d_finavalu[offset_2] = ah*(1-d_initvalu_2)-bh*d_initvalu_2;
-	d_finavalu[offset_3] = aj*(1-d_initvalu_3)-bj*d_initvalu_3;
-	I_Na_junc = Fjunc*GNa*pow(d_initvalu_1,3)*d_initvalu_2*d_initvalu_3*(d_initvalu_39-ena_junc);
-	I_Na_sl = Fsl*GNa*pow(d_initvalu_1,3)*d_initvalu_2*d_initvalu_3*(d_initvalu_39-ena_sl);
-	// I_Na = I_Na_junc+I_Na_sl;
-
-	// I_nabk: Na Background Current
-	I_nabk_junc = Fjunc*GNaB*(d_initvalu_39-ena_junc);
-	I_nabk_sl = Fsl*GNaB*(d_initvalu_39-ena_sl);
-	// I_nabk = I_nabk_junc+I_nabk_sl;
-
-	// I_nak: Na/K Pump Current
-	sigma = (exp(Nao/67.3)-1)/7;
-	fnak = 1/(1+0.1245*exp(-0.1*d_initvalu_39*FoRT)+0.0365*sigma*exp(-d_initvalu_39*FoRT));
-	I_nak_junc = Fjunc*IbarNaK*fnak*Ko /(1+pow((KmNaip/d_initvalu_32),4)) /(Ko+KmKo);
-	I_nak_sl = Fsl*IbarNaK*fnak*Ko /(1+pow((KmNaip/d_initvalu_33),4)) /(Ko+KmKo);
-	I_nak = I_nak_junc+I_nak_sl;
-
-	// I_kr: Rapidly Activating K Current
-	gkr = 0.03*sqrt(Ko/5.4);
-	xrss = 1/(1+exp(-(d_initvalu_39+50)/7.5));
-	tauxr = 1/(0.00138*(d_initvalu_39+7)/(1-exp(-0.123*(d_initvalu_39+7)))+6.1e-4*(d_initvalu_39+10)/(exp(0.145*(d_initvalu_39+10))-1));
-	d_finavalu[offset_12] = (xrss-d_initvalu_12)/tauxr;
-	rkr = 1/(1+exp((d_initvalu_39+33)/22.4));
-	I_kr = gkr*d_initvalu_12*rkr*(d_initvalu_39-ek);
-
-	// I_ks: Slowly Activating K Current
-	pcaks_junc = -log10(d_initvalu_36)+3.0; 
-	pcaks_sl = -log10(d_initvalu_37)+3.0;  
-	gks_junc = 0.07*(0.057 +0.19/(1+ exp((-7.2+pcaks_junc)/0.6)));
-	gks_sl = 0.07*(0.057 +0.19/(1+ exp((-7.2+pcaks_sl)/0.6))); 
-	eks = (1/FoRT)*log((Ko+pNaK*Nao)/(d_initvalu_35+pNaK*d_initvalu_34));	
-	xsss = 1/(1+exp(-(d_initvalu_39-1.5)/16.7));
-	tauxs = 1/(7.19e-5*(d_initvalu_39+30)/(1-exp(-0.148*(d_initvalu_39+30)))+1.31e-4*(d_initvalu_39+30)/(exp(0.0687*(d_initvalu_39+30))-1)); 
-	d_finavalu[offset_13] = (xsss-d_initvalu_13)/tauxs;
-	I_ks_junc = Fjunc*gks_junc*pow(d_initvalu_12,2)*(d_initvalu_39-eks);
-	I_ks_sl = Fsl*gks_sl*pow(d_initvalu_13,2)*(d_initvalu_39-eks);
-	I_ks = I_ks_junc+I_ks_sl;
-
-	// I_kp: Plateau K current
-	kp_kp = 1/(1+exp(7.488-d_initvalu_39/5.98));
-	I_kp_junc = Fjunc*gkp*kp_kp*(d_initvalu_39-ek);
-	I_kp_sl = Fsl*gkp*kp_kp*(d_initvalu_39-ek);
-	I_kp = I_kp_junc+I_kp_sl;
-
-	// I_to: Transient Outward K Current (slow and fast components)
-	xtoss = 1/(1+exp(-(d_initvalu_39+3.0)/15));
-	ytoss = 1/(1+exp((d_initvalu_39+33.5)/10));
-	rtoss = 1/(1+exp((d_initvalu_39+33.5)/10));
-	tauxtos = 9/(1+exp((d_initvalu_39+3.0)/15))+0.5;
-	tauytos = 3e3/(1+exp((d_initvalu_39+60.0)/10))+30;
-	taurtos = 2800/(1+exp((d_initvalu_39+60.0)/10))+220; 
-	d_finavalu[offset_8] = (xtoss-d_initvalu_8)/tauxtos;
-	d_finavalu[offset_9] = (ytoss-d_initvalu_9)/tauytos;
-	d_finavalu[offset_40]= (rtoss-d_initvalu_40)/taurtos; 
-	I_tos = GtoSlow*d_initvalu_8*(d_initvalu_9+0.5*d_initvalu_40)*(d_initvalu_39-ek);									// [uA/uF]
-
-	//
-	tauxtof = 3.5*exp(-d_initvalu_39*d_initvalu_39/30/30)+1.5;
-	tauytof = 20.0/(1+exp((d_initvalu_39+33.5)/10))+20.0;
-	d_finavalu[offset_10] = (xtoss-d_initvalu_10)/tauxtof;
-	d_finavalu[offset_11] = (ytoss-d_initvalu_11)/tauytof;
-	I_tof = GtoFast*d_initvalu_10*d_initvalu_11*(d_initvalu_39-ek);
-	I_to = I_tos + I_tof;
-
-	// I_ki: Time-Independent K Current
-	aki = 1.02/(1+exp(0.2385*(d_initvalu_39-ek-59.215)));
-	bki =(0.49124*exp(0.08032*(d_initvalu_39+5.476-ek)) + exp(0.06175*(d_initvalu_39-ek-594.31))) /(1 + exp(-0.5143*(d_initvalu_39-ek+4.753)));
-	kiss = aki/(aki+bki);
-	I_ki = 0.9*sqrt(Ko/5.4)*kiss*(d_initvalu_39-ek);
-
-	// I_ClCa: Ca-activated Cl Current, I_Clbk: background Cl Current
-	I_ClCa_junc = Fjunc*GClCa/(1+KdClCa/d_initvalu_36)*(d_initvalu_39-ecl);
-	I_ClCa_sl = Fsl*GClCa/(1+KdClCa/d_initvalu_37)*(d_initvalu_39-ecl);
-	I_ClCa = I_ClCa_junc+I_ClCa_sl;
-	I_Clbk = GClB*(d_initvalu_39-ecl);
-
-	// I_Ca: L-type Calcium Current
-	dss = 1/(1+exp(-(d_initvalu_39+14.5)/6.0));
-	taud = dss*(1-exp(-(d_initvalu_39+14.5)/6.0))/(0.035*(d_initvalu_39+14.5));
-	fss = 1/(1+exp((d_initvalu_39+35.06)/3.6))+0.6/(1+exp((50-d_initvalu_39)/20));
-	tauf = 1/(0.0197*exp(-pow(0.0337*(d_initvalu_39+14.5),2))+0.02);
-	d_finavalu[offset_4] = (dss-d_initvalu_4)/taud;
-	d_finavalu[offset_5] = (fss-d_initvalu_5)/tauf;
-	d_finavalu[offset_6] = 1.7*d_initvalu_36*(1-d_initvalu_6)-11.9e-3*d_initvalu_6;											// fCa_junc  
-	d_finavalu[offset_7] = 1.7*d_initvalu_37*(1-d_initvalu_7)-11.9e-3*d_initvalu_7;											// fCa_sl
-
-	//
-	ibarca_j = pCa*4*(d_initvalu_39*Frdy*FoRT) * (0.341*d_initvalu_36*exp(2*d_initvalu_39*FoRT)-0.341*Cao) /(exp(2*d_initvalu_39*FoRT)-1);
-	ibarca_sl = pCa*4*(d_initvalu_39*Frdy*FoRT) * (0.341*d_initvalu_37*exp(2*d_initvalu_39*FoRT)-0.341*Cao) /(exp(2*d_initvalu_39*FoRT)-1);
-	ibark = pK*(d_initvalu_39*Frdy*FoRT)*(0.75*d_initvalu_35*exp(d_initvalu_39*FoRT)-0.75*Ko) /(exp(d_initvalu_39*FoRT)-1);
-	ibarna_j = pNa*(d_initvalu_39*Frdy*FoRT) *(0.75*d_initvalu_32*exp(d_initvalu_39*FoRT)-0.75*Nao)  /(exp(d_initvalu_39*FoRT)-1);
-	ibarna_sl = pNa*(d_initvalu_39*Frdy*FoRT) *(0.75*d_initvalu_33*exp(d_initvalu_39*FoRT)-0.75*Nao)  /(exp(d_initvalu_39*FoRT)-1);
-	I_Ca_junc = (Fjunc_CaL*ibarca_j*d_initvalu_4*d_initvalu_5*(1-d_initvalu_6)*pow(Q10CaL,Qpow))*0.45;
-	I_Ca_sl = (Fsl_CaL*ibarca_sl*d_initvalu_4*d_initvalu_5*(1-d_initvalu_7)*pow(Q10CaL,Qpow))*0.45;
-	I_Ca = I_Ca_junc+I_Ca_sl;
-	d_finavalu[offset_43]=-I_Ca*Cmem/(Vmyo*2*Frdy)*1e3;
-	I_CaK = (ibark*d_initvalu_4*d_initvalu_5*(Fjunc_CaL*(1-d_initvalu_6)+Fsl_CaL*(1-d_initvalu_7))*pow(Q10CaL,Qpow))*0.45;
-	I_CaNa_junc = (Fjunc_CaL*ibarna_j*d_initvalu_4*d_initvalu_5*(1-d_initvalu_6)*pow(Q10CaL,Qpow))*0.45;
-	I_CaNa_sl = (Fsl_CaL*ibarna_sl*d_initvalu_4*d_initvalu_5*(1-d_initvalu_7)*pow(Q10CaL,Qpow))*0.45;
-	// I_CaNa = I_CaNa_junc+I_CaNa_sl;
-	// I_Catot = I_Ca+I_CaK+I_CaNa;
-
-	// I_ncx: Na/Ca Exchanger flux
-	Ka_junc = 1/(1+pow((Kdact/d_initvalu_36),3));
-	Ka_sl = 1/(1+pow((Kdact/d_initvalu_37),3));
-	s1_junc = exp(nu*d_initvalu_39*FoRT)*pow(d_initvalu_32,3)*Cao;
-	s1_sl = exp(nu*d_initvalu_39*FoRT)*pow(d_initvalu_33,3)*Cao;
-	s2_junc = exp((nu-1)*d_initvalu_39*FoRT)*pow(Nao,3)*d_initvalu_36;
-	s3_junc = (KmCai*pow(Nao,3)*(1+pow((d_initvalu_32/KmNai),3))+pow(KmNao,3)*d_initvalu_36+ pow(KmNai,3)*Cao*(1+d_initvalu_36/KmCai)+KmCao*pow(d_initvalu_32,3)+pow(d_initvalu_32,3)*Cao+pow(Nao,3)*d_initvalu_36)*(1+ksat*exp((nu-1)*d_initvalu_39*FoRT));
-	s2_sl = exp((nu-1)*d_initvalu_39*FoRT)*pow(Nao,3)*d_initvalu_37;
-	s3_sl = (KmCai*pow(Nao,3)*(1+pow((d_initvalu_33/KmNai),3)) + pow(KmNao,3)*d_initvalu_37+pow(KmNai,3)*Cao*(1+d_initvalu_37/KmCai)+KmCao*pow(d_initvalu_33,3)+pow(d_initvalu_33,3)*Cao+pow(Nao,3)*d_initvalu_37)*(1+ksat*exp((nu-1)*d_initvalu_39*FoRT));
-	I_ncx_junc = Fjunc*IbarNCX*pow(Q10NCX,Qpow)*Ka_junc*(s1_junc-s2_junc)/s3_junc;
-	I_ncx_sl = Fsl*IbarNCX*pow(Q10NCX,Qpow)*Ka_sl*(s1_sl-s2_sl)/s3_sl;
-	I_ncx = I_ncx_junc+I_ncx_sl;
-	d_finavalu[offset_45]=2*I_ncx*Cmem/(Vmyo*2*Frdy)*1e3;
-
-	// I_pca: Sarcolemmal Ca Pump Current
-	I_pca_junc = Fjunc*pow(Q10SLCaP,Qpow)*IbarSLCaP*pow(d_initvalu_36,(fp)(1.6))/(pow(KmPCa,(fp)(1.6))+pow(d_initvalu_36,(fp)(1.6)));
-	I_pca_sl = Fsl*pow(Q10SLCaP,Qpow)*IbarSLCaP*pow(d_initvalu_37,(fp)(1.6))/(pow(KmPCa,(fp)(1.6))+pow(d_initvalu_37,(fp)(1.6)));
-	I_pca = I_pca_junc+I_pca_sl;
-	d_finavalu[offset_44]=-I_pca*Cmem/(Vmyo*2*Frdy)*1e3;
-
-	// I_cabk: Ca Background Current
-	I_cabk_junc = Fjunc*GCaB*(d_initvalu_39-eca_junc);
-	I_cabk_sl = Fsl*GCaB*(d_initvalu_39-eca_sl);
-	I_cabk = I_cabk_junc+I_cabk_sl;
-	d_finavalu[offset_46]=-I_cabk*Cmem/(Vmyo*2*Frdy)*1e3;
-
-	// SR fluxes: Calcium Release, SR Ca pump, SR Ca leak														
-	MaxSR = 15; 
-	MinSR = 1;
-	kCaSR = MaxSR - (MaxSR-MinSR)/(1+pow(ec50SR/d_initvalu_31,(fp)(2.5)));
-	koSRCa = koCa/kCaSR;
-	kiSRCa = kiCa*kCaSR;
-	RI = 1-d_initvalu_14-d_initvalu_15-d_initvalu_16;
-	d_finavalu[offset_14] = (kim*RI-kiSRCa*d_initvalu_36*d_initvalu_14)-(koSRCa*pow(d_initvalu_36,2)*d_initvalu_14-kom*d_initvalu_15);			// R
-	d_finavalu[offset_15] = (koSRCa*pow(d_initvalu_36,2)*d_initvalu_14-kom*d_initvalu_15)-(kiSRCa*d_initvalu_36*d_initvalu_15-kim*d_initvalu_16);			// O
-	d_finavalu[offset_16] = (kiSRCa*d_initvalu_36*d_initvalu_15-kim*d_initvalu_16)-(kom*d_initvalu_16-koSRCa*pow(d_initvalu_36,2)*RI);			// I
-	J_SRCarel = ks*d_initvalu_15*(d_initvalu_31-d_initvalu_36);													// [mM/ms]
-	J_serca = pow(Q10SRCaP,Qpow)*Vmax_SRCaP*(pow((d_initvalu_38/Kmf),hillSRCaP)-pow((d_initvalu_31/Kmr),hillSRCaP))
-										 /(1+pow((d_initvalu_38/Kmf),hillSRCaP)+pow((d_initvalu_31/Kmr),hillSRCaP));
-	J_SRleak = 5.348e-6*(d_initvalu_31-d_initvalu_36);													//   [mM/ms]
-
-	// Sodium and Calcium Buffering														
-	d_finavalu[offset_17] = kon_na*d_initvalu_32*(Bmax_Naj-d_initvalu_17)-koff_na*d_initvalu_17;								// NaBj      [mM/ms]
-	d_finavalu[offset_18] = kon_na*d_initvalu_33*(Bmax_Nasl-d_initvalu_18)-koff_na*d_initvalu_18;							// NaBsl     [mM/ms]
-
-	// Cytosolic Ca Buffers
-	d_finavalu[offset_19] = kon_tncl*d_initvalu_38*(Bmax_TnClow-d_initvalu_19)-koff_tncl*d_initvalu_19;						// TnCL      [mM/ms]
-	d_finavalu[offset_20] = kon_tnchca*d_initvalu_38*(Bmax_TnChigh-d_initvalu_20-d_initvalu_21)-koff_tnchca*d_initvalu_20;			// TnCHc     [mM/ms]
-	d_finavalu[offset_21] = kon_tnchmg*Mgi*(Bmax_TnChigh-d_initvalu_20-d_initvalu_21)-koff_tnchmg*d_initvalu_21;				// TnCHm     [mM/ms]
-	d_finavalu[offset_22] = 0;																		// CaM       [mM/ms]
-	d_finavalu[offset_23] = kon_myoca*d_initvalu_38*(Bmax_myosin-d_initvalu_23-d_initvalu_24)-koff_myoca*d_initvalu_23;				// Myosin_ca [mM/ms]
-	d_finavalu[offset_24] = kon_myomg*Mgi*(Bmax_myosin-d_initvalu_23-d_initvalu_24)-koff_myomg*d_initvalu_24;				// Myosin_mg [mM/ms]
-	d_finavalu[offset_25] = kon_sr*d_initvalu_38*(Bmax_SR-d_initvalu_25)-koff_sr*d_initvalu_25;								// SRB       [mM/ms]
-	J_CaB_cytosol = d_finavalu[offset_19] + d_finavalu[offset_20] + d_finavalu[offset_21] + d_finavalu[offset_22] + d_finavalu[offset_23] + d_finavalu[offset_24] + d_finavalu[offset_25];
-
-	// Junctional and SL Ca Buffers
-	d_finavalu[offset_26] = kon_sll*d_initvalu_36*(Bmax_SLlowj-d_initvalu_26)-koff_sll*d_initvalu_26;						// SLLj      [mM/ms]
-	d_finavalu[offset_27] = kon_sll*d_initvalu_37*(Bmax_SLlowsl-d_initvalu_27)-koff_sll*d_initvalu_27;						// SLLsl     [mM/ms]
-	d_finavalu[offset_28] = kon_slh*d_initvalu_36*(Bmax_SLhighj-d_initvalu_28)-koff_slh*d_initvalu_28;						// SLHj      [mM/ms]
-	d_finavalu[offset_29] = kon_slh*d_initvalu_37*(Bmax_SLhighsl-d_initvalu_29)-koff_slh*d_initvalu_29;						// SLHsl     [mM/ms]
-	J_CaB_junction = d_finavalu[offset_26]+d_finavalu[offset_28];
-	J_CaB_sl = d_finavalu[offset_27]+d_finavalu[offset_29];
-
-	// SR Ca Concentrations
-	d_finavalu[offset_30] = kon_csqn*d_initvalu_31*(Bmax_Csqn-d_initvalu_30)-koff_csqn*d_initvalu_30;						// Csqn      [mM/ms]
-	oneovervsr = 1/Vsr;
-	d_finavalu[offset_31] = J_serca*Vmyo*oneovervsr-(J_SRleak*Vmyo*oneovervsr+J_SRCarel)-d_finavalu[offset_30];   // Ca_sr     [mM/ms] %Ratio 3 leak current
-
-	// Sodium Concentrations
-	I_Na_tot_junc = I_Na_junc+I_nabk_junc+3*I_ncx_junc+3*I_nak_junc+I_CaNa_junc;		// [uA/uF]
-	I_Na_tot_sl = I_Na_sl+I_nabk_sl+3*I_ncx_sl+3*I_nak_sl+I_CaNa_sl;					// [uA/uF]
-	d_finavalu[offset_32] = -I_Na_tot_junc*Cmem/(Vjunc*Frdy)+J_na_juncsl/Vjunc*(d_initvalu_33-d_initvalu_32)-d_finavalu[offset_17];
-	oneovervsl = 1/Vsl;
-	d_finavalu[offset_33] = -I_Na_tot_sl*Cmem*oneovervsl/Frdy+J_na_juncsl*oneovervsl*(d_initvalu_32-d_initvalu_33)+J_na_slmyo*oneovervsl*(d_initvalu_34-d_initvalu_33)-d_finavalu[offset_18];
-	d_finavalu[offset_34] = J_na_slmyo/Vmyo*(d_initvalu_33-d_initvalu_34);											// [mM/msec] 
-
-	// Potassium Concentration
-	I_K_tot = I_to+I_kr+I_ks+I_ki-2*I_nak+I_CaK+I_kp;									// [uA/uF]
-	d_finavalu[offset_35] = 0;															// [mM/msec]
-
-	// Calcium Concentrations
-	I_Ca_tot_junc = I_Ca_junc+I_cabk_junc+I_pca_junc-2*I_ncx_junc;						// [uA/uF]
-	I_Ca_tot_sl = I_Ca_sl+I_cabk_sl+I_pca_sl-2*I_ncx_sl;								// [uA/uF]
-	d_finavalu[offset_36] = -I_Ca_tot_junc*Cmem/(Vjunc*2*Frdy)+J_ca_juncsl/Vjunc*(d_initvalu_37-d_initvalu_36)
-	         - J_CaB_junction+(J_SRCarel)*Vsr/Vjunc+J_SRleak*Vmyo/Vjunc;				// Ca_j
-	d_finavalu[offset_37] = -I_Ca_tot_sl*Cmem/(Vsl*2*Frdy)+J_ca_juncsl/Vsl*(d_initvalu_36-d_initvalu_37)
-	         + J_ca_slmyo/Vsl*(d_initvalu_38-d_initvalu_37)-J_CaB_sl;									// Ca_sl
-	d_finavalu[offset_38] = -J_serca-J_CaB_cytosol +J_ca_slmyo/Vmyo*(d_initvalu_37-d_initvalu_38);
-	// junc_sl=J_ca_juncsl/Vsl*(d_initvalu_36-d_initvalu_37);
-	// sl_junc=J_ca_juncsl/Vjunc*(d_initvalu_37-d_initvalu_36);
-	// sl_myo=J_ca_slmyo/Vsl*(d_initvalu_38-d_initvalu_37);
-	// myo_sl=J_ca_slmyo/Vmyo*(d_initvalu_37-d_initvalu_38);
-
-	// Simulation type													
-	state = 1;																			
-	switch(state){
-		case 0:
-			I_app = 0;
-			break;
-		case 1:																			// pace w/ current injection at cycleLength 'cycleLength'
-			if(fmod(timeinst,cycleLength) <= 5){
-				I_app = 9.5;
-			}
-			else{
-				I_app = 0.0;
-			}
-			break;
-		case 2:     
-			V_hold = -55;
-			V_test = 0;
-			if(timeinst>0.5 & timeinst<200.5){
-				V_clamp = V_test;
-			}
-			else{
-				V_clamp = V_hold;
-			}
-			R_clamp = 0.04;
-			I_app = (V_clamp-d_initvalu_39)/R_clamp;
-			break;
-	} 
-
-	// Membrane Potential												
-	I_Na_tot = I_Na_tot_junc + I_Na_tot_sl;												// [uA/uF]
-	I_Cl_tot = I_ClCa+I_Clbk;															// [uA/uF]
-	I_Ca_tot = I_Ca_tot_junc+I_Ca_tot_sl;
-	I_tot = I_Na_tot+I_Cl_tot+I_Ca_tot+I_K_tot;
-	d_finavalu[offset_39] = -(I_tot-I_app);
-
-	// Set unused output values to 0 (MATLAB does it by default)
-	d_finavalu[offset_41] = 0;
-	d_finavalu[offset_42] = 0;
-
-}
-
-//========================================================================================================================================================================================================200
-//	KERNEL_CAM
-//========================================================================================================================================================================================================200
-
-void 
-kernel_cam(	fp timeinst,
-			__global fp *d_initvalu,
-			__global fp *d_finavalu,
-			int valu_offset,
-			__global fp *d_params,
-			int params_offset,
-			__global fp *d_com,
-			int com_offset,
-			fp Ca){
-
-	//=====================================================================
-	//	VARIABLES
-	//=====================================================================
-
-	// inputs
-	// fp CaMtot;
-	fp Btot;
-	fp CaMKIItot;
-	fp CaNtot;
-	fp PP1tot;
-	fp K;
-	fp Mg;
-
-	// variable references
-	int offset_1;
-	int offset_2;
-	int offset_3;
-	int offset_4;
-	int offset_5;
-	int offset_6;
-	int offset_7;
-	int offset_8;
-	int offset_9;
-	int offset_10;
-	int offset_11;
-	int offset_12;
-	int offset_13;
-	int offset_14;
-	int offset_15;
-
-	// decoding input array
-	fp CaM;
-	fp Ca2CaM;
-	fp Ca4CaM;
-	fp CaMB;
-	fp Ca2CaMB;
-	fp Ca4CaMB;           
-	fp Pb2;
-	fp Pb;
-	fp Pt;
-	fp Pt2;
-	fp Pa;                            
-	fp Ca4CaN;
-	fp CaMCa4CaN;
-	fp Ca2CaMCa4CaN;
-	fp Ca4CaMCa4CaN;
-
-	// Ca/CaM parameters
-	fp Kd02;																		// [uM^2]
-	fp Kd24;																		// [uM^2]
-	fp k20;																			// [s^-1]      
-	fp k02;																			// [uM^-2 s^-1]
-	fp k42;																			// [s^-1]      
-	fp k24;																			// [uM^-2 s^-1]
-
-	// CaM buffering (B) parameters
-	fp k0Boff;																		// [s^-1] 
-	fp k0Bon;																		// [uM^-1 s^-1] kon = koff/Kd
-	fp k2Boff;																		// [s^-1] 
-	fp k2Bon;																		// [uM^-1 s^-1]
-	fp k4Boff;																		// [s^-1]
-	fp k4Bon;																		// [uM^-1 s^-1]
-
-	// using thermodynamic constraints
-	fp k20B;																		// [s^-1] thermo constraint on loop 1
-	fp k02B;																		// [uM^-2 s^-1] 
-	fp k42B;																		// [s^-1] thermo constraint on loop 2
-	fp k24B;																		// [uM^-2 s^-1]
-
-	// Wi Wa Wt Wp
-	fp kbi;																			// [s^-1] (Ca4CaM dissocation from Wb)
-	fp kib;																			// [uM^-1 s^-1]
-	fp kpp1;																		// [s^-1] (PP1-dep dephosphorylation rates)
-	fp Kmpp1;																		// [uM]
-	fp kib2;
-	fp kb2i;
-	fp kb24;
-	fp kb42;
-	fp kta;																			// [s^-1] (Ca4CaM dissociation from Wt)
-	fp kat;																			// [uM^-1 s^-1] (Ca4CaM reassociation with Wa)
-	fp kt42;
-	fp kt24;
-	fp kat2;
-	fp kt2a;
-
-	// CaN parameters
-	fp kcanCaoff;																	// [s^-1] 
-	fp kcanCaon;																	// [uM^-1 s^-1] 
-	fp kcanCaM4on;																	// [uM^-1 s^-1]
-	fp kcanCaM4off;																	// [s^-1]
-	fp kcanCaM2on;
-	fp kcanCaM2off;
-	fp kcanCaM0on;
-	fp kcanCaM0off;
-	fp k02can;
-	fp k20can;
-	fp k24can;
-	fp k42can;
-
-	// CaM Reaction fluxes
-	fp rcn02;
-	fp rcn24;
-
-	// CaM buffer fluxes
-	fp B;
-	fp rcn02B;
-	fp rcn24B;
-	fp rcn0B;
-	fp rcn2B;
-	fp rcn4B;
-
-	// CaN reaction fluxes 
-	fp Ca2CaN;
-	fp rcnCa4CaN;
-	fp rcn02CaN; 
-	fp rcn24CaN;
-	fp rcn0CaN;
-	fp rcn2CaN;
-	fp rcn4CaN;
-
-	// CaMKII reaction fluxes
-	fp Pix;
-	fp rcnCKib2;
-	fp rcnCKb2b;
-	fp rcnCKib;
-	fp T;
-	fp kbt;
-	fp rcnCKbt;
-	fp rcnCKtt2;
-	fp rcnCKta;
-	fp rcnCKt2a;
-	fp rcnCKt2b2;
-	fp rcnCKai;
-
-	// CaM equations
-	fp dCaM;
-	fp dCa2CaM;
-	fp dCa4CaM;
-	fp dCaMB;
-	fp dCa2CaMB;
-	fp dCa4CaMB;
-
-	// CaMKII equations
-	fp dPb2;																					// Pb2
-	fp dPb;																					// Pb
-	fp dPt;																					// Pt
-	fp dPt2;																					// Pt2
-	fp dPa;																					// Pa
-
-	// CaN equations
-	fp dCa4CaN;																			// Ca4CaN
-	fp dCaMCa4CaN;																	// CaMCa4CaN
-	fp dCa2CaMCa4CaN;																// Ca2CaMCa4CaN
-	fp dCa4CaMCa4CaN;																// Ca4CaMCa4CaN
-
-	//=====================================================================
-	//	EXECUTION													
-	//=====================================================================
-
-	// inputs
-	// CaMtot = d_params[params_offset];
-	Btot = d_params[params_offset+1];
-	CaMKIItot = d_params[params_offset+2];
-	CaNtot = d_params[params_offset+3];
-	PP1tot = d_params[params_offset+4];
-	K = d_params[16];
-	Mg = d_params[17];
-
-	// variable references
-	offset_1 = valu_offset;
-	offset_2 = valu_offset+1;
-	offset_3 = valu_offset+2;
-	offset_4 = valu_offset+3;
-	offset_5 = valu_offset+4;
-	offset_6 = valu_offset+5;
-	offset_7 = valu_offset+6;
-	offset_8 = valu_offset+7;
-	offset_9 = valu_offset+8;
-	offset_10 = valu_offset+9;
-	offset_11 = valu_offset+10;
-	offset_12 = valu_offset+11;
-	offset_13 = valu_offset+12;
-	offset_14 = valu_offset+13;
-	offset_15 = valu_offset+14;
-
-	// decoding input array
-	CaM				= d_initvalu[offset_1];
-	Ca2CaM			= d_initvalu[offset_2];
-	Ca4CaM			= d_initvalu[offset_3];
-	CaMB			= d_initvalu[offset_4];
-	Ca2CaMB			= d_initvalu[offset_5];
-	Ca4CaMB			= d_initvalu[offset_6];           
-	Pb2				= d_initvalu[offset_7];
-	Pb				= d_initvalu[offset_8];
-	Pt				= d_initvalu[offset_9];
-	Pt2				= d_initvalu[offset_10];
-	Pa				= d_initvalu[offset_11];                            
-	Ca4CaN			= d_initvalu[offset_12];
-	CaMCa4CaN		= d_initvalu[offset_13];
-	Ca2CaMCa4CaN	= d_initvalu[offset_14];
-	Ca4CaMCa4CaN	= d_initvalu[offset_15];
-
-	// Ca/CaM parameters
-	if (Mg <= 1){
-		Kd02 = 0.0025*(1+K/0.94-Mg/0.012)*(1+K/8.1+Mg/0.022);							// [uM^2]
-		Kd24 = 0.128*(1+K/0.64+Mg/0.0014)*(1+K/13.0-Mg/0.153);							// [uM^2]
-	}
-	else{
-		Kd02 = 0.0025*(1+K/0.94-1/0.012+(Mg-1)/0.060)*(1+K/8.1+1/0.022+(Mg-1)/0.068);   // [uM^2]
-		Kd24 = 0.128*(1+K/0.64+1/0.0014+(Mg-1)/0.005)*(1+K/13.0-1/0.153+(Mg-1)/0.150);  // [uM^2]
-	}
-	k20 = 10;																			// [s^-1]      
-	k02 = k20/Kd02;																		// [uM^-2 s^-1]
-	k42 = 500;																			// [s^-1]      
-	k24 = k42/Kd24;																		// [uM^-2 s^-1]
-
-	// CaM buffering (B) parameters
-	k0Boff = 0.0014;																	// [s^-1] 
-	k0Bon = k0Boff/0.2;																	// [uM^-1 s^-1] kon = koff/Kd
-	k2Boff = k0Boff/100;																// [s^-1] 
-	k2Bon = k0Bon;																		// [uM^-1 s^-1]
-	k4Boff = k2Boff;																	// [s^-1]
-	k4Bon = k0Bon;																		// [uM^-1 s^-1]
-
-	// using thermodynamic constraints
-	k20B = k20/100;																		// [s^-1] thermo constraint on loop 1
-	k02B = k02;																			// [uM^-2 s^-1] 
-	k42B = k42;																			// [s^-1] thermo constraint on loop 2
-	k24B = k24;																			// [uM^-2 s^-1]
-
-	// Wi Wa Wt Wp
-	kbi = 2.2;																			// [s^-1] (Ca4CaM dissocation from Wb)
-	kib = kbi/33.5e-3;																	// [uM^-1 s^-1]
-	kpp1 = 1.72;																		// [s^-1] (PP1-dep dephosphorylation rates)
-	Kmpp1 = 11.5;																		// [uM]
-	kib2 = kib;
-	kb2i = kib2*5;
-	kb24 = k24;
-	kb42 = k42*33.5e-3/5;
-	kta = kbi/1000;																		// [s^-1] (Ca4CaM dissociation from Wt)
-	kat = kib;																			// [uM^-1 s^-1] (Ca4CaM reassociation with Wa)
-	kt42 = k42*33.5e-6/5;
-	kt24 = k24;
-	kat2 = kib;
-	kt2a = kib*5;
-
-	// CaN parameters
-	kcanCaoff = 1;																		// [s^-1] 
-	kcanCaon = kcanCaoff/0.5;															// [uM^-1 s^-1] 
-	kcanCaM4on = 46;																	// [uM^-1 s^-1]
-	kcanCaM4off = 0.0013;																// [s^-1]
-	kcanCaM2on = kcanCaM4on;
-	kcanCaM2off = 2508*kcanCaM4off;
-	kcanCaM0on = kcanCaM4on;
-	kcanCaM0off = 165*kcanCaM2off;
-	k02can = k02;
-	k20can = k20/165;
-	k24can = k24;
-	k42can = k20/2508;
-
-	// CaM Reaction fluxes
-	rcn02 = k02*pow(Ca,2)*CaM - k20*Ca2CaM;
-	rcn24 = k24*pow(Ca,2)*Ca2CaM - k42*Ca4CaM;
-	
-	// CaM buffer fluxes
-	B = Btot - CaMB - Ca2CaMB - Ca4CaMB;
-	rcn02B = k02B*pow(Ca,2)*CaMB - k20B*Ca2CaMB;
-	rcn24B = k24B*pow(Ca,2)*Ca2CaMB - k42B*Ca4CaMB;
-	rcn0B = k0Bon*CaM*B - k0Boff*CaMB;
-	rcn2B = k2Bon*Ca2CaM*B - k2Boff*Ca2CaMB;
-	rcn4B = k4Bon*Ca4CaM*B - k4Boff*Ca4CaMB;
-	
-	// CaN reaction fluxes 
-	Ca2CaN = CaNtot - Ca4CaN - CaMCa4CaN - Ca2CaMCa4CaN - Ca4CaMCa4CaN;
-	rcnCa4CaN = kcanCaon*pow(Ca,2)*Ca2CaN - kcanCaoff*Ca4CaN;
-	rcn02CaN = k02can*pow(Ca,2)*CaMCa4CaN - k20can*Ca2CaMCa4CaN; 
-	rcn24CaN = k24can*pow(Ca,2)*Ca2CaMCa4CaN - k42can*Ca4CaMCa4CaN;
-	rcn0CaN = kcanCaM0on*CaM*Ca4CaN - kcanCaM0off*CaMCa4CaN;
-	rcn2CaN = kcanCaM2on*Ca2CaM*Ca4CaN - kcanCaM2off*Ca2CaMCa4CaN;
-	rcn4CaN = kcanCaM4on*Ca4CaM*Ca4CaN - kcanCaM4off*Ca4CaMCa4CaN;
-
-	// CaMKII reaction fluxes
-	Pix = 1 - Pb2 - Pb - Pt - Pt2 - Pa;
-	rcnCKib2 = kib2*Ca2CaM*Pix - kb2i*Pb2;
-	rcnCKb2b = kb24*pow(Ca,2)*Pb2 - kb42*Pb;
-	rcnCKib = kib*Ca4CaM*Pix - kbi*Pb;
-	T = Pb + Pt + Pt2 + Pa;
-	kbt = 0.055*T + 0.0074*pow(T,2) + 0.015*pow(T,3);
-	rcnCKbt = kbt*Pb - kpp1*PP1tot*Pt/(Kmpp1+CaMKIItot*Pt);
-	rcnCKtt2 = kt42*Pt - kt24*pow(Ca,2)*Pt2;
-	rcnCKta = kta*Pt - kat*Ca4CaM*Pa;
-	rcnCKt2a = kt2a*Pt2 - kat2*Ca2CaM*Pa;
-	rcnCKt2b2 = kpp1*PP1tot*Pt2/(Kmpp1+CaMKIItot*Pt2);
-	rcnCKai = kpp1*PP1tot*Pa/(Kmpp1+CaMKIItot*Pa);
-
-	// CaM equations
-	dCaM = 1e-3*(-rcn02 - rcn0B - rcn0CaN);
-	dCa2CaM = 1e-3*(rcn02 - rcn24 - rcn2B - rcn2CaN + CaMKIItot*(-rcnCKib2 + rcnCKt2a) );
-	dCa4CaM = 1e-3*(rcn24 - rcn4B - rcn4CaN + CaMKIItot*(-rcnCKib+rcnCKta) );
-	dCaMB = 1e-3*(rcn0B-rcn02B);
-	dCa2CaMB = 1e-3*(rcn02B + rcn2B - rcn24B);
-	dCa4CaMB = 1e-3*(rcn24B + rcn4B);
-
-	// CaMKII equations
-	dPb2 = 1e-3*(rcnCKib2 - rcnCKb2b + rcnCKt2b2);										// Pb2
-	dPb = 1e-3*(rcnCKib + rcnCKb2b - rcnCKbt);											// Pb
-	dPt = 1e-3*(rcnCKbt-rcnCKta-rcnCKtt2);												// Pt
-	dPt2 = 1e-3*(rcnCKtt2-rcnCKt2a-rcnCKt2b2);											// Pt2
-	dPa = 1e-3*(rcnCKta+rcnCKt2a-rcnCKai);												// Pa
-
-	// CaN equations
-	dCa4CaN = 1e-3*(rcnCa4CaN - rcn0CaN - rcn2CaN - rcn4CaN);							// Ca4CaN
-	dCaMCa4CaN = 1e-3*(rcn0CaN - rcn02CaN);												// CaMCa4CaN
-	dCa2CaMCa4CaN = 1e-3*(rcn2CaN+rcn02CaN-rcn24CaN);									// Ca2CaMCa4CaN
-	dCa4CaMCa4CaN = 1e-3*(rcn4CaN+rcn24CaN);											// Ca4CaMCa4CaN
-
-	// encode output array
-	d_finavalu[offset_1] = dCaM;
-	d_finavalu[offset_2] = dCa2CaM;
-	d_finavalu[offset_3] = dCa4CaM;
-	d_finavalu[offset_4] = dCaMB;
-	d_finavalu[offset_5] = dCa2CaMB;
-	d_finavalu[offset_6] = dCa4CaMB;
-	d_finavalu[offset_7] = dPb2;
-	d_finavalu[offset_8] = dPb;
-	d_finavalu[offset_9] = dPt;
-	d_finavalu[offset_10] = dPt2;
-	d_finavalu[offset_11] = dPa;
-	d_finavalu[offset_12] = dCa4CaN;
-	d_finavalu[offset_13] = dCaMCa4CaN;
-	d_finavalu[offset_14] = dCa2CaMCa4CaN;
-	d_finavalu[offset_15] = dCa4CaMCa4CaN;
-
-	// write to global variables for adjusting Ca buffering in EC coupling model
-	d_finavalu[com_offset] = 1e-3*(2*CaMKIItot*(rcnCKtt2-rcnCKb2b) - 2*(rcn02+rcn24+rcn02B+rcn24B+rcnCa4CaN+rcn02CaN+rcn24CaN)); // [uM/msec]
-	//d_finavalu[JCa] = 1; // [uM/msec]
-
-}
-
-//========================================================================================================================================================================================================200
-//	KERNEL
-//========================================================================================================================================================================================================200
-
-__kernel void 
-kernel_gpu_opencl(	int timeinst,
-					__global fp *d_initvalu,
-					__global fp *d_finavalu,
-					__global fp *d_params,
-					__global fp *d_com)
-{
-
-	//======================================================================================================================================================150
-	// 	VARIABLES
-	//======================================================================================================================================================150
-
-	// CUDA indexes
-	int bx;																				// get current horizontal block index (0-n)
-	int tx;																				// get current horizontal thread index (0-n)
-
-	// pointers
-	int valu_offset;																	// inivalu and finavalu offset
-	int params_offset;																	// parameters offset
-	int com_offset;																		// kernel1-kernel2 communication offset
-
-	// module parameters
-	fp CaDyad;																			// from ECC model, *** Converting from [mM] to [uM] ***
-	fp CaSL;																			// from ECC model, *** Converting from [mM] to [uM] ***
-	fp CaCyt;																			// from ECC model, *** Converting from [mM] to [uM] ***
-
-	//======================================================================================================================================================150
-	// 	COMPUTATION
-	//======================================================================================================================================================150
-
-	// indexes
-	// bx = blockIdx.x;																// get current horizontal block index (0-n)
-	// tx = threadIdx.x;																// get current horizontal thread index (0-n)
-	bx = get_group_id(0);															// get current horizontal block index (0-n)
-	tx = get_local_id(0);															// get current horizontal thread index (0-n)
-
-	//====================================================================================================100
-	//	ECC
-	//====================================================================================================100
-
-	// limit to useful threads
-	if(bx == 0){																		// first processor runs ECC
-
-		if(tx == 0){																	// only 1 thread runs it, since its a sequential code
-
-			// thread offset
-			valu_offset = 0;															//
-			// ecc function
-			kernel_ecc(	timeinst,
-						d_initvalu,
-						d_finavalu,
-						valu_offset,
-						d_params);
-
-		}
-
-	}
-
-	//====================================================================================================100
-	//	CAM x 3
-	//====================================================================================================100
-
-	// limit to useful threads
-	else if(bx == 1){																	// second processor runs CAMs (in parallel with ECC)
-
-		if(tx == 0){																	// only 1 thread runs it, since its a sequential code
-
-			// specific
-			valu_offset = 46;
-			params_offset = 0;
-			com_offset = 0;
-			CaDyad = d_initvalu[35]*1e3;												// from ECC model, *** Converting from [mM] to [uM] ***
-			// cam function for Dyad
-			kernel_cam(	timeinst,
-						d_initvalu,
-						d_finavalu,
-						valu_offset,
-						d_params,
-						params_offset,
-						d_com,
-						com_offset,
-						CaDyad);
-
-			// specific
-			valu_offset = 61;
-			params_offset = 5;
-			com_offset = 1;
-			CaSL = d_initvalu[36]*1e3;													// from ECC model, *** Converting from [mM] to [uM] ***
-			// cam function for Dyad
-			kernel_cam(	timeinst,
-						d_initvalu,
-						d_finavalu,
-						valu_offset,
-						d_params,
-						params_offset,
-						d_com,
-						com_offset,
-						CaSL);
-
-			// specific
-			valu_offset = 76;
-			params_offset = 10;
-			com_offset = 2;
-			CaCyt = d_initvalu[37]*1e3;										// from ECC model, *** Converting from [mM] to [uM] ***
-			// cam function for Dyad
-			kernel_cam(	timeinst,
-						d_initvalu,
-						d_finavalu,
-						valu_offset,
-						d_params,
-						params_offset,
-						d_com,
-						com_offset,
-						CaCyt);
-
-		}
-
-	}
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	//======================================================================================================================================================150
-	// 	END
-	//======================================================================================================================================================150
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 429
opencl/myocyte/kernel/kernel_gpu_opencl_wrapper.c

@@ -1,429 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	COMMON
-//======================================================================================================================================================150
-
-#include "../common.h"									// (in directory)
-
-//======================================================================================================================================================150
-//	UTILITIES
-//======================================================================================================================================================150
-
-#include "../util/timer/timer.h"						// (in directory)
-
-//======================================================================================================================================================150
-//	KERNEL
-//======================================================================================================================================================150
-
-#include "./solver.c"									// (in directory)
-#include "../util/opencl/opencl.h"						// (in directory)
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <stdio.h>										// (in path known to compiler)	needed by printf
-#include <string.h>										// (in path known to compiler)	needed by strlen
-#include <CL/cl.h>										// (in path provided to compiler)	needed by OpenCL types and functions
-
-//======================================================================================================================================================150
-//	HEADER
-//======================================================================================================================================================150
-
-#include "kernel_gpu_opencl_wrapper.h"					// (in directory)
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	MAIN FUNCTION
-//========================================================================================================================================================================================================200
-
-int 
-kernel_gpu_opencl_wrapper(	int xmax,
-							int workload,
-
-							fp ***y,
-							fp **x,
-							fp **params,
-							fp *com)
-{
-
-	//======================================================================================================================================================150
-	//	VARIABLES
-	//======================================================================================================================================================150
-
-	long long time0;
-	long long time1;
-	long long time2;
-	long long time3;
-	long long time4;
-	long long time5;
-	long long timecopyin = 0;
-	long long timekernel = 0;
-	long long timecopyout = 0;
-	long long timeother;
-
-	time0 = get_time();
-
-	int i;
-
-	//======================================================================================================================================================150
-	//	GPU SETUP
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	COMMON VARIABLES
-	//====================================================================================================100
-
-	// common variables
-	cl_int error;
-
-	//====================================================================================================100
-	//	GET PLATFORMS (Intel, AMD, NVIDIA, based on provided library), SELECT ONE
-	//====================================================================================================100
-
-	// Get the number of available platforms
-	cl_uint num_platforms;
-	error = clGetPlatformIDs(	0, 
-								NULL, 
-								&num_platforms);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Get the list of available platforms
-	cl_platform_id *platforms = (cl_platform_id *)malloc(sizeof(cl_platform_id) * num_platforms);
-	error = clGetPlatformIDs(	num_platforms, 
-								platforms, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Select the 1st platform
-	cl_platform_id platform = platforms[0];
-
-	// Get the name of the selected platform and print it (if there are multiple platforms, choose the first one)
-	char pbuf[100];
-	error = clGetPlatformInfo(	platform, 
-								CL_PLATFORM_VENDOR, 
-								sizeof(pbuf), 
-								pbuf, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	printf("Platform: %s\n", pbuf);
-
-	//====================================================================================================100
-	//	CREATE CONTEXT FOR THE PLATFORM
-	//====================================================================================================100
-
-	// Create context properties for selected platform
-	cl_context_properties context_properties[3] = {	CL_CONTEXT_PLATFORM, 
-													(cl_context_properties) platform, 
-													0};
-
-	// Create context for selected platform being GPU
-	cl_context context;
-	context = clCreateContextFromType(	context_properties, 
-										CL_DEVICE_TYPE_GPU, 
-										NULL, 
-										NULL, 
-										&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	GET DEVICES AVAILABLE FOR THE CONTEXT, SELECT ONE
-	//====================================================================================================100
-
-	// Get the number of devices (previousely selected for the context)
-	size_t devices_size;
-	error = clGetContextInfo(	context, 
-								CL_CONTEXT_DEVICES, 
-								0, 
-								NULL, 
-								&devices_size);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Get the list of devices (previousely selected for the context)
-	cl_device_id *devices = (cl_device_id *) malloc(devices_size);
-	error = clGetContextInfo(	context, 
-								CL_CONTEXT_DEVICES, 
-								devices_size, 
-								devices, 
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Select the first device (previousely selected for the context) (if there are multiple devices, choose the first one)
-	cl_device_id device;
-	device = devices[0];
-
-	// Get the name of the selected device (previousely selected for the context) and print it
-	error = clGetDeviceInfo(device, 
-							CL_DEVICE_NAME, 
-							sizeof(pbuf), 
-							pbuf, 
-							NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-	printf("Device: %s\n", pbuf);
-
-	//====================================================================================================100
-	//	CREATE COMMAND QUEUE FOR THE DEVICE
-	//====================================================================================================100
-
-	// Create a command queue
-	cl_command_queue command_queue;
-	command_queue = clCreateCommandQueue(	context, 
-											device, 
-											0, 
-											&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	CRATE PROGRAM, COMPILE IT
-	//====================================================================================================100
-
-	// Load kernel source code from file
-	const char *source = load_kernel_source("./kernel/kernel_gpu_opencl.cl");
-	size_t sourceSize = strlen(source);
-
-	// Create the program
-	cl_program program = clCreateProgramWithSource(	context, 
-													1, 
-													&source, 
-													&sourceSize, 
-													&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Compile the program
-	error = clBuildProgram(	program, 
-							1, 
-							&device, 
-							"-I./../", 
-							NULL, 
-							NULL);
-	// Print warnings and errors from compilation
-	static char log[65536]; 
-	memset(log, 0, sizeof(log));
-	clGetProgramBuildInfo(	program, 
-							device, 
-							CL_PROGRAM_BUILD_LOG, 
-							sizeof(log)-1, 
-							log, 
-							NULL);
-	printf("-----OpenCL Compiler Output-----\n");
-	if (strstr(log,"warning:") || strstr(log, "error:")) 
-		printf("<<<<\n%s\n>>>>\n", log);
-	printf("--------------------------------\n");
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Create kernel
-	cl_kernel kernel;
-	kernel = clCreateKernel(program, 
-							"kernel_gpu_opencl", 
-							&error);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	INITIAL DRIVER OVERHEAD
-	//====================================================================================================100
-
-	// cudaThreadSynchronize();
-
-	time1 = get_time();
-
-	//======================================================================================================================================================150
-	//	ALLOCATE MEMORY
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	d_initvalu_mem
-	//====================================================================================================100
-
-	int d_initvalu_mem;
-	d_initvalu_mem = EQUATIONS * sizeof(fp);
-	cl_mem d_initvalu;
-	d_initvalu = clCreateBuffer(context,					// context
-								CL_MEM_READ_WRITE,			// flags
-								d_initvalu_mem,				// size of buffer
-								NULL,						// host pointer (optional)
-								&error );					// returned error
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	d_finavalu_mem
-	//====================================================================================================100
-
-	int d_finavalu_mem;
-	d_finavalu_mem = EQUATIONS * sizeof(fp);
-	cl_mem d_finavalu;
-	d_finavalu = clCreateBuffer(context, 
-								CL_MEM_READ_WRITE, 
-								d_finavalu_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	d_params_mem
-	//====================================================================================================100
-
-	int d_params_mem;
-	d_params_mem = PARAMETERS * sizeof(fp);
-	cl_mem d_params;
-	d_params = clCreateBuffer(	context, 
-								CL_MEM_READ_WRITE, 
-								d_params_mem, 
-								NULL, 
-								&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	d_com_mem
-	//====================================================================================================100
-
-	int d_com_mem;
-	d_com_mem = 3 * sizeof(fp);
-	cl_mem d_com;
-	d_com = clCreateBuffer(	context, 
-							CL_MEM_READ_WRITE, 
-							d_com_mem, 
-							NULL, 
-							&error );
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time2 = get_time();
-
-	//======================================================================================================================================================150
-	//	EXECUTION
-	//======================================================================================================================================================150
-
-	int status;
-
-	for(i=0; i<workload; i++){
-
-		status = solver(	y[i],
-							x[i],
-							xmax,
-							params[i],
-							com,
-
-							d_initvalu,
-							d_finavalu,
-							d_params,
-							d_com,
-
-							command_queue,
-							kernel,
-
-							&timecopyin,
-							&timekernel,
-							&timecopyout);
-
-		if(status !=0){
-			printf("STATUS: %d\n", status);
-		}
-
-	}
-
-	// // // print results
-	// // int k;
-	// // for(i=0; i<workload; i++){
-		// // printf("WORKLOAD %d:\n", i);
-		// // for(j=0; j<(xmax+1); j++){
-			// // printf("\tTIME %d:\n", j);
-			// // for(k=0; k<EQUATIONS; k++){
-				// // printf("\t\ty[%d][%d][%d]=%13.10f\n", i, j, k, y[i][j][k]);
-			// // }
-		// // }
-	// // }
-
-	time3 = get_time();
-
-	//======================================================================================================================================================150
-	//	FREE GPU MEMORY
-	//======================================================================================================================================================150
-
-	// Release kernels...
-	clReleaseKernel(kernel);
-
-	// Now the program...
-	clReleaseProgram(program);
-
-	// Clean up the device memory...
-	clReleaseMemObject(d_initvalu);
-	clReleaseMemObject(d_finavalu);
-	clReleaseMemObject(d_params);
-	clReleaseMemObject(d_com);
-
-	// Flush the queue
-	error = clFlush(command_queue);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// ...and finally, the queue and context.
-	clReleaseCommandQueue(command_queue);
-
-	// ???
-	clReleaseContext(context);
-
-	time4= get_time();
-
-	//======================================================================================================================================================150
-	//	DISPLAY TIMING
-	//======================================================================================================================================================150
-
-	printf("Time spent in different stages of the application:\n");
-	printf("%15.12f s, %15.12f % : CPU: GPU SETUP\n", 								(float) (time1-time0) / 1000000, (float) (time1-time0) / (float) (time4-time0) * 100);
-	printf("%15.12f s, %15.12f % : CPU: ALLOCATE GPU MEMORY\n", 					(float) (time2-time1) / 1000000, (float) (time2-time1) / (float) (time4-time0) * 100);
-	printf("%15.12f s, %15.12f % : GPU: COMPUTATION\n", 							(float) (time3-time2) / 1000000, (float) (time3-time2) / (float) (time4-time0) * 100);
-
-	printf("\tGPU: COMPUTATION Components:\n");
-	printf("\t%15.12f s, %15.12f % : GPU: COPY DATA IN\n", 							(float) (timecopyin) / 1000000, (float) (timecopyin) / (float) (time4-time0) * 100);
-	printf("\t%15.12f s, %15.12f % : GPU: KERNEL\n", 								(float) (timekernel) / 1000000, (float) (timekernel) / (float) (time4-time0) * 100);
-	printf("\t%15.12f s, %15.12f % : GPU: COPY DATA OUT\n", 						(float) (timecopyout) / 1000000, (float) (timecopyout) / (float) (time4-time0) * 100);
-	timeother = time3-time2-timecopyin-timekernel-timecopyout;
-	printf("\t%15.12f s, %15.12f % : GPU: OTHER\n", 								(float) (timeother) / 1000000, (float) (timeother) / (float) (time4-time0) * 100);
-
-	printf("%15.12f s, %15.12f % : CPU: FREE GPU MEMORY\n", 						(float) (time4-time3) / 1000000, (float) (time4-time3) / (float) (time4-time0) * 100);
-	printf("Total time:\n");
-	printf("%.12f s\n", 															(float) (time4-time0) / 1000000);
-
-	//======================================================================================================================================================150
-	//	RETURN
-	//======================================================================================================================================================150
-
-	return 0;
-
-	//======================================================================================================================================================150
-	//	END
-	//======================================================================================================================================================150
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 24
opencl/myocyte/kernel/kernel_gpu_opencl_wrapper.h

@@ -1,24 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	FUNCTION
-//========================================================================================================================================================================================================200
-
-int 
-kernel_gpu_opencl_wrapper(	int xmax,
-							int workload,
-
-							fp*** y,
-							fp** x,
-							fp** params,
-							fp* com);
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 293
opencl/myocyte/kernel/master.c

@@ -1,293 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE / INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	COMMON
-//======================================================================================================================================================150
-
-#include "../common.h"									// (in path provided here)
-
-//======================================================================================================================================================150
-//	KERNEL
-//======================================================================================================================================================150
-
-#include "./kernel_fin.c"									// (in path provided here)
-#include "../util/opencl/opencl.h"						// (in path provided here)
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <stdio.h>										// (in path known to compiler)	needed by printf
-#include <CL/cl.h>										// (in path provided to compiler)	needed by OpenCL types and functions
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	MAIN FUNCTION
-//========================================================================================================================================================================================================200
-
-void 
-master(	fp timeinst,
-		fp *initvalu,
-		fp *parameter,
-		fp *finavalu,
-		fp *com,
-
-		cl_mem d_initvalu,
-		cl_mem d_finavalu,
-		cl_mem d_params,
-		cl_mem d_com,
-
-		cl_command_queue command_queue,
-		cl_kernel kernel,
-
-		long long *timecopyin,
-		long long *timekernel,
-		long long *timecopyout)
-{
-
-	//======================================================================================================================================================150
-	//	VARIABLES
-	//======================================================================================================================================================150
-
-	//timer
-	long long time0;
-	long long time1;
-	long long time2;
-	long long time3;
-
-	// counters
-	int i;
-
-	// offset pointers
-	int initvalu_offset_ecc;																// 46 points
-	int initvalu_offset_Dyad;															// 15 points
-	int initvalu_offset_SL;																// 15 points
-	int initvalu_offset_Cyt;																// 15 poitns
-
-	// common variables
-	cl_int error;
-
-	time0 = get_time();
-
-	//======================================================================================================================================================150
-	//	COPY DATA TO GPU MEMORY
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	initvalu
-	//====================================================================================================100
-
-	int d_initvalu_mem;
-	d_initvalu_mem = EQUATIONS * sizeof(fp);
-	error = clEnqueueWriteBuffer(	command_queue,			// command queue
-									d_initvalu,				// destination
-									1,						// block the source from access until this copy operation complates (1=yes, 0=no)
-									0,						// offset in destination to write to
-									d_initvalu_mem,			// size to be copied
-									initvalu,				// source
-									0,						// # of events in the list of events to wait for
-									NULL,					// list of events to wait for
-									NULL);					// ID of this operation to be used by waiting operations
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	parameter
-	//====================================================================================================100
-
-	int d_params_mem;
-	d_params_mem = PARAMETERS * sizeof(fp);
-	error = clEnqueueWriteBuffer(	command_queue,
-									d_params,
-									1,
-									0,
-									d_params_mem,
-									parameter,
-									0,
-									NULL,
-									NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	time1 = get_time();
-
-	//======================================================================================================================================================150
-	//	GPU: KERNEL
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	KERNEL EXECUTION PARAMETERS
-	//====================================================================================================100
-
-	size_t local_work_size[1];
-	local_work_size[0] = NUMBER_THREADS;
-	size_t global_work_size[1];
-	global_work_size[0] = 2*NUMBER_THREADS;
-
-	// printf("# of blocks = %d, # of threads/block = %d (ensure that device can handle)\n", (int)global_work_size[0]/(int)local_work_size[0], (int)local_work_size[0]);
-
-	//====================================================================================================100
-	//	KERNEL ARGUMENTS
-	//====================================================================================================100
-
-	clSetKernelArg(	kernel, 
-					0, 
-					sizeof(int), 
-					(void *) &timeinst);
-	clSetKernelArg(	kernel, 
-					1, 
-					sizeof(cl_mem), 
-					(void *) &d_initvalu);
-	clSetKernelArg(	kernel, 
-					2, 
-					sizeof(cl_mem), 
-					(void *) &d_finavalu);
-	clSetKernelArg(	kernel, 
-					3, 
-					sizeof(cl_mem), 
-					(void *) &d_params);
-	clSetKernelArg(	kernel, 
-					4, 
-					sizeof(cl_mem), 
-					(void *) &d_com);
-
-	//====================================================================================================100
-	//	KERNEL
-	//====================================================================================================100
-
-	error = clEnqueueNDRangeKernel(	command_queue, 
-									kernel, 
-									1, 
-									NULL, 
-									global_work_size, 
-									local_work_size, 
-									0, 
-									NULL, 
-									NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	// Wait for all operations to finish, much like synchronizing threads in CUDA
-	error = clFinish(command_queue);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	time2 = get_time();
-
-	//======================================================================================================================================================150
-	//	COPY DATA TO SYSTEM MEMORY
-	//======================================================================================================================================================150
-
-	//====================================================================================================100
-	//	finavalu
-	//====================================================================================================100
-
-	int d_finavalu_mem;
-	d_finavalu_mem = EQUATIONS * sizeof(fp);
-	error = clEnqueueReadBuffer(command_queue,               // The command queue.
-								d_finavalu,                  // The image on the device.
-								CL_TRUE,                     // Blocking? (ie. Wait at this line until read has finished?)
-								0,                           // Offset. None in this case.
-								d_finavalu_mem, 			 // Size to copy.
-								finavalu,                    // The pointer to the image on the host.
-								0,                           // Number of events in wait list. Not used.
-								NULL,                        // Event wait list. Not used.
-								NULL);                       // Event object for determining status. Not used.
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	com
-	//====================================================================================================100
-
-	int d_com_mem;
-	d_com_mem = 3 * sizeof(fp);
-	error = clEnqueueReadBuffer(command_queue,
-								d_com,
-								CL_TRUE,
-								0,
-								d_com_mem,
-								com,
-								0,
-								NULL,
-								NULL);
-	if (error != CL_SUCCESS) 
-		fatal_CL(error, __LINE__);
-
-	//====================================================================================================100
-	//	END
-	//====================================================================================================100
-
-	time3 = get_time();
-
-	//======================================================================================================================================================150
-	//	CPU: FINAL KERNEL
-	//======================================================================================================================================================150
-
-	// *copyin_time,
-	// *kernel_time,
-	// *copyout_time)
-
-	timecopyin[0] = timecopyin[0] + (time1-time0);
-	timekernel[0] = timekernel[0] + (time2-time1);
-	timecopyout[0] = timecopyout[0] + (time3-time2);
-
-	//======================================================================================================================================================150
-	//	CPU: FINAL KERNEL
-	//======================================================================================================================================================150
-
-	initvalu_offset_ecc = 0;												// 46 points
-	initvalu_offset_Dyad = 46;												// 15 points
-	initvalu_offset_SL = 61;												// 15 points
-	initvalu_offset_Cyt = 76;												// 15 poitns
-
-	kernel_fin(	initvalu,
-				initvalu_offset_ecc,
-				initvalu_offset_Dyad,
-				initvalu_offset_SL,
-				initvalu_offset_Cyt,
-				parameter,
-				finavalu,
-				com[0],
-				com[1],
-				com[2]);
-
-	//======================================================================================================================================================150
-	//	COMPENSATION FOR NANs and INFs
-	//======================================================================================================================================================150
-
-	for(i=0; i<EQUATIONS; i++){
-		if (isnan(finavalu[i]) == 1){ 
-			finavalu[i] = 0.0001;												// for NAN set rate of change to 0.0001
-		}
-		else if (isinf(finavalu[i]) == 1){ 
-			finavalu[i] = 0.0001;												// for INF set rate of change to 0.0001
-		}
-	}
-
-	//======================================================================================================================================================150
-	//	END
-	//======================================================================================================================================================150
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 358
opencl/myocyte/kernel/solver.c

@@ -1,358 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DESCRIPTION
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	UPDATE
-//======================================================================================================================================================150
-
-//	Summary of changes by Lukasz G. Szafaryn:
-
-//	1) The original code was obtained from: Mathematics Source Library (http://mymathlib.webtrellis.net/index.html)
-//	2) This solver and particular solving algorithm used with it (embedded_fehlberg_7_8) were adapted to work with a set of equations, not just one like in original version.
-
-//	3) In order for solver to provide deterministic number of steps (needed for particular amount of memore previousely allocated for results), every next step is incremented by 1 time unit (h_init).
-//	4) Function assumes that time interval starts at 0 (xmin) and ends at integer value (xmax) specified by the uses as a parameter on command line.
-//	5) The appropriate amount of memory is previousely allocated for that range (y).
-
-//	5) This setup in 3) - 5) allows solver to adjust the step ony from current time instance to current time instance + 0.9. The next time instance is current time instance + 1;
-
-//	6) Solver also takes parameters (params) that it then passes to the equations.
-
-//	7) The original solver cannot handle cases when equations return NAN and INF values due to discontinuities and /0. That is why equations provided by user need to make sure that no NAN and INF are returned.
-
-//	Last update: 15 DEC 09
-
-//======================================================================================================================================================150
-//	DESCRIPTION
-//======================================================================================================================================================150
-
-// int solver( fp (*f)(fp, fp), fp y[],        //
-//       fp x, fp h, fp xmax, fp *h_next, fp tolerance )  //
-//                                                                            //
-//  Description:                                                              //
-//     This function solves the differential equation y'=f(x,y) with the      //
-//     initial condition y(x) = y[0].  The value at xmax is returned in y[1]. //
-//     The function returns 0 if successful or -1 if it fails.                //
-//                                                                            //
-//  Arguments:                                                                //
-//     fp *f  Pointer to the function which returns the slope at (x,y) of //
-//                integral curve of the differential equation y' = f(x,y)     //
-//                which passes through the point (x0,y0) corresponding to the //
-//                initial condition y(x0) = y0.                               //
-//     fp y[] On input y[0] is the initial value of y at x, on output     //
-//                y[1] is the solution at xmax.                               //
-//     fp x   The initial value of x.                                     //
-//     fp h   Initial step size.                                          //
-//     fp xmax The endpoint of x.                                         //
-//     fp *h_next   A pointer to the estimated step size for successive   //
-//                      calls to solver.                       //
-//     fp tolerance The tolerance of y(xmax), i.e. a solution is sought   //
-//                so that the relative error < tolerance.                     //
-//                                                                            //
-//  Return Values:                                                            //
-//     0   The solution of y' = f(x,y) from x to xmax is stored y[1] and      //
-//         h_next has the value to the next size to try.                      //
-//    -1   The solution of y' = f(x,y) from x to xmax failed.                 //
-//    -2   Failed because either xmax < x or the step size h <= 0.            //
-//    -3   Memory limit allocated for results was reached                     //
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	COMMON
-//======================================================================================================================================================150
-
-#include "../common.h"								// (in path provided here)
-
-//======================================================================================================================================================150
-//	DEFINE
-//======================================================================================================================================================150
-
-#define max(x,y) ( (x) < (y) ? (y) : (x) )
-#define min(x,y) ( (x) < (y) ? (x) : (y) )
-
-#define ATTEMPTS 12
-#define MIN_SCALE_FACTOR 0.125
-#define MAX_SCALE_FACTOR 4.0
-
-//======================================================================================================================================================150
-//	KERNEL
-//======================================================================================================================================================150
-
-#include "./embedded_fehlberg_7_8.c"				// (in path provided here)
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <stdlib.h>									// (in path known to compiler)	needed by malloc, free
-#include <math.h>									// (in path known to compiler)	needed by pow, fabs
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	FUNCTION
-//========================================================================================================================================================================================================200
-
-int 
-solver(	fp **y,
-		fp *x,
-		int xmax,
-		fp *params,
-		fp *com,
-
-		cl_mem d_initvalu,
-		cl_mem d_finavalu,
-		cl_mem d_params,
-		cl_mem d_com,
-
-		cl_command_queue command_queue,
-		cl_kernel kernel,
-
-		long long *timecopyin,
-		long long *timecopykernel,
-		long long *timecopyout)
-{
-
-	//========================================================================================================================
-	//	VARIABLES
-	//========================================================================================================================
-
-	// solver parameters
-	fp err_exponent;
-	int error;
-	int outside;
-	fp h;
-	fp h_init;
-	fp tolerance;
-	int xmin;
-
-	// memory
-	fp scale_min;
-	fp scale_fina;
-	fp* err= (fp *) malloc(EQUATIONS* sizeof(fp));
-	fp* scale= (fp *) malloc(EQUATIONS* sizeof(fp));
-	fp* yy= (fp *) malloc(EQUATIONS* sizeof(fp));
-
-	// counters
-	int i, j, k;
-
-	//========================================================================================================================
-	//		INITIAL SETUP
-	//========================================================================================================================
-
-	// solver parameters
-	err_exponent = 1.0 / 7.0;
-	h_init = 1;
-	h = h_init;
-	xmin = 0;
-	tolerance = 10 / (fp)(xmax-xmin);
-
-	// save value for initial time instance
-	x[0] = 0;
-
-	//========================================================================================================================
-	//		CHECKING
-	//========================================================================================================================
-
-	// Verify that the step size is positive and that the upper endpoint of integration is greater than the initial enpoint.               //
-	if (xmax < xmin || h <= 0.0){
-		return -2;
-	}
-
-	// If the upper endpoint of the independent variable agrees with the initial value of the independent variable.  Set the value of the dependent variable and return success. //
-	if (xmax == xmin){
-		return 0; 
-	}
-
-	// Insure that the step size h is not larger than the length of the integration interval.                                            //
-	if (h > (xmax - xmin) ) { 
-		h = (fp)xmax - (fp)xmin; 
-	}
-
-	//========================================================================================================================
-	//		SOLVING
-	//========================================================================================================================
-
-	printf("Time Steps: ");
-	fflush(0);
-
-	for(k=1; k<=xmax; k++) {											// start after initial value
-
-		x[k] = k-1;
-		h = h_init;
-
-		//==========================================================================================
-		//		REINITIALIZE VARIABLES
-		//==========================================================================================
-
-		scale_fina = 1.0;
-
-		//==========================================================================================
-		//		MAKE ATTEMPTS TO MINIMIZE ERROR
-		//==========================================================================================
-
-		// make attempts to minimize error
-		for (j = 0; j < ATTEMPTS; j++) {
-
-			//============================================================
-			//		REINITIALIZE VARIABLES
-			//============================================================
-
-			error = 0;
-			outside = 0;
-			scale_min = MAX_SCALE_FACTOR;
-
-			//============================================================
-			//		EVALUATE ALL EQUATIONS
-			//============================================================
-
-			embedded_fehlberg_7_8(	x[k],
-									h,
-									y[k-1],
-									y[k],
-									err,
-									params,
-									com,
-
-									d_initvalu,
-									d_finavalu,
-									d_params,
-									d_com,
-
-									command_queue,
-									kernel,
-
-									timecopyin,
-									timecopykernel,
-									timecopyout);
-
-			//============================================================
-			//		IF THERE WAS NO ERROR FOR ANY OF EQUATIONS, SET SCALE AND LEAVE THE LOOP
-			//============================================================
-
-			for(i=0; i<EQUATIONS; i++){
-				if(err[i] > 0){
-					error = 1;
-				}
-			}
-			if (error != 1) {
-				scale_fina = MAX_SCALE_FACTOR; 
-				break;
-			}
-
-			//============================================================
-			//		FIGURE OUT SCALE AS THE MINIMUM OF COMPONENT SCALES
-			//============================================================
-
-			for(i=0; i<EQUATIONS; i++){
-				if(y[k-1][i] == 0.0){
-					yy[i] = tolerance;
-				}
-				else{
-					yy[i] = fabs(y[k-1][i]);
-				}
-				scale[i] = 0.8 * pow( tolerance * yy[i] / err[i] , err_exponent );
-				if(scale[i]<scale_min){
-					scale_min = scale[i];
-				}
-			}
-			scale_fina = min( max(scale_min,MIN_SCALE_FACTOR), MAX_SCALE_FACTOR);
-
-			//============================================================
-			//		IF WITHIN TOLERANCE, FINISH ATTEMPTS...
-			//============================================================
-
-			for(i=0; i<EQUATIONS; i++){
-				if ( err[i] > ( tolerance * yy[i] ) ){
-					outside = 1;
-				}
-			}
-			if (outside == 0){
-				break;
-			}
-
-			//============================================================
-			//		...OTHERWISE, ADJUST STEP FOR NEXT ATTEMPT
-			//============================================================
-
-			// scale next step in a default way
-			h = h * scale_fina;
-
-			// limit step to 0.9, because when it gets close to 1, it no longer makes sense, as 1 is already the next time instance (added to original algorithm)
-			if (h >= 0.9) {
-				h = 0.9;
-			}
-
-			// if instance+step exceeds range limit, limit to that range
-			if ( x[k] + h > (fp)xmax ){
-				h = (fp)xmax - x[k];
-			}
-
-			// if getting closer to range limit, decrease step
-			else if ( x[k] + h + 0.5 * h > (fp)xmax ){
-				h = 0.5 * h;
-			}
-
-		}
-
-		//==========================================================================================
-		//		SAVE TIME INSTANCE THAT SOLVER ENDED UP USING
-		//==========================================================================================
-
-		x[k] = x[k] + h;
-
-		//==========================================================================================
-		//		IF MAXIMUM NUMBER OF ATTEMPTS REACHED AND CANNOT GIVE SOLUTION, EXIT PROGRAM WITH ERROR
-		//==========================================================================================
-
-		if ( j >= ATTEMPTS ) {
-			return -1; 
-		}
-
-		printf("%d ", k);
-		fflush(0);
-
-	}
-
-	printf("\n");
-	fflush(0);
-
-	//========================================================================================================================
-	//		FREE MEMORY
-	//========================================================================================================================
-
-	free(err);
-	free(scale);
-	free(yy);
-
-	//========================================================================================================================
-	//		FINAL RETURN
-	//========================================================================================================================
-
-	return 0;
-
-//======================================================================================================================================================
-//======================================================================================================================================================
-//		END OF SOLVER FUNCTION
-//======================================================================================================================================================
-//======================================================================================================================================================
-
-} 
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 354
opencl/myocyte/main.c

@@ -1,354 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//======================================================================================================================================================150
-//====================================================================================================100
-//==================================================50
-
-//========================================================================================================================================================================================================200
-//	UPDATE
-//========================================================================================================================================================================================================200
-
-// Lukasz G. Szafaryn 24 JAN 09
-
-//========================================================================================================================================================================================================200
-//	DESCRIPTION
-//========================================================================================================================================================================================================200
-
-// Myocyte application models cardiac myocyte (heart muscle cell) and simulates its behavior according to the work by Saucerman and Bers [8]. The model integrates 
-// cardiac myocyte electrical activity with the calcineurin pathway, which is a key aspect of the development of heart failure. The model spans large number of temporal 
-// scales to reflect how changes in heart rate as observed during exercise or stress contribute to calcineurin pathway activation, which ultimately leads to the expression 
-// of numerous genes that remodel the heart’s structure. It can be used to identify potential therapeutic targets that may be useful for the treatment of heart failure. 
-// Biochemical reactions, ion transport and electrical activity in the cell are modeled with 91 ordinary differential equations (ODEs) that are determined by more than 200 
-// experimentally validated parameters. The model is simulated by solving this group of ODEs for a specified time interval. The process of ODE solving is based on the 
-// causal relationship between values of ODEs at different time steps, thus it is mostly sequential. At every dynamically determined time step, the solver evaluates the 
-// model consisting of a set of 91 ODEs and 480 supporting equations to determine behavior of the system at that particular time instance. If evaluation results are not 
-// within the expected tolerance at a given time step (usually as a result of incorrect determination of the time step), another calculation attempt is made at a modified 
-// (usually reduced) time step. Since the ODEs are stiff (exhibit fast rate of change within short time intervals), they need to be simulated at small time scales with an 
-// adaptive step size solver. 
-
-//	1) The original version of the current solver code was obtained from: Mathematics Source Library (http://mymathlib.webtrellis.net/index.html). The solver has been 
-//      somewhat modified to tailor it to our needs. However, it can be reverted back to original form or modified to suit other simulations.
-// 2) This solver and particular solving algorithm used with it (embedded_fehlberg_7_8) were adapted to work with a set of equations, not just one like in original version.
-//	3) In order for solver to provide deterministic number of steps (needed for particular amount of memore previousely allocated for results), every next step is 
-//      incremented by 1 time unit (h_init).
-//	4) Function assumes that simulation starts at some point of time (whatever time the initial values are provided for) and runs for the number of miliseconds (xmax) 
-//      specified by the uses as a parameter on command line.
-// 5) The appropriate amount of memory is previousely allocated for that range (y).
-//	6) This setup in 3) - 5) allows solver to adjust the step ony from current time instance to current time instance + 0.9. The next time instance is current time instance + 1;
-//	7) The original solver cannot handle cases when equations return NAN and INF values due to discontinuities and /0. That is why equations provided by user need to 
-//      make sure that no NAN and INF are returned.
-// 8) Application reads initial data and parameters from text files: y.txt and params.txt respectively that need to be located in the same folder as source files. 
-//     For simplicity and testing purposes only, when multiple number of simulation instances is specified, application still reads initial data from the same input files. That 
-//     can be modified in this source code.
-
-//========================================================================================================================================================================================================200
-//	IMPLEMENTATION-SPECIFIC DESCRIPTION (CUDA)
-//========================================================================================================================================================================================================200
-
-// This is the CUDA version of Myocyte code.
-
-// The original single-threaded code was written in MATLAB and used MATLAB ode45 ODE solver. In the process of accelerating this code, we arrived with the 
-// intermediate versions that used single-threaded Sundials CVODE solver which evaluated model parallelized with CUDA at each time step. In order to convert entire 
-// solver to CUDA code (to remove some of the operational overheads such as kernel launches and data transfer in CUDA) we used a simpler solver, from Mathematics 
-// Source Library, and tailored it to our needs. The parallelism in the cardiac myocyte model is on a very fine-grained level, close to that of ILP, therefore it is very hard 
-// to exploit as DLP or TLB in CUDA code. We were able to divide the model into 4 individual groups that run in parallel. However, even that is not enough work to 
-// compensate for some of the CUDA thread launch and data transfer overheads which resulted in performance worse than that of single-threaded C code. Speedup in 
-// this code could be achieved only if a customizable accelerator such as FPGA was used for evaluation of the model itself. We also approached the application from 
-// another angle and allowed it to run several concurrent simulations, thus turning it into an embarrassingly parallel problem. This version of the code is also useful for 
-// scientists who want to run the same simulation with different sets of input parameters. Speedup achieved with CUDA code is variable on the other hand. It depends on 
-// the number of concurrent simulations and it saturates around 300 simulations with the speedup of about 10x.
-
-// Speedup numbers reported in the description of this application were obtained on the machine with: Intel Quad Core CPU, 4GB of RAM, Nvidia GTX280 GPU.  
-
-// 1) When running with parallelization inside each simulation instance (value of 3rd command line parameter equal to 0), performance is bad because:
-// a) underutilization of GPU (only 1 out of 32 threads in each block)
-// b) significant CPU-GPU memory copy overhead
-// c) kernel launch overhead (kernel needs to be finished every time model is evaluated as it is the only way to synchronize threads in different blocks)
-// 2) When running with parallelization across simulation instances, code gets continues speedup with the increasing number of simulation insances which saturates
-//     around 240 instances on GTX280 (roughly corresponding to the number of multiprocessorsXprocessors in GTX280), with the speedup of around 10x compared
-//     to serial C version of code. Limited performance is explained mainly by:
-// a) significant CPU-GPU memory copy overhead
-// b) increasingly uncoalesced memory accesses with the increasing number of workloads
-// c) lack of cache compared to CPU, or no use of shared memory to compensate
-// d) frequency of GPU shader being lower than that of CPU core
-// 3) GPU version has an issue with memory allocation that has not been resolved yet. For certain simulation ranges memory allocation fails, or pointers incorrectly overlap 
-//     causeing value trashing.
-
-// The following are the command parameters to the application:
-// 1) Simulation time interval which is the number of miliseconds to simulate. Needs to be integer > 0
-// Example:
-// ./a.out -time 100
-
-//========================================================================================================================================================================================================200
-//	DEFINE / INCLUDE
-//========================================================================================================================================================================================================200
-
-//======================================================================================================================================================150
-//	DEFINE
-//======================================================================================================================================================150
-
-//======================================================================================================================================================150
-//	COMMON
-//======================================================================================================================================================150
-
-#include "./common.h"										// (in directory)
-
-//======================================================================================================================================================150
-//	DEFINE
-//======================================================================================================================================================150
-
-//======================================================================================================================================================150
-//	UTILITIES
-//======================================================================================================================================================150
-
-#include "./util/file/file.h"								// (in directory)
-#include "./util/timer/timer.h"								// (in directory)
-#include "./util/num/num.h"									// (in directory)
-
-//======================================================================================================================================================150
-//	KERNEL
-//======================================================================================================================================================150
-
-#include "./kernel/kernel_gpu_opencl_wrapper.h"				// (in directory)
-
-//======================================================================================================================================================150
-//	LIBRARIES
-//======================================================================================================================================================150
-
-#include <stdio.h>											// (in path known to compiler) needed by printf
-#include <stdlib.h>											// (in path known to compiler) meeded by malloc, free
-
-//======================================================================================================================================================150
-//	HEADER
-//======================================================================================================================================================150
-
-#include "./main.h"											// (in directory)
-
-//======================================================================================================================================================150
-//	END
-//======================================================================================================================================================150
-
-//========================================================================================================================================================================================================200
-//	MAIN FUNCTION
-//========================================================================================================================================================================================================200
-
-int 
-main(	int argc, 
-		char *argv []){
-
-	//======================================================================================================================================================150
-	// 	INPUT ARGUMENTS
-	//======================================================================================================================================================150
-
-	// assing default values
-	int cur_arg;
-	int xmax;
-	int workload = 1;
-
-	// go through arguments
-	if(argc==3){
-		for(cur_arg=1; cur_arg<argc; cur_arg++){
-			// check if -time
-			if(strcmp(argv[cur_arg], "-time")==0){
-				// check if value provided
-				if(argc>=cur_arg+1){
-					// check if value is a number
-					if(isInteger(argv[cur_arg+1])==1){
-						xmax = atoi(argv[cur_arg+1]);
-						if(xmax<0){
-							printf("ERROR: Wrong value to -time argument, cannot be <=0\n");
-							return 0;
-						}
-						cur_arg = cur_arg+1;
-					}
-					// value is not a number
-					else{
-						printf("ERROR: Value to -time argument in not a number\n");
-						return 0;
-					}
-				}
-				// value not provided
-				else{
-					printf("ERROR: Missing value to -time argument\n");
-					return 0;
-				}
-			}
-			// unknown
-			else{
-				printf("ERROR: Unknown argument\n");
-				return 0;
-			}
-		}
-		// Print configuration
-		//printf("Configuration used: arch = %d, cores = %d, time = %d\n", arch_arg, cores_arg, xmax);
-	}
-	else{
-		printf("Provide time argument, example: -time 100");
-		return 0;
-	}
-
-	//======================================================================================================================================================150
-	//	EXECUTION IF THERE IS 1 WORKLOAD, PARALLELIZE INSIDE 1 WORKLOAD
-	//======================================================================================================================================================150
-
-	if(workload == 1){
-
-		//====================================================================================================100
-		//	VARIABLES
-		//====================================================================================================100
-
-		int i,j;
-
-		//====================================================================================================100
-		//	MEMORY CHECK
-		//====================================================================================================100
-
-		long long memory;
-		memory = workload*(xmax+1)*EQUATIONS*4;
-		if(memory>1000000000){
-			printf("ERROR: trying to allocate more than 1.0GB of memory, decrease workload and span parameters or change memory parameter\n");
-			return 0;
-		}
-
-		//====================================================================================================100
-		//	ALLOCATE ARRAYS
-		//====================================================================================================100
-
-		fp*** y;
-		y = (fp ***) malloc(workload* sizeof(fp **));
-		for(i=0; i<workload; i++){
-			y[i] = (fp**)malloc((1+xmax)*sizeof(fp*));
-			for(j=0; j<(1+xmax); j++){
-				y[i][j]= (fp *) malloc(EQUATIONS* sizeof(fp));
-			}
-		}
-
-		fp** x;
-		x = (fp **) malloc(workload * sizeof(fp *));
-		for (i= 0; i<workload; i++){
-			x[i]= (fp *)malloc((1+xmax) *sizeof(fp));
-		}
-
-		fp** params;
-		params = (fp **) malloc(workload * sizeof(fp *));
-		for (i= 0; i<workload; i++){
-			params[i]= (fp *)malloc(PARAMETERS * sizeof(fp));
-		}
-
-		fp* com;
-		com = (fp*)malloc(3 * sizeof(fp));
-
-		//====================================================================================================100
-		//	INITIAL VALUES
-		//====================================================================================================100
-
-		// y
-		for(i=0; i<workload; i++){
-			read_file( "../../data/myocyte/y.txt",
-						y[i][0],
-						EQUATIONS,
-						1,
-						0);
-		}
-
-		// params
-		for(i=0; i<workload; i++){
-			read_file("../../data/myocyte/params.txt",
-						params[i],
-						PARAMETERS,
-						1,
-						0);
-		}
-
-		//====================================================================================================100
-		//	COMPUTATION
-		//====================================================================================================100
-
-		kernel_gpu_opencl_wrapper(	xmax,					// span
-									workload,				// # of workloads
-
-									y,
-									x,
-									params,
-									com);
-
-
-	  FILE * pFile;
-	  pFile = fopen ("output.txt","w");
-	  if (pFile==NULL)
-	    {
-	  fputs ("fopen example",pFile);
-	  return -1;
-	}
-	  // print results
-	  int k;
-	  for(i=0; i<workload; i++){
-	  fprintf(pFile, "WORKLOAD %d:\n", i);
-	  for(j=0; j<(xmax+1); j++){
-	  fprintf(pFile, "\tTIME %d:\n", j);
-	  for(k=0; k<EQUATIONS; k++){
-	  fprintf(pFile, "\t\ty[%d][%d][%d]=%10.7e\n", i, j, k, y[i][j][k]);
-	}
-	}
-	}
-
-	  fclose (pFile);
-	  
-
-
-		//====================================================================================================100
-		//	FREE SYSTEM MEMORY
-		//====================================================================================================100
-
-		// y values
-		for (i= 0; i< workload; i++){
-			for (j= 0; j< (1+xmax); j++){
-				free(y[i][j]);
-			}
-			free(y[i]);
-		}
-		free(y);
-
-		// x values
-		for (i= 0; i< workload; i++){
-			free(x[i]);
-		}
-		free(x);
-
-		// parameters
-		for (i= 0; i< workload; i++){
-			free(params[i]);
-		}
-		free(params);
-
-		// com
-		free(com);
-
-		//====================================================================================================100
-		//	END
-		//====================================================================================================100
-
-	}
-
-	//======================================================================================================================================================150
-	//	RETURN
-	//======================================================================================================================================================150
-
-	return 0;
-
-	//======================================================================================================================================================150
-	//	END
-	//======================================================================================================================================================150
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 19
opencl/myocyte/main.h

@@ -1,19 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	PROTOTYPES
-//========================================================================================================================================================================================================200
-
-int 
-main(	int argc, 
-		char *argv []);
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 1
opencl/myocyte/run

@@ -1 +0,0 @@
-./myocyte.out -time 100

+ 0 - 145
opencl/myocyte/util/file/file.c

@@ -1,145 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-// #include <stdlib.h>
-// #include <string.h>
-#include <stdio.h>
-// #include <math.h>
-// #include <time.h>
-// #include <sys/types.h>
-// #include <dirent.h>
-// #include <errno.h>
-
-#include "file.h"
-
-//========================================================================================================================================================================================================200
-//	WRITE FUNCTION
-//========================================================================================================================================================================================================200
-
-void 
-write_file(	char* filename,
-			fp* input, 
-			int data_rows, 
-			int data_cols, 
-			int major,
-			int data_range){
-
-	//=====================================================================
-	//	VARIABLES
-	//=====================================================================
-
-	FILE* fid;
-	int i, j;
-
-	//=====================================================================
-	//	CREATE/OPEN FILE FOR WRITING
-	//=====================================================================
-
-	fid = fopen(filename, "w");
-	if( fid == NULL ){
-		printf( "The file was not created/opened for writing\n" );
-		fflush(0);
-		return;
-	}
-
-	//=====================================================================
-	//	WRITE VALUES TO THE FILE
-	//=====================================================================
-
-	// if matrix is saved row major in memory (C)
-	if(major==0){
-		for(i=0; i<data_rows; i++){
-			for(j=0; j<data_cols; j++){
-				fprintf(fid, "%f ", (fp)input[i*data_cols+j]);
-			}
-			fprintf(fid, "\n");
-		}
-	}
-	// if matrix is saved column major in memory (MATLAB)
-	else{
-		for(i=0; i<data_rows; i++){
-			for(j=0; j<data_cols; j++){
-				fprintf(fid, "%f ", (fp)input[j*data_rows+i]);
-			}
-			fprintf(fid, "\n");
-		}
-	}
-
-	//=====================================================================
-	//	CLOSE FILE
-	//=====================================================================
-
-	fclose(fid);
-
-}
-
-//========================================================================================================================================================================================================200
-//	READ FUNCTION
-//========================================================================================================================================================================================================200
-
-void read_file(	char* filename,
-				fp* input,
-				int data_rows, 
-				int data_cols,
-				int major){
-
-	//=====================================================================
-	//	VARIABLES
-	//=====================================================================
-
-	FILE* fid;
-	int i, j;
-	fp temp;
-
-	//=====================================================================
-	//	OPEN FILE FOR READING
-	//=====================================================================
-
-	fid = fopen(filename, "r");
-	if( fid == NULL ){
-		printf( "The file was not opened for reading\n" );
-		fflush(0);
-		return;
-	}
-
-	//=====================================================================
-	//	READ VALUES FROM THE FILE
-	//=====================================================================
-
-	if(major==0){																// if matrix is saved row major in memory (C)
-		for(i=0; i<data_rows; i++){
-			for(j=0; j<data_cols; j++){
-				fscanf(fid, "%f", &temp);
-				input[i*data_cols+j] = (fp)temp;
-			}
-		}
-	}
-	else{																				// if matrix is saved column major in memory (MATLAB)
-		for(i=0; i<data_rows; i++){
-			for(j=0; j<data_cols; j++){
-				fscanf(fid, "%f", &temp);
-				input[j*data_rows+i] = (fp)temp;
-			}
-		}
-	}
-
-	//=====================================================================
-	//	CLOSE FILE
-	//=====================================================================
-
-	fclose(fid);
-
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 40
opencl/myocyte/util/file/file.h

@@ -1,40 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-#define fp float
-
-//========================================================================================================================================================================================================200
-//	WRITE FUNCTION
-//========================================================================================================================================================================================================200
-
-void 
-write_file(	char* filename,
-			fp* input, 
-			int data_rows, 
-			int data_cols, 
-			int major,
-			int data_range);
-
-//========================================================================================================================================================================================================200
-//	READ FUNCTION
-//========================================================================================================================================================================================================200
-
-void 
-read_file(	char* filename,
-			fp* input,
-			int data_rows, 
-			int data_cols,
-			int major);
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 50
opencl/myocyte/util/num/num.c

@@ -1,50 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//===============================================================================================================================================================================================================200
-//	DESCRIPTION
-//===============================================================================================================================================================================================================200
-
-// Returns:	0 if string does not represent integer
-//			1 if string represents integer
-
-//===============================================================================================================================================================================================================200
-//	FUNCTION
-//===============================================================================================================================================================================================================200
-
-int 
-isInteger(char *str){
-
-	//====================================================================================================100
-	//	make sure it's not empty
-	//====================================================================================================100
-
-	if (*str == '\0'){
-		return 0;
-	}
-
-	//====================================================================================================100
-	//	if any digit is not a number, return false
-	//====================================================================================================100
-
-	for(; *str != '\0'; str++){
-		if (*str < 48 || *str > 57){	// digit characters (need to include . if checking for float)
-			return 0;
-		}
-	}
-
-	//====================================================================================================100
-	//	it got past all my checks so I think it's a number
-	//====================================================================================================100
-
-	return 1;
-}
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 18
opencl/myocyte/util/num/num.h

@@ -1,18 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//===============================================================================================================================================================================================================200
-//	PROTOTYPES
-//===============================================================================================================================================================================================================200
-
-int 
-isInteger(char *str);
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 139
opencl/myocyte/util/opencl/opencl.c

@@ -1,139 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//===============================================================================================================================================================================================================200
-//	INCLUDE/DEFINE
-//===============================================================================================================================================================================================================200
-
-#include "opencl.h"					// (in directory)	function headers
-#include <CL/cl.h>
-
-//===============================================================================================================================================================================================================200
-//	LOAD KERNEL SOURCE CODE FUNCTION
-//===============================================================================================================================================================================================================200
-
-char *
-load_kernel_source(const char *filename)
-{
-	// Open the source file
-	FILE *file = fopen(filename, "r");
-	if (file == NULL){
-		fatal("Error opening kernel source file\n");
-	}
-
-	// Determine the size of the file
-	if (fseek(file, 0, SEEK_END)){
-		fatal("Error reading kernel source file\n");
-	}
-	size_t size = ftell(file);
-
-	// Allocate space for the source code (plus one for null-terminator)
-	char *source = (char *) malloc(size + 1);
-
-	// Read the source code into the string
-	fseek(file, 0, SEEK_SET);
-	// printf("Number of elements: %lu\nSize = %lu", fread(source, 1, size, file), size);
-	// exit(1);
-	if (fread(source, 1, size, file) != size){
-		fatal("Error reading kernel source file\n");
-	}
-
-	// Null-terminate the string
-	source[size] = '\0';
-
-	// Return the pointer to the string
-	return source;
-}
-
-//===============================================================================================================================================================================================================200
-//	PRINT ERROR FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-fatal(const char *s)
-{
-	fprintf(stderr, "Error: %s\n", s);
-	exit(1);
-}
-
-//===============================================================================================================================================================================================================200
-//	PRINT OPENCL ERROR FUNCTION
-//===============================================================================================================================================================================================================200
-
-void 
-fatal_CL(cl_int error, int line_no) {
-
-	printf("Error at line %d: ", line_no);
-
-	switch(error) {
-
-		case CL_SUCCESS: 									printf("CL_SUCCESS\n"); break;
-		case CL_DEVICE_NOT_FOUND: 							printf("CL_DEVICE_NOT_FOUND\n"); break;
-		case CL_DEVICE_NOT_AVAILABLE: 						printf("CL_DEVICE_NOT_AVAILABLE\n"); break;
-		case CL_COMPILER_NOT_AVAILABLE: 					printf("CL_COMPILER_NOT_AVAILABLE\n"); break;
-		case CL_MEM_OBJECT_ALLOCATION_FAILURE: 				printf("CL_MEM_OBJECT_ALLOCATION_FAILURE\n"); break;
-		case CL_OUT_OF_RESOURCES: 							printf("CL_OUT_OF_RESOURCES\n"); break;
-		case CL_OUT_OF_HOST_MEMORY: 						printf("CL_OUT_OF_HOST_MEMORY\n"); break;
-		case CL_PROFILING_INFO_NOT_AVAILABLE: 				printf("CL_PROFILING_INFO_NOT_AVAILABLE\n"); break;
-		case CL_MEM_COPY_OVERLAP: 							printf("CL_MEM_COPY_OVERLAP\n"); break;
-		case CL_IMAGE_FORMAT_MISMATCH: 						printf("CL_IMAGE_FORMAT_MISMATCH\n"); break;
-		case CL_IMAGE_FORMAT_NOT_SUPPORTED: 				printf("CL_IMAGE_FORMAT_NOT_SUPPORTED\n"); break;
-		case CL_BUILD_PROGRAM_FAILURE: 						printf("CL_BUILD_PROGRAM_FAILURE\n"); break;
-		case CL_MAP_FAILURE: 								printf("CL_MAP_FAILURE\n"); break;
-		case CL_INVALID_VALUE: 								printf("CL_INVALID_VALUE\n"); break;
-		case CL_INVALID_DEVICE_TYPE: 						printf("CL_INVALID_DEVICE_TYPE\n"); break;
-		case CL_INVALID_PLATFORM: 							printf("CL_INVALID_PLATFORM\n"); break;
-		case CL_INVALID_DEVICE: 							printf("CL_INVALID_DEVICE\n"); break;
-		case CL_INVALID_CONTEXT: 							printf("CL_INVALID_CONTEXT\n"); break;
-		case CL_INVALID_QUEUE_PROPERTIES: 					printf("CL_INVALID_QUEUE_PROPERTIES\n"); break;
-		case CL_INVALID_COMMAND_QUEUE: 						printf("CL_INVALID_COMMAND_QUEUE\n"); break;
-		case CL_INVALID_HOST_PTR: 							printf("CL_INVALID_HOST_PTR\n"); break;
-		case CL_INVALID_MEM_OBJECT: 						printf("CL_INVALID_MEM_OBJECT\n"); break;
-		case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: 			printf("CL_INVALID_IMAGE_FORMAT_DESCRIPTOR\n"); break;
-		case CL_INVALID_IMAGE_SIZE: 						printf("CL_INVALID_IMAGE_SIZE\n"); break;
-		case CL_INVALID_SAMPLER: 							printf("CL_INVALID_SAMPLER\n"); break;
-		case CL_INVALID_BINARY: 							printf("CL_INVALID_BINARY\n"); break;
-		case CL_INVALID_BUILD_OPTIONS: 						printf("CL_INVALID_BUILD_OPTIONS\n"); break;
-		case CL_INVALID_PROGRAM: 							printf("CL_INVALID_PROGRAM\n"); break;
-		case CL_INVALID_PROGRAM_EXECUTABLE: 				printf("CL_INVALID_PROGRAM_EXECUTABLE\n"); break;
-		case CL_INVALID_KERNEL_NAME: 						printf("CL_INVALID_KERNEL_NAME\n"); break;
-		case CL_INVALID_KERNEL_DEFINITION: 					printf("CL_INVALID_KERNEL_DEFINITION\n"); break;
-		case CL_INVALID_KERNEL: 							printf("CL_INVALID_KERNEL\n"); break;
-		case CL_INVALID_ARG_INDEX: 							printf("CL_INVALID_ARG_INDEX\n"); break;
-		case CL_INVALID_ARG_VALUE: 							printf("CL_INVALID_ARG_VALUE\n"); break;
-		case CL_INVALID_ARG_SIZE: 							printf("CL_INVALID_ARG_SIZE\n"); break;
-		case CL_INVALID_KERNEL_ARGS: 						printf("CL_INVALID_KERNEL_ARGS\n"); break;
-		case CL_INVALID_WORK_DIMENSION: 					printf("CL_INVALID_WORK_DIMENSION\n"); break;
-		case CL_INVALID_WORK_GROUP_SIZE: 					printf("CL_INVALID_WORK_GROUP_SIZE\n"); break;
-		case CL_INVALID_WORK_ITEM_SIZE: 					printf("CL_INVALID_WORK_ITEM_SIZE\n"); break;
-		case CL_INVALID_GLOBAL_OFFSET: 						printf("CL_INVALID_GLOBAL_OFFSET\n"); break;
-		case CL_INVALID_EVENT_WAIT_LIST: 					printf("CL_INVALID_EVENT_WAIT_LIST\n"); break;
-		case CL_INVALID_EVENT: 								printf("CL_INVALID_EVENT\n"); break;
-		case CL_INVALID_OPERATION: 							printf("CL_INVALID_OPERATION\n"); break;
-		case CL_INVALID_GL_OBJECT: 							printf("CL_INVALID_GL_OBJECT\n"); break;
-		case CL_INVALID_BUFFER_SIZE: 						printf("CL_INVALID_BUFFER_SIZE\n"); break;
-		case CL_INVALID_MIP_LEVEL: 							printf("CL_INVALID_MIP_LEVEL\n"); break;
-		case CL_INVALID_GLOBAL_WORK_SIZE: 					printf("CL_INVALID_GLOBAL_WORK_SIZE\n"); break;
-
-		#ifdef CL_VERSION_1_1
-		case CL_MISALIGNED_SUB_BUFFER_OFFSET: 				printf("CL_MISALIGNED_SUB_BUFFER_OFFSET\n"); break;
-		case CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST:	printf("CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST\n"); break;
-		/* case CL_INVALID_PROPERTY: 							printf("CL_INVALID_PROPERTY\n"); break; */
-		#endif
-
-		default:											printf("Invalid OpenCL error code\n");
-
-	}
-
-	exit(error);
-
-}
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 40
opencl/myocyte/util/opencl/opencl.h

@@ -1,40 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//===============================================================================================================================================================================================================200
-//	INCLUDE/DEFINE
-//===============================================================================================================================================================================================================200
-
-#include <stdio.h>					// (in path known to compiler)		needed by printf
-
-#include <CL/cl.h>					// (in path specified to compiler)	needed by OpenCL types
-
-//===============================================================================================================================================================================================================200
-//	LOAD KERNEL SOURCE CODE FUNCTION HEADER
-//===============================================================================================================================================================================================================200
-
-char *
-load_kernel_source(const char *filename);
-
-//===============================================================================================================================================================================================================200
-//	PRINT ERROR FUNCTION HEADER
-//===============================================================================================================================================================================================================200
-
-void 
-fatal(const char *s);
-
-//===============================================================================================================================================================================================================200
-//	PRINT OPENCL ERROR FUNCTION HEADER
-//===============================================================================================================================================================================================================200
-
-void 
-fatal_CL(cl_int error, int line_no);
-
-//===============================================================================================================================================================================================================200
-//	END
-//===============================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 34
opencl/myocyte/util/timer/timer.c

@@ -1,34 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	DEFINE/INCLUDE
-//========================================================================================================================================================================================================200
-
-#include <stdlib.h>
-#include <sys/time.h>
-
-#include "timer.h"
-
-//========================================================================================================================================================================================================200
-//	GET TIME
-//========================================================================================================================================================================================================200
-
- // Returns the current system time in microseconds
-long long 
-get_time() {
-
-	struct timeval tv;
-	gettimeofday(&tv, NULL);
-
-	return (tv.tv_sec * 1000000) + tv.tv_usec;
-}
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif

+ 0 - 19
opencl/myocyte/util/timer/timer.h

@@ -1,19 +0,0 @@
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-//========================================================================================================================================================================================================200
-//	GET TIME
-//========================================================================================================================================================================================================200
-
- // Returns the current system time in microseconds
-long long 
-get_time();
-
-//========================================================================================================================================================================================================200
-//	END
-//========================================================================================================================================================================================================200
-
-// #ifdef __cplusplus
-// }
-// #endif