Skip to content
Snippets Groups Projects
Commit a1f0523d authored by CHAMONT David's avatar CHAMONT David
Browse files

Ajout d'une solution sequentielle.

parent e6a34bb8
No related branches found
No related tags found
No related merge requests found
# 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)
#!/bin/bash
clear
rm -rf build
mkdir -p build
cd build
cmake ..
#!/bin/bash
clear
cd build
make all
#!/bin/bash
time ./build/main.exe 1080 1920 5 100
echo
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}")
#include <vector>
#include <iostream>
#include <iomanip>
#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 };
void drop( std::vector<float> & data, std::size_t nb_rows, std::size_t nb_cols, float value ) {
const std::size_t center_row { nb_rows/2ul };
const std::size_t center_col { nb_cols/2ul };
for (std::size_t r = (center_row-2ul) ; r < (center_row+2ul); r++) {
for (std::size_t c = (center_col-3ul); c < (center_col+3ul); c++) {
data[r*nb_cols+c] = value ;
}
}
}
void process(
std::vector<float> const & iu, std::vector<float> const & iv,
std::vector<float> & ou, std::vector<float> & 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;
float full_u = 0.0f;
float 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;
full_v += iv[(r+k)*nb_cols+c+l] - v;
}
}
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;
ou[(r+1)*nb_cols+c+1] = u + du*DT;
ov[(r+1)*nb_cols+c+1] = v + dv*DT;
}
}
}
int main( int argc, char * argv[] ) {
// runtime parameters
assert(argc==5) ;
std::size_t nb_rows {std::stoul(argv[1])} ;
std::size_t nb_cols {std::stoul(argv[2])} ;
std::size_t nb_images {std::stoul(argv[3])} ;
std::size_t nb_iterations {std::stoul(argv[4])} ;
assert(nb_iterations % 2 == 0); // nb_iterations must be even
std::cout << std::fixed << std::setprecision(6) << std::endl;
try {
// Initialize input data
const std::size_t padded_nb_rows { nb_rows+2 };
const std::size_t padded_nb_cols { nb_cols+2 };
const std::size_t size { padded_nb_rows*padded_nb_cols };
std::vector<float> u1(size,1.f);
std::vector<float> v1(size,0.f);
std::vector<float> u2(size,1.f);
std::vector<float> v2(size,0.f);
drop(u1, padded_nb_rows, padded_nb_cols, 0.f);
drop(v1, padded_nb_rows, padded_nb_cols, 1.f);
// iterations
std::cout<<"\nCheckpoints: ";
for ( std::size_t image = 0 ; image < nb_images ; ++image ) {
for ( std::size_t iter = 0 ; iter < nb_iterations ; iter += 2 ) {
process( u1, v1, u2, v2, padded_nb_rows, padded_nb_cols );
process( u2, v2, u1, v1, padded_nb_rows, padded_nb_cols );
}
std::cout<< std::accumulate(u1.begin(),u1.end(),0.f)/size << " ";
}
std::cout << std::endl;
}
catch (std::exception & e) {
std::cout << e.what() << std::endl;
}
catch (const char * e) {
std::cout << e << std::endl;
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment