From e1f7cbaa1d6914f9e1a78f73633c8b24e13ed11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Thu, 25 Oct 2018 23:00:26 +0200 Subject: [PATCH] Optimize color changing with OpenMP. --- CMakeLists.txt | 3 ++- src/cube.cpp | 1 + src/cube.hpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94ecca2..b8ecfd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ set(OpenGL_GL_PREFERENCE "GLVND") find_package(OpenGL REQUIRED) find_package(GLUT REQUIRED) find_package(GLEW REQUIRED) +find_package(OpenMP REQUIRED) find_package(PkgConfig REQUIRED) pkg_search_module(SDL2 REQUIRED sdl2) @@ -54,7 +55,7 @@ set(SRCS "src/simulation.cpp") # Define C++ compiler flags -set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wpedantic -Wfatal-errors -Werror -pedantic-errors -fno-elide-constructors") +set(CMAKE_CXX_FLAGS "-std=c++11 ${OpenMP_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wfatal-errors -Werror -pedantic-errors -fno-elide-constructors") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(CMAKE_CXX_FLAGS_RELEASE "-O3") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3") diff --git a/src/cube.cpp b/src/cube.cpp index 8bc6860..68ea0ae 100644 --- a/src/cube.cpp +++ b/src/cube.cpp @@ -84,6 +84,7 @@ void cube::render() { } void cube::shift_colors() { + #pragma omp parallel for for(size_t i = 0; i < colors.size(); ++i) { colors[i] += color_ascending[i] ? color_shift : diff --git a/src/cube.hpp b/src/cube.hpp index eb54c48..316226a 100644 --- a/src/cube.hpp +++ b/src/cube.hpp @@ -36,7 +36,7 @@ public: void render(); private: - const float color_shift = 0.0001; + const float color_shift = 0.005; void shift_colors(); // OpenGL buffers