Index: proiecte/NBody/NBody 2.0/ReleaseResources.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/ReleaseResources.cpp	(revision 35)
+++ proiecte/NBody/NBody 2.0/ReleaseResources.cpp	(revision 35)
@@ -0,0 +1,135 @@
+#include "NBody.hpp"
+
+/////////////////////////////////// NBody::cleanup Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Releases OpenCL resources (Context, Memory etc.)
+//
+/////////////////////////////////// NBody::cleanup Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+int NBody::cleanup()
+{
+	//================================================
+	// Resources common to all integrators:
+
+    /* Releases OpenCL resources (Context, Memory etc.) */
+    cl_int status;
+
+    status = clReleaseKernel(kernel);
+	if (status != CL_SUCCESS){
+		std::cout << "clReleaseKernel failed." << std::endl;
+		return 1;
+	}
+
+	status = clReleaseProgram(program);
+	if (status != CL_SUCCESS){
+		std::cout << "clReleaseProgram failed." << std::endl;
+		return 1;
+	}
+
+    status = clReleaseMemObject(updatedPos);
+	if (status != CL_SUCCESS){
+		std::cout << "clReleaseMemObject failed." << std::endl;
+		return 1;
+	}
+
+    status = clReleaseMemObject(updatedVel);
+	if (status != CL_SUCCESS){
+		std::cout << "clReleaseMemObject failed." << std::endl;
+		return 1;
+	}
+
+    status = clReleaseCommandQueue(commandQueue);
+	if (status != CL_SUCCESS){
+		std::cout << "clReleaseMemObject failed." << std::endl;
+		return 1;
+	}
+ 
+    status = clReleaseContext(context);
+	if (status != CL_SUCCESS){
+		std::cout << "clReleaseMemObject failed." << std::endl;
+		return 1;
+	}
+
+	//================================================
+	// Resources specific only for Leapfrog integrator:
+
+	status = clReleaseMemObject(updatedAcc);
+	if (status != CL_SUCCESS){
+		std::cout << "clReleaseMemObject failed." << std::endl;
+		return 1;
+	}
+
+    return 0;
+}
+
+/////////////////////////////////// NBody::~NBody() \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Override the constructor of the NBody class, releasing
+// unreleased resources
+//
+/////////////////////////////////// NBody::~NBody() \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+NBody::~NBody()
+{
+	//================================================
+	// Resources common to all integrators:
+
+    /* release program resources */
+    if(initPos)
+    {
+        free(initPos);
+        initPos = NULL;
+    }
+
+    if(initVel)
+    {
+        free(initVel);
+        initVel = NULL;
+    }
+
+    if(pos)
+    {
+        #if defined (_WIN32)
+            _aligned_free(pos);
+        #else
+            free(pos);
+        #endif
+        pos = NULL;
+    }
+    if(vel)
+    {
+        #if defined (_WIN32)
+            _aligned_free(vel);
+        #else
+            free(vel);
+        #endif
+        vel = NULL;
+    }
+
+    if(devices)
+    {
+        free(devices);
+        devices = NULL;
+    }
+
+    if(maxWorkItemSizes)
+    {
+        free(maxWorkItemSizes);
+        maxWorkItemSizes = NULL;
+    }
+
+	//================================================
+	// Resources specific only for Leapfrog integrator:
+	
+	if(acc)
+    {
+        #if defined (_WIN32)
+            _aligned_free(acc);
+        #else
+            free(acc);
+        #endif
+        acc = NULL;
+    }
+
+}
+
Index: proiecte/NBody/NBody 2.0/RunKernels.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/RunKernels.cpp	(revision 35)
+++ proiecte/NBody/NBody 2.0/RunKernels.cpp	(revision 35)
@@ -0,0 +1,237 @@
+#include "NBody.hpp"
+
+extern int numBodies;
+
+/////////////////////////////////// NBody::runCLKernels Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Enqueue calls to the kernels on to the command queue, 
+// wait till end of kernel execution.
+//
+/////////////////////////////////// NBody::runCLKernels Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+int NBody::runCLKernels()
+{
+    cl_int   status;
+    cl_event events[1];
+
+    /* 
+     * Enqueue a kernel run call.
+     */
+    size_t globalThreads[] = {numBodies};
+    size_t localThreads[] = {GROUP_SIZE};
+
+	if(localThreads[0] > maxWorkItemSizes[0] || localThreads[0] > maxWorkGroupSize)
+	{
+		std::cout<<"Unsupported: Device does not support requested number of work items.";
+				 
+		return 1;
+	}
+
+    status = clEnqueueNDRangeKernel(
+                 commandQueue,
+                 kernel,
+                 1,
+                 NULL,
+                 globalThreads,
+                 localThreads,
+                 0,
+                 NULL,
+                 NULL);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clEnqueueNDRangeKernel failed." << std::endl;
+        return 1;
+    }
+
+	status = clFinish(commandQueue);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clFinish failed." << std::endl;
+        return 1;
+    }
+
+    /* Enqueue readBuffer*/
+    status = clEnqueueReadBuffer(
+                commandQueue,
+                updatedPos,
+                CL_TRUE,
+                0,
+                numBodies* sizeof(cl_float4),
+                pos,
+                0,
+                NULL,
+                &events[0]);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clEnqueueReadBuffer failed." << std::endl;
+        return 1;
+    }
+    
+    /* Wait for the read buffer to finish execution */
+    status = clWaitForEvents(1, &events[0]);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clWaitForEvents failed." << std::endl;
+        return 1;
+    }
+    
+    clReleaseEvent(events[0]);
+
+    return 0;
+}
+
+
+int NBody::runCLKernelLeapfrog()
+{
+    //cl_int   status;
+    //cl_event events[1];
+
+	if (initialAccComputation){
+		enqueueKernel();
+		initialAccComputation = 0;
+	}
+
+	float min = collTime[0];
+
+	for (int i = 1; i < numParticles; i++){
+		if (min > collTime[i])
+			min = collTime[i];
+	}
+	
+	cl_float dt = (float)delT ;//* min;
+
+	// Compute the partial v_(n+1) and x_(n+1):
+	for (int i = 0; i < numParticles; i++){
+
+		int idx = i*4;
+
+        for (int k = 0; k < 3; k++)
+			vel[idx+k] += acc[idx+k]*dt/2;
+
+	    for (int k = 0; k < 3; k++)
+	    	pos[idx+k] += vel[idx+k] * dt;
+	}
+
+
+	enqueueKernel();
+ 
+	min = collTime[0];
+
+	for (int i = 1; i < numParticles; i++){
+		if (min > collTime[i])
+			min = collTime[i];
+	}
+	
+	dt = (float)delT ;//* min;
+
+	// Now we compute the rest of the v_(n+1):
+	for (int i = 0; i < numParticles; i++){
+		
+		int idx = i*4;
+
+		for (int k = 0; k < 3; k++)
+            vel[idx+k] += acc[idx+k] * dt/2;
+   		}
+
+    return 0;
+}
+
+int NBody::enqueueKernel()
+{
+	cl_int   status;
+    cl_event events[1];
+
+	/* 
+     * Enqueue a kernel run call.
+     */
+    size_t globalThreads[] = {numBodies};
+    size_t localThreads[] = {GROUP_SIZE};
+
+	if(localThreads[0] > maxWorkItemSizes[0] || localThreads[0] > maxWorkGroupSize)
+	{
+		std::cout << "Unsupported: Device does not support requested number of work items." << std::endl;
+				 
+		return 1;
+	}
+
+
+	status = clEnqueueNDRangeKernel(
+                 commandQueue,
+                 kernel,
+                 1,
+                 NULL,
+                 globalThreads,
+                 localThreads,
+                 0,
+                 NULL,
+                 NULL);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clEnqueueNDRangeKernel failed." << std::endl;
+        return 1;
+    }
+
+	status = clFinish(commandQueue);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clFinish failed." << std::endl;
+        return 1;
+    }
+
+    /* Enqueue readBuffer*/
+    status = clEnqueueReadBuffer(
+                commandQueue,
+                updatedAcc,
+                CL_TRUE,
+                0,
+                numBodies* sizeof(cl_float4),
+                acc,
+                0,
+                NULL,
+                &events[0]);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clEnqueueReadBuffer failed." << std::endl;
+        return 1;
+    }
+    
+    /* Wait for the read buffer to finish execution */
+    status = clWaitForEvents(1, &events[0]);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clWaitForEvents failed." << std::endl;
+        return 1;
+    }
+
+	/* Enqueue readBuffer*/
+    status = clEnqueueReadBuffer(
+                commandQueue,
+                updatedCollTime,
+                CL_TRUE,
+                0,
+                numBodies* sizeof(cl_float),
+                collTime,
+                0,
+                NULL,
+                &events[0]);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clEnqueueReadBuffer failed." << std::endl;
+        return 1;
+    }
+    
+    /* Wait for the read buffer to finish execution */
+    status = clWaitForEvents(1, &events[0]);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clWaitForEvents failed." << std::endl;
+        return 1;
+    }
+    
+    clReleaseEvent(events[0]);
+}
Index: proiecte/NBody/NBody 2.0/SetupKernelsCL.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/SetupKernelsCL.cpp	(revision 35)
+++ proiecte/NBody/NBody 2.0/SetupKernelsCL.cpp	(revision 35)
@@ -0,0 +1,190 @@
+#include "NBody.hpp"
+
+extern int numBodies;	
+
+/////////////////////////////////// NBody::setupCLKernels Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// This function only sets the Kernel arguments
+//
+/////////////////////////////////// NBody::setupCLKernels Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+int NBody::setupCLKernels()
+{
+    cl_int   status;
+
+	/* get a kernel object handle for a kernel with the given name */
+    kernel = clCreateKernel(
+                 program,
+                 kernelFunctionName,
+                 &status);
+	
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clCreateKernel failed." << std::endl;
+        return 1;
+    }
+
+	//================================================
+	// Arguments specific to all kernels:
+
+    /*** Set appropriate arguments to the kernel ***/
+
+    /* Particle positions */
+    status = clSetKernelArg(
+                 kernel,
+                 0,					// Argument one;
+                 sizeof(cl_mem),
+                 (void *)&updatedPos);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (updatedPos)" << std::endl;
+        return 1;
+    }
+
+    /* Particle velocity */
+    status = clSetKernelArg(
+                 kernel,
+                 1,					// Argument two;
+                 sizeof(cl_mem),
+                 (void *)&updatedVel);
+	
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (updatedVel)" << std::endl;
+        return 1;
+    }
+ 
+    /* numBodies */
+    status = clSetKernelArg(
+                 kernel,
+                 2,					// Argument three;
+                 sizeof(cl_int),
+                 (void *)&numBodies);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (numBodies)" << std::endl;
+        return 1;
+    }
+
+    /* time step */
+    status = clSetKernelArg(
+                 kernel,
+                 3,					// Argument four;
+                 sizeof(cl_float),
+                 (void *)&delT);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (delT)" << std::endl;
+        return 1;
+    }
+
+    /* upward Pseudoprobability */
+    status = clSetKernelArg(
+                 kernel,
+                 4,					// Argument five;
+                 sizeof(cl_float),
+                 (void *)&espSqr);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (espSqr)" << std::endl;
+        return 1;
+    }
+
+    /* local memory */
+    status = clSetKernelArg(
+                 kernel,
+                 5,					// Argument six;
+                 GROUP_SIZE * 4 * sizeof(float),
+                 NULL);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (localPos)" << std::endl;
+        return 1;
+    }
+
+	//================================================
+	// Arguments specific to Leapfrog kernel:
+
+	if (integrator == LEAPFROG){
+
+		/* local memory */
+		status = clSetKernelArg(
+					 kernel,
+					 6,					// Argument seven;
+					 GROUP_SIZE * 4 * sizeof(float),
+					 NULL);
+
+		if(status != CL_SUCCESS)
+		{
+			std::cout << "clSetKernelArg failed. (localVel)" << std::endl;
+			return 1;
+		}
+
+		/* Particle acceleration */
+		status = clSetKernelArg(
+					 kernel,
+					 7,					// Argument eight;
+					 sizeof(cl_mem),
+					 (void *)&updatedAcc);
+
+		if(status != CL_SUCCESS)
+		{
+			std::cout << "clSetKernelArg failed. (updatedAcc)" << std::endl;
+			return 1;
+		}
+
+		/* If it is the first run and we do not have the acc computed yet */
+		status = clSetKernelArg(
+                 kernel,
+                 8,					// Argument nine;
+                 sizeof(cl_int),
+                 (void *)&initialAccComputation);
+
+		if(status != CL_SUCCESS)
+		{
+			std::cout << "clSetKernelArg failed. (initialAccComputation)" << std::endl;
+			return 1;
+		}
+
+		/* If it is the first run and we do not have the acc computed yet */
+		status = clSetKernelArg(
+                 kernel,
+                 9,					// Argument 10;
+                 sizeof(cl_mem),
+                 (void *)&updatedCollTime);
+
+		if(status != CL_SUCCESS)
+		{
+			std::cout << "clSetKernelArg failed. (updatedCollTime)" << std::endl;
+			return 1;
+		}
+	}
+
+	//================================================
+	// Try to see if there is enough local memory
+	// on the device for the above parameter
+	// declared to be __local:
+    status = clGetKernelWorkGroupInfo(kernel,
+                                      devices[0],
+                                      CL_KERNEL_LOCAL_MEM_SIZE,
+                                      sizeof(cl_ulong),
+                                      &usedLocalMemory,
+                                      NULL);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clGetKernelWorkGroupInfo CL_KERNEL_LOCAL_MEM_SIZE failed." << std::endl;
+        return 1;
+    }
+
+    if(usedLocalMemory > totalLocalMemory)
+    {
+        std::cout << "Unsupported: Insufficient local memory on device." << std::endl;
+        return 1;
+    }
+
+    return 0;
+}
Index: proiecte/NBody/NBody 2.0/SetupNBody.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/SetupNBody.cpp	(revision 35)
+++ proiecte/NBody/NBody 2.0/SetupNBody.cpp	(revision 35)
@@ -0,0 +1,186 @@
+#include "NBody.hpp"
+
+int numBodies;			// No. of particles. This will show the same number as numParticles
+						// class member variable of NBody, but it is used outside the class,
+						// whitout being necessary to have a pointer to the class;
+extern FILE *inputDataFile;
+extern void* me;
+
+/////////////////////////////////// NBody::setupNBody Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Initialize the particles in the system : 
+//	- their initial positions;
+//	- their initial velocities.
+// The data is read from a file or randomly generated.
+//
+/////////////////////////////////// NBody::setupNBody Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+int NBody::setupNBody()
+{
+	//--------------------------------------------
+    // Make sure numParticles is multiple of group size
+    numParticles = (numParticles < GROUP_SIZE) ? GROUP_SIZE : numParticles;
+    numParticles = (numParticles / GROUP_SIZE) * GROUP_SIZE;
+
+    numBodies = numParticles;
+	
+	//--------------------------------------------
+	// First we will use initPos and initVel vectors to generate the
+	// input data. They will be used in this function to
+	// initialize the other vectors: the pos and vel vectors.
+	
+    initPos = (cl_float*)malloc(numBodies * sizeof(cl_float4));
+    if(initPos == NULL)	
+	{ 
+		std::cout << "Failed to allocate host memory. (initPos)" << std::endl;
+		return 1;
+	}
+
+    initVel = (cl_float*)malloc(numBodies * sizeof(cl_float4));
+	if(initVel == NULL)	
+	{ 
+		std::cout << "Failed to allocate host memory. (initVel)" << std::endl;
+		return 1;
+	}
+
+	//--------------------------------------------
+	// Initialization of inputs (positions and velocities). As we 
+	// can see, each particle will occupy 4 elements in the 
+	// pos and vel vectors. This is because the position and 
+	// velocity is represented by their 3 components x, y, z.
+	// Because we work with OpenCL we use cl_float4 vectors, so
+	// vectors with four elements. We put the mass of the particle
+	// on the 4th position occupied by a particle in the pos vector.
+
+	// If the particles data is read from a file:
+	if (readInputData){	
+		
+		if (inputDataFile == NULL){
+			std::cout << "Error: inputData file not opened." << std::endl;
+			((NBody*)me)->cleanup();
+			exit(1);
+		}
+
+		for (int i = 0; i < numBodies ; i++){
+			int idx = i*4;
+
+			fscanf(inputDataFile, "%f", &initPos[idx+3]);		// Mass of particle i;
+			
+			for (int k = 0; k < 3; k++)
+				fscanf(inputDataFile, "%f", &initPos[idx+k]);	// Position of particle i;
+				             
+			for (int k = 0; k < 3; k++)
+				fscanf(inputDataFile, "%f", &initVel[idx+k]);	// Velocity of particle i;
+
+			initVel[idx+3] = 0.0f; // Unused;
+
+		}
+  
+	}else{
+	// If the particles data is generated randomly:
+		for(int i = 0; i < numBodies; ++i)
+		{
+			int index = 4 * i;
+
+			// First 3 values are position in x,y and z direction
+			for(int j = 0; j < 3; ++j)
+			{
+				initPos[index + j] = random(3, 50);
+			}
+
+			// Mass value
+			initPos[index + 3] = random(1, 1000);
+			//initPos[index + 3] = random(0.1, 1.0);
+			//initPos[index + 3] = 0.04;
+
+			// First 3 values are velocity in x,y and z direction
+			for(int j = 0; j < 3; ++j)
+			{
+				initVel[index + j] = 0.0f;
+			}
+
+			// unused
+			initVel[3] = 0.0f;
+		}
+	}
+
+	//================================================
+	// Resources common to all integrators:
+	
+	//--------------------------------------------
+	// Allocate memory for pos and vel vectors.
+
+	#if defined (_WIN32)
+		pos = (cl_float*)_aligned_malloc(numBodies * sizeof(cl_float4), 16);
+	#else
+		pos = (cl_float*)memalign(16, numBodies * sizeof(cl_float4));
+	#endif
+
+	if(pos == NULL)	
+	{ 
+		std::cout << "Failed to allocate host memory. (pos)" << std::endl;
+		return 1;
+	}
+
+	#if defined (_WIN32)
+		vel = (cl_float*)_aligned_malloc(numBodies * sizeof(cl_float4), 16);
+	#else
+		vel = (cl_float*)memalign(16, numBodies * sizeof(cl_float4));
+	#endif
+
+	if(vel == NULL)	
+	{ 
+		std::cout << "Failed to allocate host memory. (vel)" << std::endl;
+		return 1;
+	}
+
+	//--------------------------------------------
+	// Copy the auxiliary vectors into the pos and vel ones:
+	memcpy(pos, initPos, 4 * numBodies * sizeof(cl_float));
+	memcpy(vel, initVel, 4 * numBodies * sizeof(cl_float));
+
+	//================================================
+	// Resources specific only for Leapfrog integrator:
+
+	if (integrator == LEAPFROG){
+		#if defined (_WIN32)
+			acc = (cl_float*)_aligned_malloc(numBodies * sizeof(cl_float4), 16);
+		#else
+			acc = (cl_float*)memalign(16, numBodies * sizeof(cl_float4));
+		#endif
+
+		if(acc == NULL)	
+		{ 
+			std::cout << "Failed to allocate host memory. (acc)" << std::endl;
+			return 1;
+		}
+
+		#if defined (_WIN32)
+			collTime = (cl_float*)_aligned_malloc(numBodies * sizeof(cl_float), 16);
+		#else
+			collTime = (cl_float*)memalign(16, numBodies * sizeof(cl_float));
+		#endif
+
+		if(collTime == NULL)	
+		{ 
+			std::cout << "Failed to allocate host memory. (collTime)" << std::endl;
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+/////////////////////////////////// NBody::random Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Generates random values in the interval [randMax, randMin]
+//
+/////////////////////////////////// NBody::random Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+float NBody::random(float randMax, float randMin)
+{
+    float result;
+    result =(float)rand()/(float)RAND_MAX;
+
+    return ((1.0f - result) * randMin + result *randMax);
+}
Index: proiecte/NBody/NBody 2.0/SetupOpenCL.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/SetupOpenCL.cpp	(revision 35)
+++ proiecte/NBody/NBody 2.0/SetupOpenCL.cpp	(revision 35)
@@ -0,0 +1,179 @@
+#include "NBody.hpp"
+
+extern int numBodies;			// No. of particles;
+
+/////////////////////////////////// NBody::setupCL Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Initialize OpenCL specific information : 
+//		- get context, devices;
+//		- create command-queues, memory buffers, program, kernels;
+//
+/////////////////////////////////// NBody::setupCL Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+int NBody::setupCL()
+{
+    cl_int status = CL_SUCCESS;
+
+    cl_device_type dType;
+    
+    if(deviceType.compare("cpu") == 0)
+    {
+        dType = CL_DEVICE_TYPE_CPU;
+    }
+    else //deviceType = "gpu" 
+    {
+        dType = CL_DEVICE_TYPE_GPU;
+    }
+
+    /* Create context from given device type */
+    context = clCreateContextFromType(
+                  0,
+                  dType,
+                  NULL,
+                  NULL,
+                  &status);
+    /* 
+     * if opencl fails to open a context on default device GPU 
+	 * then it falls back to CPU 
+     */
+    if(status != CL_SUCCESS && dType == CL_DEVICE_TYPE_GPU)
+    {
+        std::cout << "Unsupported GPU device; falling back to CPU ..." << std::endl;
+		std::cout << std::endl;
+        context = clCreateContextFromType(
+                      0, 
+                      CL_DEVICE_TYPE_CPU, 
+                      NULL, 
+                      NULL, 
+                      &status);
+    }
+
+	if (status != CL_SUCCESS){
+		std::cout << "clCreateContextFromType failed." << std::endl;
+		return 1;
+	}
+
+	size_t deviceListSize;
+    
+    /* First, get the size of device list data */
+    status = clGetContextInfo(
+			     context, 
+                 CL_CONTEXT_DEVICES, 
+                 0, 
+                 NULL, 
+                 &deviceListSize);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetContextInfo failed." << std::endl;
+		return 1;
+	}
+	
+    /* Now allocate memory for device list based on the size we got earlier */
+    devices = (cl_device_id *)malloc(deviceListSize);
+    
+	if(devices==NULL) {
+		std::cout << "Failed to allocate memory (devices)." << std::endl;
+		return 1;
+	}
+
+    /* Now, get the device list data */
+    status = clGetContextInfo(
+			     context, 
+                 CL_CONTEXT_DEVICES, 
+                 deviceListSize, 
+                 devices, 
+                 NULL);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clGetContextInfo failed." << std::endl;
+		return 1;
+	}
+  
+    /* Create command queue */
+
+    commandQueue = clCreateCommandQueue(
+                       context,
+                       devices[0],
+                       0,
+                       &status);
+	
+	if (status != CL_SUCCESS){
+		std::cout <<  "clCreateCommandQueue failed." << std::endl;
+		return 1;
+	}
+
+  	//----------------------------------
+	// Device infos:
+
+	getDeviceInfo();
+ 
+    /*
+     * Create and initialize memory objects
+     */
+
+	//================================================
+	// Buffers used for all Kernels:
+
+    /* Create memory objects for position */
+	updatedPos = clCreateBuffer(
+					  context,
+					  CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
+					  numBodies * sizeof(cl_float4), // numbodies * (cl_float  f32[4]);
+					  pos,	
+					  &status);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clCreateBuffer failed. (updatePos)" << std::endl;
+		return 1;
+	}
+   
+    /* Create memory objects for velocity */
+	updatedVel = clCreateBuffer(
+					  context,
+					  CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
+					  numBodies * sizeof(cl_float4),
+					  vel,
+					  &status);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clCreateBuffer failed. (updatedVel)" << std::endl;
+		return 1;
+	}
+
+	//================================================
+	// Buffers used only for Leapfrog Kernels:
+
+	if (integrator == LEAPFROG){
+
+		/* Create memory objects for accelerations */
+		updatedAcc = clCreateBuffer(
+						  context,
+						  CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
+						  numBodies * sizeof(cl_float4),
+						  acc,
+						  &status);
+		
+		if (status != CL_SUCCESS){
+			std::cout << "clCreateBuffer failed. (updatedAcc)" << std::endl;
+			return 1;
+		}
+
+		/* Create memory objects for collision time */
+		updatedCollTime = clCreateBuffer(
+						  context,
+						  CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
+						  numBodies * sizeof(cl_float),
+						  collTime,
+						  &status);
+		
+		if (status != CL_SUCCESS){
+			std::cout << "clCreateBuffer failed. (updatedCollTime)" << std::endl;
+			return 1;
+		}
+
+		initialAccComputation = 1;
+	}
+   
+    return 0;
+}
+
Index: proiecte/NBody/NBody 2.0/SetupProgramCL.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/SetupProgramCL.cpp	(revision 35)
+++ proiecte/NBody/NBody 2.0/SetupProgramCL.cpp	(revision 35)
@@ -0,0 +1,126 @@
+#include "NBody.hpp"
+
+/////////////////////////////////// NBody::setupCLProgram() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Build CL kernel program executable.
+//
+/////////////////////////////////// NBody::setupCLProgram() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+int NBody::setupCLProgram()
+{
+	cl_int   status;
+
+	/* create a CL program using the kernel source */
+	char *program_source = load_program_source(kernelFileName);
+	size_t sourceSize[] = { strlen(program_source) };
+	
+    program = clCreateProgramWithSource(
+        context,
+        1,
+        (const char**)&program_source,
+        sourceSize,
+        &status);
+  
+	if (status != CL_SUCCESS){
+		std::cout << "clCreateProgramWithSource failed." << std::endl;
+		return 1;
+	}
+
+	/* create a cl program executable for all the devices specified */
+    status = clBuildProgram(
+                 program,
+                 1,
+                 &devices[0],
+                 NULL,
+                 NULL,
+                 NULL);
+    
+	if(status != CL_SUCCESS)
+    {
+        if(status == CL_BUILD_PROGRAM_FAILURE)
+        {
+            cl_int logStatus;
+            char * buildLog = NULL;
+            size_t buildLogSize = 0;
+            logStatus = clGetProgramBuildInfo (program, 
+                                            devices[0], 
+                                            CL_PROGRAM_BUILD_LOG, 
+                                            buildLogSize, 
+                                            buildLog, 
+                                            &buildLogSize);
+			if (logStatus != CL_SUCCESS){
+				std::cout << "clGetProgramBuildInfo failed." << std::endl;
+				return 1;
+			}
+           
+            buildLog = (char*)malloc(buildLogSize);
+            if(buildLog == NULL)
+            {
+                std::cout << "Failed to allocate host memory. (buildLog)" << std::endl;
+                return 1;
+            }
+            memset(buildLog, 0, buildLogSize);
+
+            logStatus = clGetProgramBuildInfo (program, 
+                                            devices[0], 
+                                            CL_PROGRAM_BUILD_LOG, 
+                                            buildLogSize, 
+                                            buildLog, 
+                                            NULL);
+			if (logStatus != CL_SUCCESS){
+				std::cout << "clGetProgramBuildInfo failed." << std::endl;
+				free(buildLog);
+				return 1;
+			}
+       
+
+            std::cout << " \n\t\t\tBUILD LOG\n";
+            std::cout << " ************************************************\n";
+            std::cout << buildLog << std::endl;
+            std::cout << " ************************************************\n";
+            free(buildLog);
+        }
+        
+		if(status != CL_SUCCESS)
+        {
+            std::cout << "clBuildProgram failed." << std::endl;
+            return 1;
+        }
+    }
+}
+
+/////////////////////////////////// NBody::load_program_source Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Loads the kernel code form a .cl file type and returns the source code as a char*
+//
+/////////////////////////////////// NBody::load_program_source Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+char* NBody::load_program_source(const char *filename)
+{ 
+	FILE *fh; 
+	char *source; 
+	int size;
+	
+	fh = fopen(filename, "r");
+	if (fh == NULL){
+		std::cout << "Reading the source cod for kernel failed." << std::endl;
+		exit(1); 
+	}
+	
+	fseek (fh, 0, SEEK_END);
+    size = ftell (fh);
+	rewind(fh);
+
+	source = (char *) malloc(size+1);
+
+	int result = fread(source, 1, size, fh);
+	/*if (result != size){
+		std::cout << "Reading the source cod for kernel failed." << std::endl;
+		exit(1); 
+	}*/
+	source[result] = '\0';
+	
+	fclose(fh);
+		
+	return source; 
+} 
