Index: proiecte/NBody/NBody 2.0/GetDeviceInfos.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/GetDeviceInfos.cpp	(revision 34)
+++ proiecte/NBody/NBody 2.0/GetDeviceInfos.cpp	(revision 34)
@@ -0,0 +1,342 @@
+#include "NBody.hpp"
+
+/////////////////////////////////// NBody::getDeviceInfo Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Returns information about the device on  which the simulation 
+// will run. Also some variables will be init here based on the 
+// device information.
+//
+/////////////////////////////////// NBody::getDeviceInfo Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+int NBody::getDeviceInfo()
+{
+	cl_int status = CL_SUCCESS;
+
+	cl_char infoString[1024] = {0};
+	cl_ulong infoLong;
+	cl_uint infoInt;
+	cl_bool infoBool;
+	size_t infoSize_t;
+	size_t *infoSz_t;
+	
+	//----------------------------------
+	status= clGetDeviceInfo(
+			devices[0], 
+			CL_DEVICE_NAME, 
+			sizeof(infoString), 
+			infoString, 
+			NULL);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_NAME failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_NAME : \t\t" << infoString << std::endl;
+	}
+
+	//----------------------------------
+	status = clGetDeviceInfo(
+			devices[0], 
+			CL_DEVICE_VENDOR, 
+			sizeof(infoString), 
+			infoString, 
+			NULL);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_VENDOR failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_VENDOR : \t\t\t" << infoString << std::endl;
+	}
+	
+	//----------------------------------
+	status = clGetDeviceInfo(
+			devices[0], 
+			CL_DRIVER_VERSION, 
+			sizeof(infoString), 
+			infoString, 
+			NULL);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DRIVER_VERSION failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DRIVER_VERSION : \t\t\t" << infoString << std::endl;
+	}
+
+	//----------------------------------
+	status = clGetDeviceInfo(
+			devices[0], 
+			CL_DEVICE_TYPE, 
+			sizeof(cl_device_type), 
+			(void*)&infoLong, 
+			NULL);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_TYPE failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_TYPE : \t\t\t";
+
+		switch(infoLong){
+			case CL_DEVICE_TYPE_CPU :			std::cout << "CL_DEVICE_TYPE_CPU" << std::endl;
+												break;
+			case CL_DEVICE_TYPE_GPU :			std::cout << "CL_DEVICE_TYPE_GPU" << std::endl;
+												break;
+			case CL_DEVICE_TYPE_ACCELERATOR	: 	std::cout << "CL_DEVICE_TYPE_ACCELERATOR" << std::endl;
+												break;
+			case CL_DEVICE_TYPE_ALL :			std::cout << "CL_DEVICE_TYPE_ALL" << std::endl;
+												break;
+			case CL_DEVICE_TYPE_DEFAULT :		std::cout << "CL_DEVICE_TYPE_DEFAULT" << std::endl;
+												break;
+		}
+	}
+
+	std::cout << std::endl;
+
+	//----------------------------------
+	// The number of parallel compute cores
+	// on the OpenCL device.
+
+	status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_MAX_COMPUTE_UNITS,
+            sizeof(cl_uint),
+            (void*)&infoInt,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_MAX_COMPUTE_UNITS failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_MAX_COMPUTE_UNITS : \t\t" << (size_t)infoInt << std::endl;
+	}
+
+	//----------------------------------
+	status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
+            sizeof(cl_uint),
+            (void*)&maxDimensions,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS : \t" << (size_t)maxDimensions << std::endl;
+	}
+	   
+    maxWorkItemSizes = (size_t*)malloc(maxDimensions * sizeof(size_t));
+    
+	//----------------------------------
+	// Maximum number of work-items that can be 
+	// specified in each dimension of the work-group 
+	// to clEnqueueNDRangeKernel.
+
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_MAX_WORK_ITEM_SIZES,
+            sizeof(size_t) * maxDimensions,
+            (void*)maxWorkItemSizes,
+            NULL);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_SIZES failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_MAX_WORK_ITEM_SIZES : \t" << (size_t)maxWorkItemSizes << std::endl;
+	}
+
+	//----------------------------------
+	// Maximum number of work-items in a work-group 
+	// executing a kernel using the data parallel 
+	// execution model
+
+
+	status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_MAX_WORK_GROUP_SIZE,
+            sizeof(size_t),
+            (void*)&maxWorkGroupSize,
+            NULL);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_MAX_WORK_GROUP_SIZE failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_MAX_WORK_GROUP_SIZE : \t" << maxWorkGroupSize << std::endl;
+	}
+
+	std::cout << std::endl;
+
+	//----------------------------------
+	// Is CL_TRUE if images are supported by the 
+	// OpenCL device and CL_FALSE otherwise.
+
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_IMAGE_SUPPORT,
+            sizeof(cl_bool),
+            (void *)&infoBool,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE_SUPPORT failed." << std::endl;
+		return 1;
+	}else{
+		if (infoBool == true)
+			std::cout << "CL_DEVICE_IMAGE_SUPPORT : \t\t" << "true" << std::endl;
+		else
+			std::cout << "CL_DEVICE_IMAGE_SUPPORT : \t\t" << "false" << std::endl;
+	}
+
+	//----------------------------------
+	// Max width of 2D image in pixels. The minimum 
+	// value is 8192 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
+
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_IMAGE2D_MAX_WIDTH,
+            sizeof(size_t),
+            (void *)&infoSize_t,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE2D_MAX_WIDTH failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_IMAGE2D_MAX_WIDTH : \t\t" << (size_t)infoSize_t 
+			<< " pixels" << std::endl;
+	}
+
+	//----------------------------------
+	// Max height of 2D image in pixels. The minimum value 
+	// is 8192 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
+
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_IMAGE2D_MAX_HEIGHT,
+            sizeof(size_t),
+            (void *)&infoSize_t,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE2D_MAX_HEIGHT failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_IMAGE2D_MAX_HEIGHT : \t\t" << (size_t)infoSize_t 
+			<< " pixels" << std::endl;
+	}
+
+	//----------------------------------
+	// Max width of 3D image in pixels. The minimum value 
+	// is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
+
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_IMAGE3D_MAX_WIDTH,
+            sizeof(size_t),
+            (void *)&infoSize_t,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE3D_MAX_WIDTH failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_IMAGE3D_MAX_WIDTH : \t\t" << (size_t)infoSize_t 
+			<< " pixels" << std::endl;
+	}
+
+	//----------------------------------
+	// Max height of 3D image in pixels. The minimum value 
+	// is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
+
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_IMAGE3D_MAX_HEIGHT,
+            sizeof(size_t),
+            (void *)&infoSize_t,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE3D_MAX_HEIGHT failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_IMAGE3D_MAX_HEIGHT : \t\t" << (size_t)infoSize_t 
+			<< " pixels" << std::endl;
+	}
+
+	//----------------------------------
+	// Max depth of 3D image in pixels. The minimum value 
+	// is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
+
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_IMAGE3D_MAX_DEPTH,
+            sizeof(size_t),
+            (void *)&infoSize_t,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE3D_MAX_DEPTH failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_IMAGE3D_MAX_DEPTH : \t\t" << (size_t)infoSize_t 
+			<< " pixels" << std::endl;
+	}
+
+	std::cout << std::endl;
+
+	//----------------------------------
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_MAX_CLOCK_FREQUENCY,
+            sizeof(cl_uint),
+            (void *)&infoInt,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_MAX_CLOCK_FREQUENCY failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_MAX_CLOCK_FREQUENCY : \t" << infoInt << " MHz" << std::endl;
+	}
+
+	//----------------------------------
+	// Size of global device memory in bytes.
+
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_GLOBAL_MEM_SIZE,
+            sizeof(cl_ulong),
+            (void *)&infoLong,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_GLOBAL_MEM_SIZE failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_GLOBAL_MEM_SIZE : \t\t" << infoLong << " bytes" << std::endl;
+	}
+
+	//----------------------------------
+	// Size of local memory arena in bytes.
+	// The minimum value is 16 KB.
+
+    status = clGetDeviceInfo(
+            devices[0],
+            CL_DEVICE_LOCAL_MEM_SIZE,
+            sizeof(cl_ulong),
+            (void *)&totalLocalMemory,
+            NULL);
+
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_LOCAL_MEM_SIZE failed." << std::endl;
+		return 1;
+	}else{
+		std::cout << "CL_DEVICE_LOCAL_MEM_SIZE : \t\t" << totalLocalMemory << " bytes" << std::endl;
+	}
+
+	return 0;
+}
Index: proiecte/NBody/NBody 2.0/Input-Output/input_64.txt
===================================================================
--- proiecte/NBody/NBody 2.0/Input-Output/input_64.txt	(revision 34)
+++ proiecte/NBody/NBody 2.0/Input-Output/input_64.txt	(revision 34)
@@ -0,0 +1,64 @@
+0.0078125 -0.561583 -0.0653953 -0.54142 -0.106656 -0.119243 0.286915 
+0.0078125 4.85715 -0.32989 -1.61621 0.388497 0.20792 0.120547 
+0.0078125 0.593217 0.235838 -0.0272317 0.0567244 -0.0189743 -0.391682 
+0.0078125 0.425112 -0.0570265 -0.102289 -0.76996 0.739456 -0.169181 
+0.0078125 -0.0244972 0.862396 -0.000555732 0.128044 0.160373 0.206437 
+0.0078125 -0.513309 -0.167869 1.09716 0.349379 0.347551 -0.0848735 
+0.0078125 -0.264388 -0.746426 -0.542277 0.639579 -0.373554 -0.226712 
+0.0078125 0.417573 0.310909 0.59141 -0.0583432 -0.00363399 -0.245571 
+0.0078125 0.154153 0.41177 -0.10071 -0.787805 0.105596 -0.438093 
+0.0078125 -4.6044 1.10861 0.33756 -0.139234 -0.143949 -0.154247 
+0.0078125 -0.706602 -0.0472532 0.748726 -0.0727336 0.334968 0.383024 
+0.0078125 -0.192172 -0.337933 0.213683 -0.901189 -0.475339 -0.539601 
+0.0078125 0.179866 -0.268977 -0.0605338 0.223589 -0.0170284 -0.186268 
+0.0078125 2.96078 -1.41116 -1.33619 0.0559445 0.257364 -0.209946 
+0.0078125 0.172295 0.207404 -0.133516 0.0956968 0.253246 -0.88766 
+0.0078125 -0.514109 0.144286 -0.0704705 0.208169 0.789467 0.788264 
+0.0078125 -0.177585 1.20233 -0.677041 0.312979 0.106783 -0.673485 
+0.0078125 0.448221 0.578203 0.141096 0.214575 -0.474873 -0.165383 
+0.0078125 -0.0329403 2.75999 -0.5621 0.146503 0.150967 0.0838864 
+0.0078125 0.0113743 0.139806 0.256194 -0.140107 -0.237034 0.896022 
+0.0078125 -0.143066 0.451225 0.347718 -0.0682482 0.395516 0.193018 
+0.0078125 -0.772185 0.292455 0.255409 -0.283089 -0.0587602 -0.013165 
+0.0078125 0.0261782 0.18092 -1.06157 0.00541864 -0.303779 0.542291 
+0.0078125 -0.357691 -0.326914 1.05071 -0.101559 -0.639916 0.464835 
+0.0078125 -0.941137 -0.113388 -0.0571181 0.391073 0.214316 0.0434986 
+0.0078125 -0.206825 -0.429225 0.329095 -0.636147 -0.506036 -0.00934656 
+0.0078125 -0.281783 0.357202 0.593003 0.110573 -0.205025 -0.213378 
+0.0078125 0.14681 -0.0808604 0.366173 0.227999 -0.00231039 -0.690504 
+0.0078125 -0.00283323 0.497696 -0.370414 0.309578 -0.454582 0.0793015 
+0.0078125 -0.364943 0.0668188 0.524401 -0.441061 -0.0287642 0.44691 
+0.0078125 -0.593893 -0.457863 0.250611 0.449883 0.156787 0.759861 
+0.0078125 0.721056 0.708421 -0.0803228 0.417303 0.261432 0.255582 
+0.0078125 2.79888 -3.81444 5.72763 -0.0788148 -0.11228 -0.0911524 
+0.0078125 -0.264817 0.580976 0.324753 0.204712 0.501081 0.60662 
+0.0078125 0.159077 -0.194931 3.03607 0.248306 0.127007 -0.335696 
+0.0078125 0.384243 -0.474148 0.117701 -0.591088 0.138479 0.175385 
+0.0078125 0.891879 -0.981796 0.68726 0.369926 0.0436471 0.356356 
+0.0078125 -0.23801 -0.340323 -0.42139 -0.683381 -0.537409 0.120988 
+0.0078125 -0.54539 0.331053 -0.338651 -0.358726 0.405047 -0.594486 
+0.0078125 0.329465 -0.0716469 0.148638 -0.904883 0.196906 -0.39708 
+0.0078125 -0.245302 0.0406106 -0.0246707 -0.948876 -0.0264139 -0.285205 
+0.0078125 -0.0547374 -0.214788 0.548032 0.373441 0.48664 -0.739805 
+0.0078125 -0.808209 -0.785836 -0.487431 -0.130457 -0.260229 0.137378 
+0.0078125 0.130226 0.251818 -0.27214 0.72646 0.0983734 -0.768273 
+0.0078125 0.816609 0.638435 -0.602271 0.201578 -0.0997548 0.0533556 
+0.0078125 0.0335484 0.160705 -0.604803 -0.458248 -0.328877 -0.231626 
+0.0078125 0.289742 0.0851022 0.296247 0.0590116 -0.146066 -0.260767 
+0.0078125 0.803008 0.235945 1.32902 -0.182219 -0.204981 0.274746 
+0.0078125 -0.11325 0.0231081 0.692128 0.422542 -0.281747 0.117922 
+0.0078125 0.839393 -0.790337 0.371333 0.0761422 -0.195154 -0.120698 
+0.0078125 -0.376874 0.196914 -0.427419 0.378496 -0.0721329 0.818237 
+0.0078125 -0.0851764 -0.633248 -0.728609 -0.0371911 0.124373 0.443528 
+0.0078125 1.26564 -0.693253 0.124148 -0.0656925 -0.31456 0.200808 
+0.0078125 0.540138 0.838819 0.594402 -0.0695378 0.267221 -0.0535934 
+0.0078125 0.718664 -0.866464 0.43578 0.0328011 0.624732 -0.622752 
+0.0078125 0.0709217 0.289103 -1.18601 -0.541128 -0.273111 0.259376 
+0.0078125 0.165375 0.253924 0.308721 -0.302709 0.206246 -0.421021 
+0.0078125 0.30295 0.45103 -1.18285 -0.675552 -0.309687 -0.195789 
+0.0078125 1.91037 1.48552 1.6489 -0.0572668 -0.167331 -0.0485191 
+0.0078125 -0.203928 2.21686 0.365465 0.370893 -0.154465 -0.229943 
+0.0078125 -0.141565 0.121267 -0.190342 -0.324136 1.06391 -0.252832 
+0.0078125 0.882969 0.318097 -1.22108 0.0106645 -0.0603032 0.28376 
+0.0078125 1.68156 -0.970704 0.955315 -0.112403 -0.0539148 0.155832 
+0.0078125 1.29341 -0.0844446 3.79333 0.151948 0.0359666 0.0193931
Index: proiecte/NBody/NBody 2.0/Kernels/leapfrogIntegratorKernel.cl
===================================================================
--- proiecte/NBody/NBody 2.0/Kernels/leapfrogIntegratorKernel.cl	(revision 34)
+++ proiecte/NBody/NBody 2.0/Kernels/leapfrogIntegratorKernel.cl	(revision 34)
@@ -0,0 +1,132 @@
+__constant float VERY_LARGE_NUMBER = 99999999; // A big number used fo scalling time steps;
+
+
+__kernel void leapfrog_integrator(	__global float4* pos ,
+
+									__global float4* vel,
+
+									int numBodies,
+
+								    float deltaTime,
+		
+								    float epsSqr,
+
+								    __local float4* localPos,
+								    
+								    __local float4* localVel,
+								    
+								    __global float4* acc ,
+								    
+								    int initialAccComputation,
+								   
+								    __global float* collTime)
+
+{
+	//---------------------------------------
+    unsigned int tid = get_local_id(0);		
+
+    unsigned int gid = get_global_id(0);		// Index of the particle that it must update;
+
+    unsigned int localSize = get_local_size(0); // This can be thought of as the number of threads
+												// executing this kernel, for different work-items, 
+												// concurrently and synchronously;
+
+	//---------------------------------------
+    // Number of tiles we need to iterate
+
+    unsigned int numTiles = numBodies / localSize;
+
+
+	//---------------------------------------
+	// Reads the particle position (and mass) and velocity 
+	// of particle "i" for which this kernel invocation 
+	// is tasked to update. 
+	
+    float4 oldPos = pos[gid];
+    float4 oldVel = vel[gid];
+
+	//---------------------------------------
+	// Initializes the float4 we will use to accumulate
+	// the acceleration on particle "i".
+	
+    float4 oldAcc = (float4)(0.0f, 0.0f, 0.0f, 0.0f);
+
+	float time_scale_sq = VERY_LARGE_NUMBER;	// Init the collision time [read theory
+												// for more information;
+												
+    // Compute the partial v_(n+1) and x_(n+1):
+	//oldVel += acc[gid]*deltaTime/2;
+	//oldPos += oldVel*deltaTime;
+	
+    for(int i = 0; i < numTiles; ++i)
+
+    {
+        // load one tile into local memory
+
+        int idx = i * localSize + tid;
+
+        localPos[tid] = pos[idx];
+        localVel[tid] = vel[idx];
+
+        // Synchronize to make sure data is available for processing
+
+        barrier(CLK_LOCAL_MEM_FENCE);
+
+        for(int j = 0; j < localSize; ++j)
+
+        {
+			float4 rji, vji;
+            float r2= 0.0f, r3= 0.0f, v2=0.0f;	// r^2, r^3, v^2;
+           	
+			rji = localPos[j] - oldPos;
+			vji = localVel[j] - oldVel;
+           
+			r2 = pow(rji.x, 2) + pow(rji.y, 2) + pow(rji.z, 2);
+			v2 = pow(vji.x, 2) + pow(vji.y, 2) + pow(vji.z, 2);
+
+			if (r2 == 0)
+				r2 = 0.000000000001;
+           
+			r3= r2*sqrt(r2);
+		
+        	//----------------------
+			// The computation of acc
+			
+			oldAcc += oldPos.w*rji/r3;
+			
+			
+			//----------------------
+			// The computation of time_scale_sq:
+			
+			float estimate_sq= r2/v2;			// [distance]^2/[velocity]^2 = [time]^2
+        	if (time_scale_sq > estimate_sq){
+          		time_scale_sq = estimate_sq;
+			}
+			
+			float a = (oldPos.w + localPos[j].w)/r2;
+		    estimate_sq = sqrt(r2)/a;         	// [distance]/[acceleration] = [time]^2
+			
+			if (time_scale_sq > estimate_sq){
+          		time_scale_sq = estimate_sq;
+			}
+	    }
+
+        // Synchronize so that next tile can be loaded
+
+        barrier(CLK_LOCAL_MEM_FENCE);
+		
+    }
+    
+    collTime[gid] = sqrt(time_scale_sq);
+    
+    // Now we compute the rest of the v_(n+1):
+    //oldVel += oldAcc*deltaTime/2;
+    
+//	pos[gid] = oldPos;
+//	vel[gid] = oldVel;
+	acc[gid] = oldAcc;
+
+}
+
+
+
Index: proiecte/NBody/NBody 2.0/Kernels/simpleIntegratorKernel.cl
===================================================================
--- proiecte/NBody/NBody 2.0/Kernels/simpleIntegratorKernel.cl	(revision 34)
+++ proiecte/NBody/NBody 2.0/Kernels/simpleIntegratorKernel.cl	(revision 34)
@@ -0,0 +1,122 @@
+/*
+ * Each work-item invocation of this kernel, calculates the position for 
+ * one particle
+ *
+ * Work-items use local memory to reduce memory bandwidth and reuse of data
+ */
+
+__kernel void simple_integrator(	__global float4* pos ,
+
+									__global float4* vel,
+
+									int numBodies,
+
+								    float deltaTime,
+		
+								    float epsSqr,
+
+								    __local float4* localPos)
+
+{
+	//---------------------------------------
+    unsigned int tid = get_local_id(0);		
+
+    unsigned int gid = get_global_id(0);		// Index of the particle that it must update;
+
+    unsigned int localSize = get_local_size(0); // This can be thought of as the number of threads
+												// executing this kernel, for different work-items, 
+												// concurrently and synchronously;
+
+	//---------------------------------------
+    // Number of tiles we need to iterate
+
+    unsigned int numTiles = numBodies / localSize;
+
+
+	//---------------------------------------
+	// Reads the particle position (and mass) and velocity 
+	// of particle "i" for which this kernel invocation 
+	// is tasked to update. 
+	
+    float4 oldPos = pos[gid];
+    float4 oldVel = vel[gid];
+
+	//---------------------------------------
+	// Initializes the float4 we will use to accumulate
+	// the acceleration on particle "i".
+	
+    float4 acc = (float4)(0.0f, 0.0f, 0.0f, 0.0f);
+
+
+    for(int i = 0; i < numTiles; ++i)
+
+    {
+
+        // load one tile into local memory
+
+        int idx = i * localSize + tid;
+
+        localPos[tid] = pos[idx];
+
+
+
+        // Synchronize to make sure data is available for processing
+
+        barrier(CLK_LOCAL_MEM_FENCE);
+
+
+        // calculate acceleration effect due to each body
+
+        // a[i->j] = m[j] * r[i->j] / (r^2 + epsSqr)^(3/2)
+
+        for(int j = 0; j < localSize; ++j)
+
+        {
+
+            // Calculate acceleartion caused by particle j on particle i
+
+            float4 r = localPos[j] - oldPos;
+
+            float distSqr = r.x * r.x  +  r.y * r.y  +  r.z * r.z;
+
+            float invDist = 1.0f / sqrt(distSqr + epsSqr);
+
+            float invDistCube = invDist * invDist * invDist;
+
+            float s = localPos[j].w * invDistCube;
+
+
+
+            // accumulate effect of all particles
+
+            acc += s * r;
+
+        }
+
+        // Synchronize so that next tile can be loaded
+
+        barrier(CLK_LOCAL_MEM_FENCE);
+
+    }
+
+
+
+    // updated position and velocity
+
+    float4 newPos = oldPos + oldVel * deltaTime + acc * 0.5f * deltaTime * deltaTime;
+
+    newPos.w = oldPos.w;
+
+
+
+    float4 newVel = oldVel + acc * deltaTime;
+
+
+
+    // write to global memory
+
+    pos[gid] = newPos;
+
+    vel[gid] = newVel;
+}
+
Index: proiecte/NBody/NBody 2.0/NBody 2.0.vcproj
===================================================================
--- proiecte/NBody/NBody 2.0/NBody 2.0.vcproj	(revision 34)
+++ proiecte/NBody/NBody 2.0/NBody 2.0.vcproj	(revision 34)
@@ -0,0 +1,248 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9.00"
+	Name="NBody 2.0"
+	ProjectGUID="{4E58C4AD-225E-4A7E-8234-EE7CB259218C}"
+	RootNamespace="NBody20"
+	Keyword="Win32Proj"
+	TargetFrameworkVersion="196613"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="C:\NVIDIA\GPU Computing SDK 2.3\OpenCL\common\inc\; C:\NVIDIA\GPU Computing SDK 2.3\shared\inc\"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="oclUtils32D.lib shrUtils32D.lib glew32.lib glut32.lib OpenCL.lib"
+				LinkIncremental="2"
+				AdditionalLibraryDirectories="C:\NVIDIA\GPU Computing SDK 2.3\OpenCL\common\lib\;C:\NVIDIA\GPU Computing SDK 2.3\shared\lib\;C:\NVIDIA\GPU Computing SDK 2.3\OpenCL\common\lib\$(PlatformName)\"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				EnableIntrinsicFunctions="true"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="1"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\GetDeviceInfos.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\NBody_main.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\OpenGLDisplay.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\OutputData.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\ReleaseResources.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\RunKernels.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\SetupKernelsCL.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\SetupNBody.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\SetupOpenCL.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\SetupProgramCL.cpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath=".\NBody.hpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+			>
+		</Filter>
+		<Filter
+			Name="Kernels"
+			>
+			<File
+				RelativePath=".\Kernels\leapfrogIntegratorKernel.cl"
+				>
+			</File>
+			<File
+				RelativePath=".\Kernels\simpleIntegratorKernel.cl"
+				>
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
Index: proiecte/NBody/NBody 2.0/NBody 2.0.vcproj.STATIAGX4.3dUPB.user
===================================================================
--- proiecte/NBody/NBody 2.0/NBody 2.0.vcproj.STATIAGX4.3dUPB.user	(revision 34)
+++ proiecte/NBody/NBody 2.0/NBody 2.0.vcproj.STATIAGX4.3dUPB.user	(revision 34)
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioUserFile
+	ProjectType="Visual C++"
+	Version="9.00"
+	ShowAllFiles="false"
+	>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			>
+			<DebugSettings
+				Command="$(TargetPath)"
+				WorkingDirectory=""
+				CommandArguments=""
+				Attach="false"
+				DebuggerType="3"
+				Remote="1"
+				RemoteMachine="STATIAGX4"
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor=""
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			>
+			<DebugSettings
+				Command="$(TargetPath)"
+				WorkingDirectory=""
+				CommandArguments=""
+				Attach="false"
+				DebuggerType="3"
+				Remote="1"
+				RemoteMachine="STATIAGX4"
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor=""
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
+	</Configurations>
+</VisualStudioUserFile>
Index: proiecte/NBody/NBody 2.0/NBody.hpp
===================================================================
--- proiecte/NBody/NBody 2.0/NBody.hpp	(revision 34)
+++ proiecte/NBody/NBody 2.0/NBody.hpp	(revision 34)
@@ -0,0 +1,338 @@
+#ifndef NBODY_H_
+#define NBODY_H_
+
+// standard utility and system includes
+#include <oclUtils.h>
+
+// GLEW and GLUT includes
+#include <GL/glew.h>
+#if defined (__APPLE__) || defined(MACOSX)
+    #include <GLUT/glut.h>
+#else
+    #include <GL/glut.h>
+#endif
+
+// Extra CL/GL include
+#include <CL/cl_gl.h>
+
+
+#include <iostream>
+#include <iomanip>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <cmath>
+#include <malloc.h>
+#include <time.h>
+
+#include <GL/glut.h>
+
+#define GROUP_SIZE 64
+#define NUM_PARTICLES 30000
+#define END_TIME 2
+
+//----------------------
+#define TAKE_DIAGNOSTICS		0
+#define DO_NOT_TAKE_DIAGNOSTICS 1
+#define TAKE_SNAPSHOTS			2
+#define DO_NOT_TAKE_SNAPSHOTS	3
+
+static int takeDiagnostics = DO_NOT_TAKE_DIAGNOSTICS;
+static int takeSnapshots = DO_NOT_TAKE_SNAPSHOTS;
+
+//----------------------
+#define SIMPLE		0
+#define LEAPFROG	1
+
+static int integrator = 0;
+
+//----------------------
+
+static bool displayOpenGL = true;			// If it is true then OpenGL display is used; 
+static bool readInputData = false;			// If true then the particles information will be read
+											// from an input file. If it is false, then the information
+											// is generated via random functions;
+
+static std::string deviceType("gpu");		// It says on which device we want to do the computations;
+
+static time_t rawtime;						// Variables used for measuring the duration of the run;
+static struct tm * timeinfo;
+
+static char* inputDataFileName = "Input-Output\\input_64.txt";
+											// Represents the name of the file which contains the
+											// information about particles (mass, position, vel);
+
+static char* snapshotFileName = "Input-Output\\snapshot.txt";	
+											// Represents the name of the file in which we will take
+											// snapshots of the current system when we require.
+
+static char* diagnosticFileName = "Input-Output\\diagnostic.txt";	
+											// Represents the name of the file in which we will
+											// write information about the energy conservation,
+											// from time to time;
+
+//----------------------
+
+
+/**
+ * NBody 
+ * Class implements OpenCL  NBody sample
+ *
+ */
+
+class NBody 
+{
+public:
+
+	//================================================
+	// General variables used for all integrators
+
+    cl_double  setupTimeCL;			// Time taken to setup OpenCL resources and building kernel;
+    cl_double  kernelTime;			// Time taken to run kernel and read result back;
+    
+	cl_context context;             // CL context; 
+    cl_device_id *devices;          // CL device list; 
+
+    size_t maxWorkGroupSize;        // Max allowed work-items in a group;
+    cl_uint maxDimensions;          // Max group dimensions allowed;
+    size_t* maxWorkItemSizes;       // Max work-items sizes in each dimensions;
+    cl_ulong totalLocalMemory;      // Max local memory allowed;
+    cl_ulong usedLocalMemory;       // Used local memory;
+
+	cl_float* initPos;              // Initial position. Used to hold the initial particle position;
+    cl_float* initVel;              // Initial velocity. Used to hold the initial particle velocity;
+	
+	cl_float* pos;					// This is the buffer for positions that resides on the host
+									// side of the application. It is linked with the memory
+									// buffer for positions "updatedPos";
+    
+	cl_float* vel;                  // This is the buffer for velocities that resides on the host
+									// side of the application. It is linked with the memory
+									// buffer for velocities "updatedVel";
+
+
+    cl_mem   updatedPos;            // This is a memory buffer representing the position of 
+									// partciles. It is linked with the application buffer 
+									// for positions "pos". updatedPos is set as an argument to
+									// the kernel, and also used to read data from the kernel by
+									// enqueueing a read command. It will represent the updated
+									// values of positions after running once the kernel;
+   
+	cl_mem   updatedVel;            // This is a memory buffer representing the poelocity of 
+									// partciles. It is linked with the application buffer 
+									// for velocities "vel". updatedVel is set as an argument to
+									// the kernel, and also used to read data from the kernel by
+									// enqueueing a read command. It will represent the updated
+									// values of velocities after running once the kernel; 
+    
+	cl_command_queue commandQueue;  // CL command queue; 
+    cl_program program;             // CL program; 
+    cl_kernel kernel;               // CL kernel; 
+
+    cl_int  numParticles;			// Number of particles in the system;  
+		    
+    cl_float espSqr;                // Softening Factor;
+	cl_float delT;                  // dT (timestep);
+	cl_double curr_time_step;		// Reatins the current time step in the simulation;
+	cl_double end_time;				// The total time (end time) of the simulation; 
+	cl_long taken_steps;			// Tne number of steps taken by now (at the curr_time_step);
+	cl_double dt_snap;				// The interval between two snapshots;
+	cl_double dt_diag;				// The interval between two diagnostics;
+	cl_double curr_snap_time;		// This is the current time that must be reached by 
+									// curr_time_step in order to take a snapshot. After this,
+									// curr_snap_time will be incremented by dt_snap;
+	cl_double curr_diag_time;		// This is the current time that must be reached by 
+									// curr_time_step in order to make a diagnostication of the
+									// system. After this, curr_diag_time will be incremented by dt_diag;
+	
+	cl_double Etot_init;			// Will retain the total energy of the system at the beggining
+									// of the simulation. It is used to measure the convergence
+									// (error) of the simulation;
+
+	bool initFlag;					// This flag variable is used to make some initialisations of
+									// variables when the simulation starts. For example if 
+									// initFlag is true, than we are starting the simulation and
+									// compute "Etot_init" energy. After this first step of simulation
+									// it becomes false;
+
+	const char * kernelFileName;	// The name of the file that contains the kernel code;
+	const char * kernelFunctionName;// The name of the __kernel function in the kernel file;
+
+	//================================================
+	// Variables specific only to Leapfrog integrator:
+
+	cl_float* acc;                  // This is the buffer for accelerations that resides on the host
+									// side of the application. It is linked with the memory
+									// buffer for accelerations "updatedAcc";
+
+    cl_mem   updatedAcc;            // This is a memory buffer representing the acceleration of 
+									// partciles. It is linked with the application buffer 
+									// for acc "acc". updatedAcc is set as an argument to
+									// the kernel, and also used to read data from the kernel by
+									// enqueueing a read command. It will represent the updated
+									// values of accelerations after running once the kernel;
+	cl_mem   updatedCollTime;
+	cl_float* collTime;
+
+	cl_int initialAccComputation;
+
+	
+
+	
+private:
+	float random(float randMax, float randMin);
+   
+public:
+    /** 
+     * Constructor 
+     * Initialize member variables
+     * @param name name of sample (string)
+     */
+    explicit NBody(std::string name)
+    {
+		setupTimeCL = 0;
+		kernelTime = 0;
+		delT = 0.005f;
+		espSqr = 50.0f;
+		initPos = NULL;
+		initVel = NULL;
+		pos = NULL;
+		vel = NULL;
+		devices = NULL;
+		maxWorkItemSizes = NULL;
+		kernelFileName = "Kernels\\simpleIntegratorKernel.cl";
+		kernelFunctionName = "simple_integrator";
+		numParticles = 30;
+		curr_time_step = 0;
+		end_time = 10;	
+		initFlag = true;
+		dt_snap = 0.1;
+		dt_diag = 0.1;
+		curr_snap_time = dt_snap;
+		curr_diag_time = dt_diag;
+		taken_steps = 0;
+    }
+
+    /** 
+     * Constructor 
+     * Initialize member variables
+     * @param name name of sample (const char*)
+     */
+    explicit NBody(const char* name)
+    {
+		setupTimeCL = 0;
+		kernelTime = 0;
+		delT = 0.01f;
+		espSqr = 50.0f;
+		initPos = NULL;
+		initVel = NULL;
+		pos = NULL;
+		vel = NULL;
+		devices = NULL;
+		maxWorkItemSizes = NULL;
+		if (integrator == LEAPFROG){
+			kernelFileName = "Kernels\\leapfrogIntegratorKernel.cl";
+			kernelFunctionName = "leapfrog_integrator";
+		}else{
+			kernelFileName = "Kernels\\simpleIntegratorKernel.cl";
+			kernelFunctionName = "simple_integrator";
+		}
+		numParticles = NUM_PARTICLES;
+		curr_time_step = 0;
+		end_time = END_TIME;
+		initFlag = true;
+		dt_snap = 1.0;
+		dt_diag = 1.0;
+		curr_snap_time = dt_snap;
+		curr_diag_time = dt_diag;
+		taken_steps = 0;
+    }
+
+    ~NBody();
+
+    /**
+     * Returns information about the device on  which the
+	 * simulation will run. Also some variables will be init
+	 * here based on the device information
+     * @return 1 on success and 0 on failure
+     */
+	int getDeviceInfo();
+
+    /**
+     * Allocate and initialize host memory array with random values
+     * @return 1 on success and 0 on failure
+     */
+    int setupNBody();
+
+    /**
+     * OpenCL related initialisations. 
+     * Set up Context, Device list, Command Queue, Memory buffers
+     * @return 1 on success and 0 on failure
+     */
+    int setupCL();
+
+	/**
+     * Build CL kernel program executable
+     * @return 1 on success and 0 on failure
+	 */
+	int setupCLProgram();
+
+    /**
+     * Build kernels and set values for kernels' arguments
+     * @return 1 on success and 0 on failure
+     */
+    int setupCLKernels();
+
+    /**
+     * Enqueue calls to the kernels
+     * on to the command queue, wait till end of kernel execution.
+     * Get kernel start and end time if timing is enabled
+     * @return 1 on success and 0 on failure
+     */
+    int runCLKernels();
+
+    /**
+     * Load a .cl source file as a char* and it will be used
+	 * for as a parameter for creating a program
+     * @return the char vector
+     */
+	char * load_program_source(const char *filename);
+
+    /**
+     * Override from SDKSample
+     * Run OpenCL NBody
+     */
+    int run();
+
+    /**
+     * Override from SDKSample
+     * Cleanup memory allocations
+     */
+    int cleanup();
+	
+	/**
+     * Writes a single snapshot on the output snapshot file.
+	 */
+	void put_snapshot();
+	
+	/**
+	 * Writes diagnostics on the diagnostics file:
+	 * current time; number of integration steps so far;
+	 * kinetic, potential, and total energy; absolute and
+	 * relative energy errors since the start of the run.
+	 */
+	void write_diagnostics();
+	
+	/**
+	 * Computes the potential energy of a single particle.
+	 */ 
+	float epot_particle(int currPart);
+
+	int runCLKernelLeapfrog();
+
+	int enqueueKernel();
+
+};
+
+#endif // NBODY_H_
Index: proiecte/NBody/NBody 2.0/NBody_main.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/NBody_main.cpp	(revision 34)
+++ proiecte/NBody/NBody 2.0/NBody_main.cpp	(revision 34)
@@ -0,0 +1,104 @@
+#include "NBody.hpp"
+
+//----------------------
+ extern int numBodies;					
+
+ void* me;								// Pointing to NBody class; 
+
+ FILE *snapshotsFile, *diagnosticsFile;	// Represent the files that will retain the snapshots 
+										// and diagnostics;
+ FILE *inputDataFile;					// Represents the file for inputData for paricles;
+
+//----------------------
+extern void startOpenGLSimulation(int argc, char * argv[]);
+
+
+/////////////////////////////////// MAIN Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Here starts the application
+//
+/////////////////////////////////// MAIN Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+int main(int argc, char * argv[])
+{
+    NBody clNBody("OpenCL NBody");
+    me = &clNBody;
+	
+	//--------------------------------
+	// Open file for input data if this option is
+	// activated:
+	if (readInputData){
+		inputDataFile = fopen(inputDataFileName, "r");
+		if(inputDataFile == NULL)
+		{
+			std::cout << "Error opening inputData file." << std::endl;
+			return 1;
+		}
+	}
+
+	//--------------------------------
+	// Open files for output data:
+	snapshotsFile = fopen(snapshotFileName, "w");
+	if(snapshotsFile == NULL)
+	{
+		std::cout << "Error opening snapshots file." << std::endl;
+		return 1;
+	}
+
+	diagnosticsFile = fopen(diagnosticFileName, "w");
+	if(diagnosticsFile == NULL)
+	{
+		std::cout << "Error opening diagnostics file." << std::endl;
+		return 1;
+	}
+
+	//--------------------------------
+	// Initialize particles:
+	if(clNBody.setupNBody()!= 0){		// SDK_SUCCESS == 0;
+        return 1;
+	}
+
+	//--------------------------------
+	// Initialize OpenCL env:
+	if(clNBody.setupCL()!= 0){			// SDK_SUCCESS == 0;
+        return 1;
+	}
+
+	//--------------------------------
+	// Build CL kernel program executable:
+	if(clNBody.setupCLProgram() != 0){	// SDK_SUCCESS == 0;
+        return 1;
+	}
+
+	//--------------------------------
+    // Create kernels and set arguments to Kernels:
+	if(clNBody.setupCLKernels()!= 0){	// SDK_SUCCESS == 0;
+		return 1;
+    }
+
+	//--------------------------------
+	// Start the simulation:
+	std::cout << std::endl;
+	std::cout << "============================" << std::endl;
+	std::cout << "Simulation started..." << std::endl;
+	std::cout << std::endl;
+
+	time ( &rawtime );
+	timeinfo = localtime ( &rawtime );
+	std::cout << "Start time and date: " << asctime (timeinfo) << std::endl;
+
+	startOpenGLSimulation(argc, argv);
+
+	//--------------------------------
+	// Clean memory allocation:
+	if(clNBody.cleanup() != 0){			// SDK_SUCCESS == 0;
+		return 1;
+	}
+
+	fclose(snapshotsFile);
+	fclose(diagnosticsFile);
+
+	return 0;
+}
+
+
Index: proiecte/NBody/NBody 2.0/OpenGLDisplay.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/OpenGLDisplay.cpp	(revision 34)
+++ proiecte/NBody/NBody 2.0/OpenGLDisplay.cpp	(revision 34)
@@ -0,0 +1,256 @@
+#include "NBody.hpp"
+
+extern int numBodies;					// No. of particles;
+extern void* me;						// Pointing to NBody class; 
+
+bool rotate = false;
+bool translateW = false;
+bool translateZ = false;
+
+//--------------------------------
+// PROTOTIPE FUNCTIONS
+
+void GLInit();
+void idle();
+void reShape(int w,int h);
+void displayfunc();
+void keyboardFunc(unsigned char key, int mouseX, int mouseY);
+
+/////////////////////////////////// startOpenGLSimulation Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// This function is called to display the simulation in
+// OpenGL. If "display" variable is not TRUE then the
+// simulation in OpenGL will not take place.
+//
+/////////////////////////////////// startOpenGLSimulation Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+void startOpenGLSimulation(int argc, char * argv[])
+{
+	char * windowName = (char*)malloc(1024);
+
+	sprintf (windowName, "NBody simulation : %d particles", numBodies);
+	
+
+	if(displayOpenGL)
+    {
+        // Run in  graphical window if requested 
+        glutInit(&argc, argv);
+        glutInitWindowPosition(100,10);
+        glutInitWindowSize(600,600); 
+        glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
+		glutCreateWindow(windowName); 
+		GLInit(); 
+        glutDisplayFunc(displayfunc); 
+        glutReshapeFunc(reShape);
+        glutIdleFunc(idle); 
+        glutKeyboardFunc(keyboardFunc);
+
+		free(windowName);
+
+		try {
+			 glutMainLoop();
+		}
+		catch( char * str ) {
+			std::cout << "OpenGL exited." << std::endl;
+		}
+	}else{
+		free(windowName);
+	}
+}
+
+/////////////////////////////////// GLInit Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Initialize OpenGL related stuff.
+//
+/////////////////////////////////// GLInit Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+void GLInit()
+{
+    glClearColor(0.0 ,0.0, 0.0, 0.0);
+    glClear(GL_COLOR_BUFFER_BIT);
+    glClear(GL_DEPTH_BUFFER_BIT);
+    glMatrixMode(GL_PROJECTION);	
+    glLoadIdentity();
+}
+
+/////////////////////////////////// idle Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Glut Idle function.
+//
+/////////////////////////////////// idle Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+void idle()
+{
+	// If it's time to take a snapshot:
+	if (takeSnapshots == TAKE_SNAPSHOTS){
+		if (((NBody*)me)->curr_time_step > ((NBody*)me)->curr_snap_time){
+			((NBody*)me)->curr_snap_time += ((NBody*)me)->dt_snap;
+			((NBody*)me)->put_snapshot();
+		}
+	}
+
+	// If it's time to take a diagnostication:
+	if (takeDiagnostics == TAKE_DIAGNOSTICS){
+		if (((NBody*)me)->curr_time_step > ((NBody*)me)->curr_diag_time){
+			((NBody*)me)->curr_diag_time += ((NBody*)me)->dt_diag;
+			((NBody*)me)->write_diagnostics();
+			//std::cout << "Current time: " << ((NBody*)me)->curr_time_step << std::endl;
+		}
+
+		// If it's the first step in the simulation compute
+		// the initial total energy of the system:
+		if (((NBody*)me)->taken_steps == 0){
+			((NBody*)me)->write_diagnostics();
+		}
+	}
+
+		if (((NBody*)me)->curr_time_step > ((NBody*)me)->curr_diag_time){
+			((NBody*)me)->curr_diag_time += ((NBody*)me)->dt_diag;
+			std::cout << "Current time: " << ((NBody*)me)->curr_time_step << std::endl;
+		}
+
+	// If it is not the end of the simulation:
+	if (((NBody*)me)->curr_time_step < ((NBody*)me)->end_time){
+		
+		// Move one step foreward (a step = delT):
+		((NBody*)me)->curr_time_step += ((NBody*)me)->delT;
+		
+		// Increase the number of steps by now:
+		((NBody*)me)->taken_steps++;
+		
+		//if (((NBody*)me)->taken_steps == 1800)
+		//	std::cout << "some test beep here \a\n";
+
+		//std::cout << 
+
+	}else{
+		std::cout << std::endl;
+		std::cout << "Simulation ended..." << std::endl;
+		std::cout << std::endl;
+	    time ( &rawtime );
+		timeinfo = localtime ( &rawtime );
+		std::cout << "End time and date: " << asctime (timeinfo) << std::endl;
+		std::cout << "============================" << std::endl;
+		
+		exit(1);
+	}
+
+    glutPostRedisplay();
+}
+
+/////////////////////////////////// reShape Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Glut reshape function.
+// @param w width of OpenGL window
+// @param h height of OpenGL window 
+//
+/////////////////////////////////// reShape Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+void reShape(int w,int h)
+{
+    glViewport(0,0,w,h);
+
+    glViewport(0,0,w,h);
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+    gluPerspective(45.0f,w/h,1.0f,1000.0f);
+    gluLookAt (0.0, 0.0, -2.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0);
+}
+
+/////////////////////////////////// displayfunc Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// OpenGL display function.
+//
+/////////////////////////////////// displayfunc Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+void displayfunc()
+{
+    glClearColor(0.0 ,0.0, 0.0, 0.0);
+    glClear(GL_COLOR_BUFFER_BIT);
+    glClear(GL_DEPTH_BUFFER_BIT);
+
+    glPointSize(1.0);
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+    glEnable(GL_BLEND);
+    glDepthMask(GL_FALSE);
+
+    glColor3f(1.0f,0.6f,0.0f);
+
+	//------------------------
+	// Run the kernel on the choosen device:
+	if (((NBody*)me)->curr_time_step < ((NBody*)me)->end_time){
+		//Calling kernel for calculatig subsequent positions
+		if (integrator == LEAPFROG){
+			((NBody*)me)->runCLKernelLeapfrog();
+		}else{
+			((NBody*)me)->runCLKernels();
+		}
+	}
+
+	//------------------------
+	// After running the kernel we have the new updated positions:
+
+	if (rotate){
+		glRotatef(25, 0, 1, 0);
+		rotate = false;
+	}
+	if (translateW){
+		glTranslatef(0, 0, 1);
+		translateW = false;
+	}
+
+	if (translateZ){
+		glTranslatef(0, 0, -1);
+		translateZ = false;
+	}
+
+    glBegin(GL_POINTS);
+		for(int i=0; i < numBodies; ++i)
+		{
+			//divided by 300 just for scaling
+			glVertex3d(	((NBody*)me)->pos[i*4+ 0]/300,
+						((NBody*)me)->pos[i*4+1]/300,
+						((NBody*)me)->pos[i*4+2]/300);
+		}
+    glEnd();
+
+    glFlush();
+    glutSwapBuffers();
+}
+
+/////////////////////////////////// keyboardFunc Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// OpenGL keyboard function.
+//
+/////////////////////////////////// keyboardFunc Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+void keyboardFunc(unsigned char key, int mouseX, int mouseY)
+{
+    switch(key)
+    {
+        /* If the user hits escape or Q, then exit */
+        /* ESCAPE_KEY = 27 */
+        case 27:
+		case 'r': rotate = true;
+				  glutPostRedisplay();
+				  break;
+		case 'w': translateW = true;
+				  glutPostRedisplay();
+				  break;
+		case 'z': translateZ = true;
+				  glutPostRedisplay();
+				  break;
+
+        case 'q':
+        case 'Q':
+            {
+                if(((NBody*)me)->cleanup() != 0) // SDK_SUCCESS == 0;
+                    exit(1);
+                else
+                    exit(0);
+            }
+        default:
+            break;
+    }
+}
+
Index: proiecte/NBody/NBody 2.0/OutputData.cpp
===================================================================
--- proiecte/NBody/NBody 2.0/OutputData.cpp	(revision 34)
+++ proiecte/NBody/NBody 2.0/OutputData.cpp	(revision 34)
@@ -0,0 +1,126 @@
+#include "NBody.hpp"
+
+extern FILE *snapshotsFile, *diagnosticsFile;
+extern void* me;						// Pointing to NBody class; 
+
+/////////////////////////////////// NBody::put_snapshot() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Writes a single snapshot on the output snapshot file.
+//
+/////////////////////////////////// NBody::put_snapshot() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+void NBody::put_snapshot()
+{
+	if (snapshotsFile == NULL){
+		std::cout << "Error: snapshot file not opened." << std::endl;
+		((NBody*)me)->cleanup();
+		exit(1);
+	}
+
+	// cout.precision(16);                     			// Full double precision;
+	fprintf(snapshotsFile, "%d\n", numParticles);		// Total particle number;
+	fprintf(snapshotsFile, "%f\n", curr_time_step);		// Current time;
+
+	for (int i = 0; i < numParticles ; i++){
+		
+		fprintf(snapshotsFile, "%f\t", pos[i*4+3]);		// Mass of particle i;
+    	          	
+    	for (int k = 0; k < 3; k++)
+			fprintf(snapshotsFile, "%f\t", pos[i*4+k]);	// Position of particle i;
+       		  	
+    	for (int k = 0; k < 3; k++)
+      		fprintf(snapshotsFile, "%f\t", vel[i*4+k]);	// Velocity of particle i;
+    	
+		fprintf(snapshotsFile, "\n");
+  	}
+	fprintf(snapshotsFile, "\n");
+}
+
+
+/////////////////////////////////// NBody::epot_particle() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Computes the potential energy of a single particle;
+//
+/////////////////////////////////// NBody::epot_particle() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+float NBody::epot_particle(int currPart)
+{   
+   	float ePot = 0.0;
+	for (int i=0; i<numParticles; i++){
+	   	
+		if (currPart != i){
+
+			int idx_curr = currPart*4;	// The current particle's position index in the "pos" vector;
+			int idx_other = i*4;		// The other particle's position index in the "pos" vector;
+
+			float r[3], r2= 0.0;
+			for (int k = 0; k < 3 ; k++){
+				r[k]= pos[idx_other+k] - pos[idx_curr+k];
+				r2+= r[k]*r[k];
+			}
+				
+			// To avoid Division by Zero:
+			if (r2 == 0) r2= 0.1e-50;
+
+			// ePot = -M1*M2/r;
+			ePot += -pos[idx_curr+3]*pos[idx_other+3]/sqrt(r2);
+		}
+	}
+
+   	return ePot;
+}
+
+/////////////////////////////////// NBody::write_diagnostics() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+//
+// Writes diagnostics on the diagnostics file:
+// current time; number of integration steps so far;
+// kinetic, potential, and total energy; absolute and
+// relative energy errors since the start of the run.
+//
+/////////////////////////////////// NBody::write_diagnostics() Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
+
+void NBody::write_diagnostics()
+{
+
+    float Ekin = 0;       					// The Kinetic energy of the n-body system;
+	for (int i = 0; i < numParticles ; i++){
+		
+		int idx = i*4;
+
+		for (int k = 0; k < 3 ; k++){
+			// pos[idx+3] = mass;	
+			// Ekin = 1/2*m*(v^2)
+
+            Ekin += 0.5 * pos[idx+3] * vel[idx+k] * vel[idx+k];
+		}
+	}
+
+    float Epot= 0;							// The Potential energy of the n-body system;
+	for (int i=0; i<numParticles; i++)
+    	Epot += epot_particle(i);
+    
+  	Epot *= 0.5;		  					// Against double counting;
+
+    float Etot =  Ekin+Epot;  	 			// The total energy of the actual n-body system;
+
+	if (initFlag){                       	// At first pass, the initial energy is equal to the
+		Etot_init = Etot; 					// total energy of the system. We will keep this initial
+											// energy for error detections;
+	}										
+
+	if (!initFlag){							// At first pass we don't write any diagnostics;
+		if (diagnosticsFile == NULL){
+			std::cout << "Error: diagnostics file not opened." << std::endl;
+			((NBody*)me)->cleanup();
+			exit(1);
+		}
+
+		// cout.precision(16);                     	// Full double precision;
+		fprintf(diagnosticsFile, "At time t = %f, after %ld steps:\n", curr_time_step, taken_steps);
+		fprintf(diagnosticsFile, " E_init = %f,\n E_tot = %f,\n E_kin = %f,\n E_pot = %f\n", Etot_init, Etot, Ekin, Epot);
+		fprintf(diagnosticsFile, "                Absolute energy error: E_tot - E_init = %f\n", Etot - Etot_init);
+		fprintf(diagnosticsFile, "                Relative energy error: (E_tot - E_init) / E_init = %f\n", (Etot - Etot_init) / Etot_init);
+	}else{
+		initFlag = false;
+	}
+}
