diff --git a/SimulationCode/Makefile b/SimulationCode/Makefile index 5140c08..dcec090 100644 --- a/SimulationCode/Makefile +++ b/SimulationCode/Makefile @@ -1,4 +1,4 @@ -CUDA_INSTALL_PATH ?= /usr/local/cuda-9.2/bin +CUDA_INSTALL_PATH ?= /usr/local/cuda/bin CXX := /usr/bin/g++ LDFLAGS=-lglfw -lGL NVCC := $(CUDA_INSTALL_PATH)/nvcc @@ -14,9 +14,9 @@ CUOBJS := $(subst src,build,$(CUOBJS)) TARGET := $(OUTDIR)/main # Options -NVCCOPTIONS =-O3 -m64 -arch=sm_35 -std=c++14 -g +NVCCOPTIONS =-O3 -m64 -arch=sm_35 -std=c++11 -g #NVCCOPTIONS =-O3 -m64 -std=c++14 -g -CXXOPTIONS =-O3 -m64 -std=c++14 -g -Wall -I /usr/local/cuda/include/ +CXXOPTIONS =-O3 -m64 -std=c++11 -g -Wall -I /usr/local/cuda/include/ # Common flags NVCCFLAGS += $(NVCCOPTIONS) diff --git a/SimulationCode/PerformanceTest.sh b/SimulationCode/PerformanceTest.sh new file mode 100755 index 0000000..78fb5bb --- /dev/null +++ b/SimulationCode/PerformanceTest.sh @@ -0,0 +1,15 @@ +make clean +make -j5 +out="output" +out+=$1 +echo ${out} + +echo $1 > input +echo "100" >> input +./out/main < input > ${out} +for i in {0..50} +do + echo $1 > input + echo $((1000 + $i*2000)) >> input + ./out/main < input >> ${out} +done diff --git a/SimulationCode/chart2 b/SimulationCode/chart2 new file mode 100644 index 0000000..e69de29 diff --git a/SimulationCode/input b/SimulationCode/input index 788efb5..42f03b2 100644 --- a/SimulationCode/input +++ b/SimulationCode/input @@ -1,2 +1,2 @@ -4 -100000 +2 +95000 diff --git a/SimulationCode/output2 b/SimulationCode/output2 new file mode 100644 index 0000000..e0f23f3 --- /dev/null +++ b/SimulationCode/output2 @@ -0,0 +1,48 @@ +(100,0.000147255) +(1000,0.00100808) +(3000,0.00286826) +(5000,0.00483034) +(7000,0.00709195) +(9000,0.00980842) +(11000,0.0131749) +(13000,0.0167023) +(15000,0.0205186) +(17000,0.0281992) +(19000,0.0315434) +(21000,0.0350184) +(23000,0.0387652) +(25000,0.0429775) +(27000,0.0480237) +(29000,0.0527792) +(31000,0.0580048) +(33000,0.0851563) +(35000,0.0945012) +(37000,0.103412) +(39000,0.110675) +(41000,0.120121) +(43000,0.136063) +(45000,0.142862) +(47000,0.151272) +(49000,0.159093) +(51000,0.168716) +(53000,0.178091) +(55000,0.185694) +(57000,0.195938) +(59000,0.206165) +(61000,0.21761) +(63000,0.228704) +(65000,0.239777) +(67000,0.300484) +(69000,0.313557) +(71000,0.328274) +(73000,0.345043) +(75000,0.360973) +(77000,0.376232) +(79000,0.391146) +(81000,0.406964) +(83000,0.423311) +(85000,0.439855) +(87000,0.466543) +(89000,0.48233) +(91000,0.494591) +(93000,0.511687) diff --git a/SimulationCode/output4 b/SimulationCode/output4 new file mode 100644 index 0000000..b3dfe23 --- /dev/null +++ b/SimulationCode/output4 @@ -0,0 +1,52 @@ +(100,0.00826626) +(1000,0.0145179) +(3000,0.0219876) +(5000,0.0501732) +(7000,0.0480744) +(9000,0.0454484) +(11000,0.0442917) +(13000,0.0421267) +(15000,0.0429789) +(17000,0.0511684) +(19000,0.0436969) +(21000,0.0445312) +(23000,0.0452354) +(25000,0.0453264) +(27000,0.049968) +(29000,0.047501) +(31000,0.0521729) +(33000,0.0483408) +(35000,0.0498652) +(37000,0.0513726) +(39000,0.0540352) +(41000,0.0534255) +(43000,0.0584782) +(45000,0.056337) +(47000,0.053342) +(49000,0.0504997) +(51000,0.0531557) +(53000,0.0583203) +(55000,0.0546283) +(57000,0.0532342) +(59000,0.0703022) +(61000,0.054763) +(63000,0.0551174) +(65000,0.0766021) +(67000,0.0989813) +(69000,0.0857285) +(71000,0.0693708) +(73000,0.0610821) +(75000,0.0669189) +(77000,0.10345) +(79000,0.104832) +(81000,0.0791419) +(83000,0.0702073) +(85000,0.0853074) +(87000,0.12837) +(89000,0.118374) +(91000,0.087911) +(93000,0.0833733) +(95000,0.0727809) +(97000,0.0687188) +(99000,0.0826717) +(101000,0.0929585) diff --git a/SimulationCode/src/.vscode/settings.json b/SimulationCode/src/.vscode/settings.json new file mode 100644 index 0000000..3dc7f3c --- /dev/null +++ b/SimulationCode/src/.vscode/settings.json @@ -0,0 +1,47 @@ +{ + "files.associations": { + "chrono": "cpp", + "cctype": "cpp", + "cmath": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "*.tcc": "cpp", + "clocale": "cpp", + "cstdint": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "memory": "cpp", + "new": "cpp", + "ostream": "cpp", + "numeric": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "system_error": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "type_traits": "cpp", + "tuple": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "utility": "cpp" + } +} \ No newline at end of file diff --git a/SimulationCode/src/BarnesHutStep.h b/SimulationCode/src/BarnesHutStep.h index f2fa8ab..0e8af74 100644 --- a/SimulationCode/src/BarnesHutStep.h +++ b/SimulationCode/src/BarnesHutStep.h @@ -33,7 +33,7 @@ class BarnesHutStep : public Step { std::vector forces; std::vector velocities; float sizeFrame = 8.0; - const float theta = 0.5; + const float theta = 2.0; const float EPS = 0.01; }; diff --git a/SimulationCode/src/ComputationsBarnesHutCuda.cu b/SimulationCode/src/ComputationsBarnesHutCuda.cu index af2ade6..44b0119 100644 --- a/SimulationCode/src/ComputationsBarnesHutCuda.cu +++ b/SimulationCode/src/ComputationsBarnesHutCuda.cu @@ -1,11 +1,13 @@ #include "ComputationsBarnesHutCuda.h" #include +#include +#include #include #include const float G = 6.674 * (1e-11); const float EPS = 0.01f; -const float theta = 2; +const float theta = 2.0; const int THREADS_PER_BLOCK = 1024; const int K = 15; diff --git a/SimulationCode/src/Main.cpp b/SimulationCode/src/Main.cpp index 1a0d055..6bab866 100644 --- a/SimulationCode/src/Main.cpp +++ b/SimulationCode/src/Main.cpp @@ -3,54 +3,49 @@ using namespace std; int main() { int programVersion, numberOfBodies; - printf("Wybierz tryb wykonywania programu\n"); + //printf("Wybierz tryb wykonywania programu\n"); while (1) { - printf("1. Naiwny algorytm CPU\n2. Naiwny algorytm GPU\n3. Algorytm " - "Barnes-Hut CPU\n4. Algorytm Barnes-Hut GPU\n"); + //printf("1. Naiwny algorytm CPU\n2. Naiwny algorytm GPU\n3. Algorytm " + // "Barnes-Hut CPU\n4. Algorytm Barnes-Hut GPU\n"); int res = scanf("%d", &programVersion); if (programVersion > 4 || programVersion <= 0) { - printf("Nie ma takiej opcji, sprobuj ponownie\n"); + //printf("Nie ma takiej opcji, sprobuj ponownie\n"); continue; } break; } - printf("Podaj liczbę jednostek do poddania symulacji\n"); + //printf("Podaj liczbę jednostek do poddania symulacji\n"); int res = scanf("%d", &numberOfBodies); if(res == EOF) return 1; RandomGenerators *randomGenerator = new RandomGenerators(); std::vector masses(numberOfBodies); randomGenerator->initializeWeights(masses, numberOfBodies); - Render *rend = nullptr; Step *step = nullptr; Simulation *sim; switch (programVersion) { case 1: { - rend = new Render(masses, numberOfBodies, 1.0); step = new StepNaive(masses, numberOfBodies); break; } case 2: { - rend = new Render(masses, numberOfBodies, 1.0); step = new StepNaiveCuda(masses, numberOfBodies); break; } case 3: { - rend = new Render(masses, numberOfBodies, 8.0); step = new BarnesHutStep(masses, numberOfBodies); break; } case 4: { - rend = new Render(masses, numberOfBodies, -1); step = new BarnesHutStepCuda(masses, numberOfBodies); break; } default: break; } - sim = new Simulation(rend, step, numberOfBodies); - sim->MakeSimulation(); - + sim = new Simulation(step, numberOfBodies); + for(int kk=9900; kk<=70000; kk+=500) + sim->MakeSimulation(kk); delete randomGenerator; return 0; } diff --git a/SimulationCode/src/RandomGenerators.cpp b/SimulationCode/src/RandomGenerators.cpp index cf9f0a5..a86ea55 100644 --- a/SimulationCode/src/RandomGenerators.cpp +++ b/SimulationCode/src/RandomGenerators.cpp @@ -44,7 +44,7 @@ void RandomGenerators::initializeWeights(std::vector &weights, unsigned n weights.resize(numberOfBodies); int typeMass = 3; unsigned divi; - printf("TYP %d\n", typeMass); + //printf("TYP %d\n", typeMass); switch (typeMass) { case 0: for (unsigned i = 0; i < numberOfBodies; i++) diff --git a/SimulationCode/src/Render.cpp b/SimulationCode/src/Render.cpp deleted file mode 100644 index ca2ee6a..0000000 --- a/SimulationCode/src/Render.cpp +++ /dev/null @@ -1,329 +0,0 @@ -#include "Render.h" -#include - -float Render::camera_theta = 0.02; -float Render::camera_phi = 0.01; -float Render::camera_radius = 4; -bool Render::is_mouse_pressed = false; -double Render::mouse_position_x = 0; -double Render::mouse_position_y = 0; - -Render::Render(std::vector masses, unsigned numberOfBodies, float cubeSize) : numberOfBodies(numberOfBodies), cubeSize(cubeSize) { - positionsToRender = new float[3*numberOfBodies]; - colorsToRender = new char[3*numberOfBodies]; - massesToRender = new float[numberOfBodies]; - for(unsigned i=0; igetRandomColor(); - } - } - cubeVertices = new float[24*3]{ - -cubeSize, -cubeSize, cubeSize, - cubeSize, -cubeSize, cubeSize, - cubeSize, -cubeSize, cubeSize, - cubeSize, cubeSize, cubeSize, - cubeSize, cubeSize, cubeSize, - -cubeSize, cubeSize, cubeSize, - -cubeSize, cubeSize, cubeSize, - -cubeSize, -cubeSize, cubeSize, - - -cubeSize, -cubeSize, -cubeSize, - cubeSize, -cubeSize, -cubeSize, - cubeSize, -cubeSize, -cubeSize, - cubeSize, cubeSize, -cubeSize, - cubeSize, cubeSize, -cubeSize, - -cubeSize, cubeSize, -cubeSize, - -cubeSize, cubeSize, -cubeSize, - -cubeSize, -cubeSize, -cubeSize, - - -cubeSize, -cubeSize, cubeSize, - -cubeSize, -cubeSize, -cubeSize, - -cubeSize, cubeSize, cubeSize, - -cubeSize, cubeSize, -cubeSize, - cubeSize, -cubeSize, cubeSize, - cubeSize, -cubeSize, -cubeSize, - cubeSize, cubeSize, cubeSize, - cubeSize, cubeSize, -cubeSize - }; -} - -Render::~Render() { - delete randomGenerator; - delete [] massesToRender; - delete [] colorsToRender; - delete [] positionsToRender; - delete [] cubeVertices; -} - -void Render::mouse_move(double xpos, double ypos) { - if(is_mouse_pressed) { - camera_phi += (ypos - mouse_position_y)*0.005; - camera_theta += -(xpos - mouse_position_x)*0.005; - } - mouse_position_x = xpos; - mouse_position_y = ypos; -} - -void Render::mouse_pressed() { - is_mouse_pressed = true; -} - -void Render::mouse_released() { - is_mouse_pressed = false; -} - -void Render::mouse_scroll(double offset) { - camera_radius += offset; -} - -static void MessageCallback(GLenum source, - GLenum type, - GLuint id, - GLenum severity, - GLsizei length, - const GLchar* message, - const void* userParam) -{ - fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", - (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), - type, severity, message); -} - -void error_callback(int error, const char* description) { - throw std::runtime_error(description); -} - -void Render::key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) - glfwSetWindowShouldClose(window, 1); -} - -void Render::scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { - mouse_scroll(yoffset); -} - -void Render::mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { - if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) { - mouse_pressed(); - } - if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) { - mouse_released(); - } -} - -void Render::cursor_position_callback(GLFWwindow* window, double xpos, double ypos) { - mouse_move(xpos, ypos); -} - -void Render::setupWindow() { - if (!glfwInit()) - throw std::runtime_error("Failed to initialize glfw"); - glfwSetErrorCallback(error_callback); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_SAMPLES, 4); - - this->window = glfwCreateWindow(height, width, "N-BODY SIMULATION", NULL, NULL); - if (!this->window) - throw std::runtime_error("Failed to create window"); - - glfwMakeContextCurrent(this->window); - glfwSetKeyCallback(this->window, this->key_callback); - glfwSetCursorPosCallback(this->window, this->cursor_position_callback); - glfwSetMouseButtonCallback(this->window, this->mouse_button_callback); - glfwSetScrollCallback(this->window, this->scroll_callback); - - glfwSwapInterval(1); //enables v-sync -} - -GLuint Render::load_shader(const char* path, int shader_type) { - std::string shader_code; - std::ifstream ShaderStream(path, std::ios::in); - if(ShaderStream.is_open()){ - std::stringstream sstr; - sstr << ShaderStream.rdbuf(); - shader_code = sstr.str(); - ShaderStream.close(); - } - const char *shader_code_array[] = {shader_code.c_str()}; - GLuint shader = glCreateShader(shader_type); - glShaderSource(shader, 1, shader_code_array, nullptr); - glCompileShader(shader); - GLint isCompiled = 0; - glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled); - if(isCompiled == GL_FALSE) - { - GLint maxLength = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); - char* errorLog = new char[maxLength]; - glGetShaderInfoLog(shader, maxLength, &maxLength, errorLog); - printf("Shader compilation failed:\n"); - printf("%s\n", errorLog); - delete errorLog; - glDeleteShader(shader); - exit(1); - } - return shader; - } - -void Render::createAndBindBuffer() { - glEnable(GL_DEBUG_OUTPUT); - glDebugMessageCallback( (GLDEBUGPROC) MessageCallback, 0); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - glEnable (GL_BLEND); - glBlendFunc (GL_ONE, GL_ONE); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - - glGenBuffers(4, buffer); - glBindBuffer(GL_ARRAY_BUFFER, buffer[0]); - glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*numberOfBodies, positionsToRender, GL_DYNAMIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); - - glBindBuffer(GL_ARRAY_BUFFER, buffer[1]); - glBufferData(GL_ARRAY_BUFFER, sizeof(char)*3*numberOfBodies, colorsToRender, GL_DYNAMIC_DRAW); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 3, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0); - - glBindBuffer(GL_ARRAY_BUFFER, buffer[2]); - glBufferData(GL_ARRAY_BUFFER, sizeof(float)*numberOfBodies, massesToRender, GL_DYNAMIC_DRAW); - glEnableVertexAttribArray(2); - glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 0, 0); - - glGenVertexArrays(1, &vao_cube); - glBindVertexArray(vao_cube); - glGenBuffers(1, buffer_cube); - - glBindBuffer(GL_ARRAY_BUFFER, buffer_cube[0]); - glBufferData(GL_ARRAY_BUFFER, sizeof(float)*24*3, cubeVertices, GL_STATIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); -} - -void Render::createAndCompileShaders() { - shVertex = load_shader("./src/vertexshader.glsl", GL_VERTEX_SHADER); - shFragment = load_shader("./src/fragmentshader.glsl", GL_FRAGMENT_SHADER); -} - -void Render::createAndLinkProgram() { - program = glCreateProgram(); - glAttachShader(program, shVertex); - glAttachShader(program, shFragment); - glBindAttribLocation(program, 0, "position"); - glBindAttribLocation(program, 1, "color"); - glBindAttribLocation(program, 2, "mass"); - glBindFragDataLocation (program, 0, "vertex_color"); - glLinkProgram(program); - glDetachShader(program, shVertex); - glDetachShader(program, shFragment); -} - -void Render::init() { - createAndBindBuffer(); - createAndCompileShaders(); - createAndLinkProgram(); -} - -void Render::setupOpenGL() { - setupWindow(); - init(); -} - -bool Render::clearWindow() { - if(!glfwWindowShouldClose(this->window)) { - int wid, hei; - glfwGetFramebufferSize(this->window, &wid, &hei); - glViewport(0, 0, wid, hei); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - return false; - } - else { - destroyWindow(); - return true; - } -} - -bool Render::swapBuffers() { - if(!glfwWindowShouldClose(this->window)) { - glfwSwapBuffers(this->window); - glfwPollEvents(); - return false; - } - else { - destroyWindow(); - return true; - } -} - -void Render::destroyWindow() { - glfwDestroyWindow(this->window); - glfwTerminate(); -} - -void Render::render() { - glUseProgram(program); - glm::mat4 view = glm::lookAt( - glm::vec3( - camera_radius*sin(camera_theta), - camera_radius*cos(camera_theta)*cos(camera_phi), - camera_radius*cos(camera_theta)*sin(camera_phi) - ), // the position of your camera, in world space - glm::vec3(0, 0, 0), // where you want to look at, in world space - glm::vec3(0, 1, 0) // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too - ); - glm::mat4 projection = glm::perspective( - glm::radians(45.0f), // The vertical Field of View, in radians: the amount of "zoom". Think "camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in) - 1.0f*width/height, // Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ? - 0.1f, // Near clipping plane. Keep as big as possible, or you'll get precision issues. - 100.0f // Far clipping plane. Keep as little as possible. - ); - glm::mat4 mvp = projection * view; - GLuint MatrixID = glGetUniformLocation(program, "MVP"); - glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &mvp[0][0]); - - glBindVertexArray(vao); - - glBindBuffer(GL_ARRAY_BUFFER, buffer[0]); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*numberOfBodies, positionsToRender); - - glBindBuffer(GL_ARRAY_BUFFER, buffer[1]); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(char)*3*numberOfBodies, colorsToRender); - - glBindBuffer(GL_ARRAY_BUFFER, buffer[2]); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*numberOfBodies, massesToRender); - - - glDrawArrays(GL_POINTS, 0, numberOfBodies); - - glBindVertexArray(vao_cube); - glBindBuffer(GL_ARRAY_BUFFER, buffer_cube[0]); - - glDrawArrays(GL_LINES, 0, 24); -} - -bool Render::draw(thrust::host_vector& positions) { - for(unsigned i=0; i -#include -#include -#include -#include -#include -#include -#include // glm::vec3 -#include // glm::vec4 -#include // glm::mat4 -#include // glm::translate, glm::rotate, glm::scale, glm::perspective - -#include "gl.h" -#include "RandomGenerators.h" - -typedef thrust::host_vector tf3; - -class Render { -public: - Render(std::vector masses, unsigned numberOfBodies, float cubeSize); - ~Render(); - void createAndBindBuffer(); - void createAndCompileShaders(); - void createAndLinkProgram(); - void setupWindow(); - void init(); - void setupOpenGL(); - - bool clearWindow(); - void destroyWindow(); - bool swapBuffers(); - - static void mouse_pressed(); - static void mouse_released(); - static void mouse_scroll(double offset); - static void mouse_move(double xpos, double ypos); - - static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); - static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset); - static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods); - static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos); - - void render(); - - bool draw(thrust::host_vector& positions); - GLuint load_shader(const char* path, int shader_type); - float getTime(); -private: - static float camera_theta; - static float camera_phi; - static float camera_radius; - - static bool is_mouse_pressed; - static double mouse_position_x; - static double mouse_position_y; - - const int width = 1000; - const int height = 1000; - float last_time; - - char* colorsToRender; - float* positionsToRender; - float* massesToRender; - - float* cubeVertices; - - GLuint buffer[4]; - GLuint buffer_cube[1]; - GLuint vao; - GLuint vao_cube; - GLuint program, shFragment, shVertex; - GLFWwindow* window; - float cubeSize; - RandomGenerators* randomGenerator; - unsigned numberOfBodies; -}; - -#endif \ No newline at end of file diff --git a/SimulationCode/src/Simulation.cpp b/SimulationCode/src/Simulation.cpp index 54ac157..f4d0bdc 100644 --- a/SimulationCode/src/Simulation.cpp +++ b/SimulationCode/src/Simulation.cpp @@ -1,7 +1,8 @@ #include "Simulation.h" +#include -Simulation::Simulation(Render *rend, Step *step, unsigned numberOfBodies) - : rend(rend), step(step), numberOfBodies(numberOfBodies) { +Simulation::Simulation(Step *step, unsigned numberOfBodies) + : step(step), numberOfBodies(numberOfBodies) { randomGenerator = new RandomGenerators(); positions.reserve(3 * numberOfBodies); for (unsigned i = 0; i < numberOfBodies; i++) { @@ -16,24 +17,28 @@ Simulation::~Simulation() { delete randomGenerator; positions.clear(); delete step; - delete rend; } -void Simulation::MakeSimulation() { - rend->setupOpenGL(); - float last_time = rend->getTime(); - float curr_time; - +void Simulation::MakeSimulation(int rounds) { + typedef std::chrono::high_resolution_clock Time; + typedef std::chrono::duration fsec; + fsec fs; + auto last_time = Time::now(); + auto before_time = Time::now(); int count = 0; - float avgDt = 0.0; - int numberOfRounds = 10; - while(1) {//!rend->draw(positions)) { + int numberOfRounds = rounds; + while(1) { if(count >= numberOfRounds) break; - curr_time = rend->getTime(); - avgDt += (curr_time - last_time); - step->compute(positions, (curr_time - last_time)*3); + auto curr_time = Time::now(); + fs = curr_time - last_time; + float dt = fs.count(); + step->compute(positions, dt); last_time = curr_time; count++; } - std::cout << avgDt/numberOfRounds << std::endl; -} + auto after_time = Time::now(); + fsec timeInSec = after_time - before_time; + float avgDt = timeInSec.count(); + float res = avgDt/numberOfRounds; + std::cout << "(" << numberOfRounds << "," << res << ")" << std::endl; +} \ No newline at end of file diff --git a/SimulationCode/src/Simulation.h b/SimulationCode/src/Simulation.h index d639a3d..07d3969 100644 --- a/SimulationCode/src/Simulation.h +++ b/SimulationCode/src/Simulation.h @@ -8,20 +8,18 @@ #include #include "RandomGenerators.h" -#include "Render.h" #include "Step.h" class Simulation { - Render *rend; Step *step; unsigned numberOfBodies; thrust::host_vector positions; RandomGenerators *randomGenerator; public: - Simulation(Render *rend, Step *step, unsigned numberOfBodies); + Simulation(Step *step, unsigned numberOfBodies); ~Simulation(); - void MakeSimulation(); + void MakeSimulation(int rounds); }; #endif diff --git a/SimulationCode/src/gl.h b/SimulationCode/src/gl.h deleted file mode 100644 index 018a972..0000000 --- a/SimulationCode/src/gl.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WDGK_OPENGL_GL -#define WDGK_OPENGL_GL - -#define GL_GLEXT_PROTOTYPES 1 -#define GL3_PROTOTYPES 1 -#include - -#endif