Index: proiecte/NBody/NBody 1.0/NBody 1.0.sln
===================================================================
--- proiecte/NBody/NBody 1.0/NBody 1.0.sln	(revision 30)
+++ proiecte/NBody/NBody 1.0/NBody 1.0.sln	(revision 30)
@@ -0,0 +1,20 @@
+﻿
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NBody 1.0", "NBody 1.0\NBody 1.0.vcproj", "{6A0B1FF6-EE6A-4CF8-84D8-7C45EEFEBE21}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{6A0B1FF6-EE6A-4CF8-84D8-7C45EEFEBE21}.Debug|Win32.ActiveCfg = Debug|Win32
+		{6A0B1FF6-EE6A-4CF8-84D8-7C45EEFEBE21}.Debug|Win32.Build.0 = Debug|Win32
+		{6A0B1FF6-EE6A-4CF8-84D8-7C45EEFEBE21}.Release|Win32.ActiveCfg = Release|Win32
+		{6A0B1FF6-EE6A-4CF8-84D8-7C45EEFEBE21}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal
Index: proiecte/NBody/NBody 1.0/NBody 1.0/Debug/NBody 1.0.exe.embed.manifest
===================================================================
--- proiecte/NBody/NBody 1.0/NBody 1.0/Debug/NBody 1.0.exe.embed.manifest	(revision 30)
+++ proiecte/NBody/NBody 1.0/NBody 1.0/Debug/NBody 1.0.exe.embed.manifest	(revision 30)
@@ -0,0 +1,15 @@
+﻿<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
+    </dependentAssembly>
+  </dependency>
+</assembly>
Index: proiecte/NBody/NBody 1.0/NBody 1.0/Debug/NBody 1.0.exe.intermediate.manifest
===================================================================
--- proiecte/NBody/NBody 1.0/NBody 1.0/Debug/NBody 1.0.exe.intermediate.manifest	(revision 30)
+++ proiecte/NBody/NBody 1.0/NBody 1.0/Debug/NBody 1.0.exe.intermediate.manifest	(revision 30)
@@ -0,0 +1,15 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+    <security>
+      <requestedPrivileges>
+        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+      </requestedPrivileges>
+    </security>
+  </trustInfo>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity type='win32' name='Microsoft.VC90.DebugCRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
+    </dependentAssembly>
+  </dependency>
+</assembly>
Index: proiecte/NBody/NBody 1.0/NBody 1.0/Debug/mt.dep
===================================================================
--- proiecte/NBody/NBody 1.0/NBody 1.0/Debug/mt.dep	(revision 30)
+++ proiecte/NBody/NBody 1.0/NBody 1.0/Debug/mt.dep	(revision 30)
@@ -0,0 +1,1 @@
+Manifest resource last updated at 23:58:59.30 on Thu 12/03/2009 
Index: proiecte/NBody/NBody 1.0/NBody 1.0/NBody 1.0.vcproj
===================================================================
--- proiecte/NBody/NBody 1.0/NBody 1.0/NBody 1.0.vcproj	(revision 30)
+++ proiecte/NBody/NBody 1.0/NBody 1.0/NBody 1.0.vcproj	(revision 30)
@@ -0,0 +1,202 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9.00"
+	Name="NBody 1.0"
+	ProjectGUID="{6A0B1FF6-EE6A-4CF8-84D8-7C45EEFEBE21}"
+	RootNamespace="NBody10"
+	Keyword="Win32Proj"
+	TargetFrameworkVersion="196613"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			InheritedPropertySheets="C:\Program Files\ATI Stream\Samples\samples\opencl\common\openclsdk_debug.vsprops"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				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"
+				LinkIncremental="2"
+				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=".\NBody.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\NBody_Kernels.cl"
+				>
+			</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>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
Index: proiecte/NBody/NBody 1.0/NBody 1.0/NBody 1.0.vcproj.YOUR-10F19F641C.Iulian C-tin Milas.user
===================================================================
--- proiecte/NBody/NBody 1.0/NBody 1.0/NBody 1.0.vcproj.YOUR-10F19F641C.Iulian C-tin Milas.user	(revision 30)
+++ proiecte/NBody/NBody 1.0/NBody 1.0/NBody 1.0.vcproj.YOUR-10F19F641C.Iulian C-tin Milas.user	(revision 30)
@@ -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="YOUR-10F19F641C"
+				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="YOUR-10F19F641C"
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor=""
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
+	</Configurations>
+</VisualStudioUserFile>
Index: proiecte/NBody/NBody 1.0/NBody 1.0/NBody.cpp
===================================================================
--- proiecte/NBody/NBody 1.0/NBody 1.0/NBody.cpp	(revision 30)
+++ proiecte/NBody/NBody 1.0/NBody 1.0/NBody.cpp	(revision 30)
@@ -0,0 +1,1002 @@
+#include "NBody.hpp"
+
+int numBodies;					// No. of particles;
+cl_float* pos;					// Output position; 
+void* me;						// Pointing to NBody class; 
+cl_bool display;				// If it is true then OpenGL display is used; 
+long curr_step = 0;				// Reatins the current step in the simulation;
+long n_steps = 110;				// Numbuer of steps of the simulation; 
+cl_bool verify = false;			// Compares the final position vectors resulted from running
+								// the code on CPU and GPU;
+
+
+std::string deviceType("cpu");	// It says on which device we want to do the computations;
+
+time_t rawtime;					// Variables used for measuring the duration of the run;
+struct tm * timeinfo;
+
+
+float NBody::random(float randMax, float randMin)
+{
+    float result;
+    result =(float)rand()/(float)RAND_MAX;
+
+    return ((1.0f - result) * randMin + result *randMax);
+}
+
+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 only in this function to
+	// initialize the other vectors: the pos and vel vectors
+	// used in simulation on GPU only, and refPos and refVel used in
+	// simulation on CPU only
+    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 
+    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);
+
+        // 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;
+    }
+
+	//--------------------------------------------
+	// Variables used on GPU Running only:	
+	if(deviceType.compare("gpu") == 0){
+
+		#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));
+	}
+
+	//--------------------------------------------
+	// Variables used on CPU Running only:
+	if(deviceType.compare("cpu") == 0){
+
+		refPos = (cl_float*)malloc(numBodies * sizeof(cl_float4));
+		if(refPos == NULL)	
+		{ 
+			std::cout << "Failed to allocate host memory. (refPos)" << std::endl;
+			return 1;
+		}
+
+		refVel = (cl_float*)malloc(numBodies * sizeof(cl_float4));
+		if(refVel == NULL)	
+		{ 
+			std::cout << "Failed to allocate host memory. (refVel)" << std::endl;
+			return 1;
+		}
+		
+		// Copy the auxiliary vectors into the refPos and refVel ones:
+		memcpy(refPos, initPos, 4 * numBodies * sizeof(cl_float));
+		memcpy(refVel, initVel, 4 * numBodies * sizeof(cl_float));
+	}
+
+	return 0;
+}
+
+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;
+        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;
+	}
+
+    /* Get Device specific Information */
+    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;
+	}
+	//----------------------------------
+	// Device infos:
+	cl_char vendor_name[1024] = {0};
+	cl_char device_name[1024] = {0};
+	
+	status = clGetDeviceInfo(
+			devices[0], 
+			CL_DEVICE_VENDOR, 
+			sizeof(vendor_name), 
+			vendor_name, 
+			NULL);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_VENDOR failed." << std::endl;
+		return 1;
+	}
+		
+	status|= clGetDeviceInfo(
+			devices[0], 
+			CL_DEVICE_NAME, 
+			sizeof(device_name), 
+			device_name, 
+			NULL);
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clGetDeviceInfo CL_DEVICE_NAME failed." << std::endl;
+		return 1;
+	}
+
+	std::cout << "Connecting to " << vendor_name << ", " << device_name << " ... " << 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;
+	}
+	   
+    maxWorkItemSizes = (size_t*)malloc(maxDimensions * sizeof(size_t));
+    
+    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;
+	}
+ 
+    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;
+	}
+ 
+    /*
+     * Create and initialize memory objects
+     */
+
+    /* Create memory objects for position */
+	if(deviceType.compare("gpu") == 0){
+		updatedPos = clCreateBuffer(
+						  context,
+						  CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
+						  numBodies * sizeof(cl_float4),
+						  pos,
+						  &status);
+	}else
+	if(deviceType.compare("cpu") == 0){
+		updatedPos = clCreateBuffer(
+				  context,
+				  CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
+				  numBodies * sizeof(cl_float4),
+				  refPos,
+				  &status);
+	}
+
+	if (status != CL_SUCCESS){
+		std::cout << "clCreateBuffer failed. (updatePos)" << std::endl;
+		return 1;
+	}
+   
+    /* Create memory objects for velocity */
+	if(deviceType.compare("gpu") == 0){
+		updatedVel = clCreateBuffer(
+						  context,
+						  CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
+						  numBodies * sizeof(cl_float4),
+						  vel,
+						  &status);
+	}else
+	if(deviceType.compare("cpu") == 0){
+		updatedVel = clCreateBuffer(
+						  context,
+						  CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
+						  numBodies * sizeof(cl_float4),
+						  refVel,
+						  &status);
+	}
+	
+	if (status != CL_SUCCESS){
+		std::cout << "clCreateBuffer failed. (updatedVel)" << std::endl;
+		return 1;
+	}
+   
+    /* create a CL program using the kernel source */
+	char *program_source = load_program_source(filename);
+	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;
+        }
+    }
+
+    /* get a kernel object handle for a kernel with the given name */
+    kernel = clCreateKernel(
+                 program,
+                 "nbody_sim",
+                 &status);
+	
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clCreateKernel failed." << std::endl;
+        return 1;
+    }
+
+    return 0;
+}
+
+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; 
+} 
+
+int NBody::setupCLKernels()
+{
+    cl_int   status;
+
+    /*** Set appropriate arguments to the kernel ***/
+
+    /* Particle positions */
+    status = clSetKernelArg(
+                 kernel,
+                 0,
+                 sizeof(cl_mem),
+                 (void *)&updatedPos);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (updatedPos)" << std::endl;
+        return 1;
+    }
+
+    /* Particle velocity */
+    status = clSetKernelArg(
+                 kernel,
+                 1,
+                 sizeof(cl_mem),
+                 (void *)&updatedVel);
+	
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (updatedVel)" << std::endl;
+        return 1;
+    }
+ 
+    /* numBodies */
+    status = clSetKernelArg(
+                 kernel,
+                 2,
+                 sizeof(cl_int),
+                 (void *)&numBodies);
+
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (numBodies)" << std::endl;
+        return 1;
+    }
+
+    /* time step */
+    status = clSetKernelArg(
+                 kernel,
+                 3,
+                 sizeof(cl_float),
+                 (void *)&delT);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (delT)" << std::endl;
+        return 1;
+    }
+
+    /* upward Pseudoprobability */
+    status = clSetKernelArg(
+                 kernel,
+                 4,
+                 sizeof(cl_float),
+                 (void *)&espSqr);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (espSqr)" << std::endl;
+        return 1;
+    }
+
+    /* local memory */
+    status = clSetKernelArg(
+                 kernel,
+                 5,
+                 GROUP_SIZE * 4 * sizeof(float),
+                 NULL);
+	if(status != CL_SUCCESS)
+    {
+        std::cout << "clSetKernelArg failed. (localPos)" << std::endl;
+        return 1;
+    }
+    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;
+}
+
+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;
+}
+
+/*
+ * n-body simulation on cpu
+ */
+void NBody::nBodyCPUReference()
+{
+    //Iterate for all samples
+    for(int i = 0; i < numBodies; ++i)
+    {
+        int myIndex = 4 * i;
+        float acc[3] = {0.0f, 0.0f, 0.0f};
+        for(int j = 0; j < numBodies; ++j)
+        {
+            float r[3];
+            int index = 4 * j;
+
+            float distSqr = 0.0f;
+            for(int k = 0; k < 3; ++k)
+            {
+                r[k] = refPos[index + k] - refPos[myIndex + k];
+
+                distSqr += r[k] * r[k];
+            }
+
+            float invDist = 1.0f / sqrt(distSqr + espSqr);
+            float invDistCube =  invDist * invDist * invDist;
+            float s = refPos[index + 3] * invDistCube;
+
+            for(int k = 0; k < 3; ++k)
+            {
+                acc[k] += s * r[k];
+            }
+        }
+
+        for(int k = 0; k < 3; ++k)
+        {
+            refPos[myIndex + k] += refVel[myIndex + k] * delT + 0.5f * acc[k] * delT * delT;
+            refVel[myIndex + k] += acc[k] * delT;
+        }
+    }
+}
+
+int NBody::setup()
+{
+    if(setupNBody()!= 0) // SDK_SUCCESS == 0;
+        return 1;
+/*
+    int timer = sampleCommon->createTimer();
+    sampleCommon->resetTimer(timer);
+    sampleCommon->startTimer(timer);
+*/ 
+    if(setupCL()!= 0)
+        return 1;
+
+/*    sampleCommon->stopTimer(timer);
+    // Compute setup time 
+    setupTime = (double)(sampleCommon->readTimer(timer));
+*/
+    display= true;
+
+    return 0;
+}
+
+/** 
+* @brief Initialize GL 
+*/
+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();
+}
+
+/** 
+* @brief Glut Idle function
+*/
+void idle()
+{
+	if (curr_step < n_steps){
+		curr_step++;
+	}else{
+	    time ( &rawtime );
+		timeinfo = localtime ( &rawtime );
+		std::cout << "End time and date: " << asctime (timeinfo) << std::endl;
+		exit(1);
+	}
+
+    glutPostRedisplay();
+}
+
+/** 
+* @brief Glut reshape func
+* 
+* @param w numParticles of OpenGL window
+* @param h height of OpenGL window 
+*/
+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);
+}
+
+/** 
+* @brief OpenGL display function
+*/
+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);
+
+	if (curr_step < n_steps){
+		if (deviceType.compare("gpu") == 0){
+			//Calling kernel for calculatig subsequent positions
+			((NBody*)me)->runCLKernels();
+		}else
+		if (deviceType.compare("cpu") == 0){
+			((NBody*)me)->nBodyCPUReference();
+		}
+	}
+
+    glBegin(GL_POINTS);
+    for(int i=0; i < numBodies; ++i)
+    {
+		if (deviceType.compare("gpu") == 0){
+			//divided by 300 just for scaling
+			glVertex3d(pos[i*4+ 0]/300,pos[i*4+1]/300,pos[i*4+2]/300);
+		}else
+		if (deviceType.compare("cpu") == 0){
+			//divided by 300 just for scaling
+			glVertex3d(((NBody*)me)->refPos[i*4+ 0]/300,((NBody*)me)->refPos[i*4+1]/300,((NBody*)me)->refPos[i*4+2]/300);
+		}
+    }
+    glEnd();
+
+    glFlush();
+    glutSwapBuffers();
+}
+
+/* keyboard function */
+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 'q':
+        case 'Q':
+            {
+                if(((NBody*)me)->cleanup() != 0) // SDK_SUCCESS == 0;
+                    exit(1);
+                else
+                    exit(0);
+            }
+        default:
+            break;
+    }
+}
+
+int NBody::run()
+{
+    /* Arguments are set and execution call is enqueued on command buffer */
+    if(setupCLKernels()!= 0) // SDK_SUCCESS == 0;
+    {
+        return 1;
+    }
+
+/*
+    if(!quiet)
+    {
+		// Printeaza pozitiile corpurilor de la inceput:
+        sampleCommon->printArray<cl_float>("Output", pos, numBodies, 1);
+    }
+*/
+	return 0;
+}
+
+void NBody::printStats()
+{
+ /*   std::string strArray[3] = {"Particles", "Iterations", "Time(sec)"};
+    std::string stats[3];
+    totalTime = setupTime + kernelTime;
+
+    stats[0] = sampleCommon->toString(numParticles, std::dec);
+    stats[1] = sampleCommon->toString(ITER, std::dec);
+    stats[2] = sampleCommon->toString(totalTime, std::dec);
+
+    this->SDKSample::printStats(strArray, stats, 3);
+	*/ 
+}
+
+int NBody::cleanup()
+{
+    /* 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;
+	}
+
+    return 0;
+}
+
+NBody::~NBody()
+{
+    /* 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(refPos)
+    {
+        free(refPos);
+        refPos = NULL;
+    }
+
+    if(refVel)
+    {
+        free(refVel);
+        refVel = NULL;
+    }
+
+    if(maxWorkItemSizes)
+    {
+        free(maxWorkItemSizes);
+        maxWorkItemSizes = NULL;
+    }
+}
+
+
+int main(int argc, char * argv[])
+{
+    NBody clNBody("OpenCL NBody");
+    me = &clNBody;
+ 
+	if(clNBody.setup() != 0)
+		return 1;
+
+    if(clNBody.run() != 0)
+		return 1;
+
+	time ( &rawtime );
+	timeinfo = localtime ( &rawtime );
+	std::cout << "Start time and date: " << asctime (timeinfo) << std::endl;
+	
+	if(display)
+    {
+        // Run in  graphical window if requested 
+        glutInit(&argc, argv);
+        glutInitWindowPosition(100,10);
+        glutInitWindowSize(600,600); 
+        glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
+        glutCreateWindow("NBody simulation"); 
+        GLInit(); 
+        glutDisplayFunc(displayfunc); 
+        glutReshapeFunc(reShape);
+        glutIdleFunc(idle); 
+        glutKeyboardFunc(keyboardFunc);
+        glutMainLoop();
+    }
+    
+	if(clNBody.cleanup() != 0)
+		return 1;
+
+	clNBody.printStats();
+
+	return 0;
+}
Index: proiecte/NBody/NBody 1.0/NBody 1.0/NBody.hpp
===================================================================
--- proiecte/NBody/NBody 1.0/NBody 1.0/NBody.hpp	(revision 30)
+++ proiecte/NBody/NBody 1.0/NBody 1.0/NBody.hpp	(revision 30)
@@ -0,0 +1,174 @@
+#ifndef NBODY_H_
+#define NBODY_H_
+
+#include <CL/cl.h>
+
+#include <iostream>
+#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 ITER 5
+
+/**
+ * NBody 
+ * Class implements OpenCL  NBody sample
+ *
+ */
+
+class NBody 
+{
+	public:
+    cl_double  setupTime;			// Time taken to setup OpenCL resources and building kernel;
+    cl_double  kernelTime;			// Time taken to run kernel and read result back;
+    
+    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 delT;                  // dT (timestep);
+    cl_float espSqr;                // Softening Factor;
+    cl_float* initPos;              // Initial position;
+    cl_float* initVel;              // Initial velocity; 
+    cl_float* vel;                  // Output velocity; 
+    cl_float* refPos;               // Reference position; 
+    cl_float* refVel;               // Reference velocity; 
+    cl_context context;             // CL context; 
+    cl_device_id *devices;          // CL device list; 
+    cl_mem   updatedPos;            // Position of partciles; 
+    cl_mem   updatedVel;            // Velocity of partciles; 
+    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;  
+	const char * filename;			// The name of the file that contains the kernel code;
+
+
+private:
+
+    float random(float randMax, float randMin);
+    int compareArray(const float* mat0, const float* mat1, unsigned int size);
+
+public:
+    /** 
+     * Constructor 
+     * Initialize member variables
+     * @param name name of sample (string)
+     */
+    explicit NBody(std::string name)
+    {
+		  setupTime = 0;
+		  kernelTime = 0;
+		  delT = 0.005f;
+		  espSqr = 50.0f;
+		  initPos = NULL;
+		  initVel = NULL;
+		  vel = NULL;
+		  refPos = NULL;
+		  refVel = NULL;
+		  devices = NULL;
+		  maxWorkItemSizes = NULL;
+		  filename = "NBody_Kernels.cl";
+		  numParticles = 164;
+    }
+
+    /** 
+     * Constructor 
+     * Initialize member variables
+     * @param name name of sample (const char*)
+     */
+    explicit NBody(const char* name)
+    {
+		  setupTime = 0;
+		  kernelTime = 0;
+		  delT = 0.005f;
+		  espSqr = 50.0f;
+		  initPos = NULL;
+		  initVel = NULL;
+		  vel = NULL;
+		  refPos = NULL;
+		  refVel = NULL;
+		  devices = NULL;
+		  maxWorkItemSizes = NULL;
+		  filename = "NBody_Kernels.cl";
+		  numParticles = 1564;
+    }
+
+    ~NBody();
+
+    /**
+     * 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
+     * Build CL kernel program executable
+     * @return 1 on success and 0 on failure
+     */
+    int setupCL();
+
+    /**
+     * 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);
+
+    /**
+     * Reference CPU implementation of Binomial Option
+     * for performance comparison
+     */
+    void nBodyCPUReference();
+
+    /**
+     * Override from SDKSample. Print sample stats.
+     */
+    void printStats();
+
+    /**
+     * Override from SDKSample, adjust width and height 
+     * of execution domain, perform all sample setup
+     */
+    int setup();
+
+    /**
+     * Override from SDKSample
+     * Run OpenCL NBody
+     */
+    int run();
+
+    /**
+     * Override from SDKSample
+     * Cleanup memory allocations
+     */
+    int cleanup();
+};
+
+#endif // NBODY_H_
Index: proiecte/NBody/NBody 1.0/NBody 1.0/NBody_Kernels.cl
===================================================================
--- proiecte/NBody/NBody 1.0/NBody 1.0/NBody_Kernels.cl	(revision 30)
+++ proiecte/NBody/NBody 1.0/NBody 1.0/NBody_Kernels.cl	(revision 30)
@@ -0,0 +1,123 @@
+/*
+ * 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 nbody_sim(	__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);
+
+    unsigned int localSize = get_local_size(0);
+
+
+
+    // Number of tiles we need to iterate
+
+    unsigned int numTiles = numBodies / localSize;
+
+
+
+    // position of this work-item
+
+    float4 myPos = pos[gid];
+
+    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] - myPos;
+
+            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);
+
+    }
+
+
+
+    float4 oldVel = vel[gid];
+
+
+
+    // updated position and velocity
+
+    float4 newPos = myPos + oldVel * deltaTime + acc * 0.5f * deltaTime * deltaTime;
+
+    newPos.w = myPos.w;
+
+
+
+    float4 newVel = oldVel + acc * deltaTime;
+
+
+
+    // write to global memory
+
+    pos[gid] = newPos;
+
+    vel[gid] = newVel;
+}
+
