diff --git a/GrayScott/CMakeLists.txt b/GrayScott/CMakeLists.txt deleted file mode 100755 index c07f2f8241471945d24cb0c03e229b90916c8373..0000000000000000000000000000000000000000 --- a/GrayScott/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# Direct CMake to use icpx rather than the default C++ compiler/linker -set(CMAKE_CXX_COMPILER icpx) - -cmake_minimum_required (VERSION 3.4) - -project(GrayScottBuffer CXX) - -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) - -add_subdirectory (src) diff --git a/GrayScott/build/GNUmakefile b/GrayScott/build/GNUmakefile new file mode 100644 index 0000000000000000000000000000000000000000..b2fe1224947acb648bfb3a622bd86ff6285b0659 --- /dev/null +++ b/GrayScott/build/GNUmakefile @@ -0,0 +1,11 @@ + +SHELL = /bin/bash + +all: main.exe + +clean: + rm -f *.exe + +%.exe: ../src/%.cpp + @rm -f $@ + g++ -std=c++20 -O2 -Wall -Wextra -Wfloat-equal -o $@ $^ -lcadnaC diff --git a/GrayScott/cmake.bash b/GrayScott/cmake.bash deleted file mode 100755 index 0e74b590ae0cbb8075261922d1d3e8d32e98d23a..0000000000000000000000000000000000000000 --- a/GrayScott/cmake.bash +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -clear -rm -rf build -mkdir -p build -cd build -cmake .. diff --git a/GrayScott/run.bash b/GrayScott/run.bash index 755bf35e558c21c2b5fc6c76e42ea702a6c6e757..454a77d8d25b951dc09bdb32acc9ddcabab68742 100755 --- a/GrayScott/run.bash +++ b/GrayScott/run.bash @@ -1,3 +1,3 @@ #!/bin/bash -time ./build/main.exe 1080 1920 5 100 +time ./build/main.exe 1080 1920 50 10 echo diff --git a/GrayScott/src/CMakeLists.txt b/GrayScott/src/CMakeLists.txt deleted file mode 100755 index 56f4225eac97f67d8ecd00b4fc960174419938f9..0000000000000000000000000000000000000000 --- a/GrayScott/src/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -set(SOURCE_FILE main.cpp) -set(TARGET_NAME main.exe) - -set(COMPILE_FLAGS "-Wall") - -add_executable(${TARGET_NAME} ${SOURCE_FILE}) -set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS}") diff --git a/GrayScott/src/main.cpp b/GrayScott/src/main.cpp index 1a7528c336873b7dd6377b0a9adb62cc1233c7ac..b50415d7fc0b483c02f8baf0970ae895825343ed 100644 --- a/GrayScott/src/main.cpp +++ b/GrayScott/src/main.cpp @@ -4,14 +4,18 @@ #include <cassert> #include <numeric> -constexpr float KILL_RATE { 0.062f }; -constexpr float FEED_RATE { 0.03f }; -constexpr float DT { 1.0f }; -constexpr float DIFFUSION_RATE_U { 0.1f }; -constexpr float DIFFUSION_RATE_V { 0.05f }; +#include <cadna.h> + +using real = double_st ; + +const real KILL_RATE { 0.062f }; +const real FEED_RATE { 0.03f }; +const real DT { 1.0f }; +const real DIFFUSION_RATE_U { 0.1f }; +const real DIFFUSION_RATE_V { 0.05f }; template<typename Collection> -void drop( Collection & data, std::size_t nb_rows, std::size_t nb_cols, float value ) { +void drop( Collection & data, std::size_t nb_rows, std::size_t nb_cols, real value ) { const std::size_t center_row { nb_rows/2ul }; const std::size_t center_col { nb_cols/2ul }; @@ -24,19 +28,19 @@ void drop( Collection & data, std::size_t nb_rows, std::size_t nb_cols, float va } void process( - std::vector<float> const & iu, std::vector<float> const & iv, - std::vector<float> & ou, std::vector<float> & ov, + std::vector<real> const & iu, std::vector<real> const & iv, + std::vector<real> & ou, std::vector<real> & ov, std::size_t nb_rows, std::size_t nb_cols ) { for (std::size_t r = 0 ; r < (nb_rows-2); r++) { for (std::size_t c = 0; c < (nb_cols-2); c++) { - float u = iu[(r+1)*nb_cols+c+1]; - float v = iv[(r+1)*nb_cols+c+1]; - float uvv = u*v*v; + real u = iu[(r+1)*nb_cols+c+1]; + real v = iv[(r+1)*nb_cols+c+1]; + real uvv = u*v*v; - float full_u = 0.0f; - float full_v = 0.0f; + real full_u = 0.0f; + real full_v = 0.0f; for(std::size_t k = 0ul; k < 3ul; ++k){ for(std::size_t l = 0ul; l < 3ul; ++l){ full_u += iu[(r+k)*nb_cols+c+l] - u; @@ -44,8 +48,8 @@ void process( } } - float du = DIFFUSION_RATE_U*full_u - uvv + FEED_RATE*(1.0f - u); - float dv = DIFFUSION_RATE_V*full_v + uvv - (FEED_RATE + KILL_RATE)*v; + real du = DIFFUSION_RATE_U*full_u - uvv + FEED_RATE*(1.0f - u); + real dv = DIFFUSION_RATE_V*full_v + uvv - (FEED_RATE + KILL_RATE)*v; ou[(r+1)*nb_cols+c+1] = u + du*DT; ov[(r+1)*nb_cols+c+1] = v + dv*DT; @@ -63,19 +67,21 @@ int main( int argc, char * argv[] ) { std::size_t nb_images {std::stoul(argv[3])}; std::size_t nb_iterations {std::stoul(argv[4])}; std::cout << std::fixed << std::setprecision(6); + std::cout << std::endl; + cadna_init(-1); try { // Temporary work images - std::vector<float> u1(nb_rows*nb_cols,1.f); - std::vector<float> v1(nb_rows*nb_cols,0.f); - std::vector<float> u2(nb_rows*nb_cols,1.f); - std::vector<float> v2(nb_rows*nb_cols,0.f); + std::vector<real> u1(nb_rows*nb_cols,1.f); + std::vector<real> v1(nb_rows*nb_cols,0.f); + std::vector<real> u2(nb_rows*nb_cols,1.f); + std::vector<real> v2(nb_rows*nb_cols,0.f); drop(u1, nb_rows, nb_cols, 0.f); drop(v1, nb_rows, nb_cols, 1.f); // Final images sequence - std::vector<std::vector<float>> images; + std::vector<std::vector<real>> images; images.push_back(u1); // Iterations @@ -85,12 +91,19 @@ int main( int argc, char * argv[] ) { process( u1, v1, u2, v2, nb_rows, nb_cols ); std::swap(u1,u2) ; std::swap (v1,v2) ; } - float flag = std::inner_product(u1.begin(), u1.end(), v1.begin(),0.f); - std::cout << flag << ' ' << std::flush; + std::cout << '.' << std::flush; images.push_back(u1); } std::cout << std::endl; + // Final product + std::cout << std::endl; + real product = std::inner_product(u1.begin(), u1.end(), v1.begin(),0.f); + std::cout + << "product : " << product + << ", with " << product.nb_significant_digit() << " significant digits" + << std::endl; + } catch (std::exception & e) { std::cout << e.what() << std::endl; @@ -100,5 +113,7 @@ int main( int argc, char * argv[] ) { } // End + std::cout << std::endl; + cadna_end(); return 0; }