Commit b604ddd8 authored by Lars Kuehne's avatar Lars Kuehne

clean up

parent 05a6d497
cmake_minimum_required(VERSION 3.1.3) cmake_minimum_required(VERSION 3.9.6)
project(dynamicsystems LANGUAGES CXX) project(dynamicsystems LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11) find_package(Boost REQUIRED COMPONENTS program_options)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE) find_package(PNG REQUIRED)
find_package(OpenMP) add_library(dynamicsystems compute.cpp picture.cpp)
add_executable(dynamicsystems-cli cli.cpp compute.cpp picture.cpp) target_link_libraries(dynamicsystems PRIVATE PNG::PNG Boost::boost)
target_link_libraries(dynamicsystems PUBLIC Boost::boost)
target_compile_features(dynamicsystems PUBLIC cxx_std_11)
find_package(FLTK) find_package(OpenMP)
find_package(OpenGL) if(OPENMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${-lfltk_images} ${-lfltk_png}") target_link_libraries(dynamicsystems PRIVATE OpenMP::OpenMP_CXX)
find_package(PNG REQUIRED) endif()
include_directories(${PNG_INCLUDE_DIR})
add_executable(dynamicsystems-gui gui.cpp compute.cpp picture.cpp) add_executable(dynamicsystems-cli cli.cpp)
target_link_libraries(dynamicsystems-gui ${FLTK_LIBRARIES} ${OPENGL_LIBRARIES} ${PNG_LIBRARY}) target_link_libraries(dynamicsystems-cli PRIVATE dynamicsystems)
if(OPENMP_FOUND) set(FLTK_SKIP_OPENGL TRUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") set(FLTK_SKIP_FLUID TRUE)
find_package(FLTK)
if(FLTK_FOUND)
add_executable(dynamicsystems-gui gui.cpp)
target_link_libraries(dynamicsystems-gui PRIVATE dynamicsystems)
target_include_directories(dynamicsystems-gui PRIVATE ${FLTK_INCLUDE_DIR})
target_link_libraries(dynamicsystems-gui PRIVATE ${FLTK_LIBRARIES})
endif() endif()
find_package(Boost REQUIRED COMPONENTS program_options)
target_include_directories(dynamicsystems-cli PRIVATE ${Boost_INCLUDE_DIR})
target_link_libraries(dynamicsystems-cli PRIVATE ${PNG_LIBRARY} ${Boost_LIBRARIES})
target_link_libraries(dynamicsystems-cli PRIVATE Boost::program_options
Boost::disable_autolinking
Boost::dynamic_linking)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
if (WIN32) if (WIN32)
......
#include "compute.hpp" #include "compute.hpp"
#include <cassert>
#include <cmath>
#include <algorithm> #include <algorithm>
#include <chrono>
#include <fstream>
#include <iostream>
#include <string>
#include "picture.hpp"
float compute(float alpha, float beta, aligned_vector<float> seed_x, constexpr float PI = 3.14159265358979323846264338327950288419716939f;
aligned_vector<float> seed_y, int num_iterations, constexpr float TWO_PI = 2 * PI;
float compute(float alpha, float beta, const aligned_vector<float>& seed_x,
const aligned_vector<float>& seed_y, int num_iterations,
float threshold) { float threshold) {
int num_seeds = seed_x.size(); int num_seeds = seed_x.size();
assert(seed_y.size() == num_seeds); assert(seed_y.size() == num_seeds);
...@@ -34,21 +46,10 @@ float compute(float alpha, float beta, aligned_vector<float> seed_x, ...@@ -34,21 +46,10 @@ float compute(float alpha, float beta, aligned_vector<float> seed_x,
return d; return d;
} }
void compute_all(int num_iterations, float threshold, float alphamin,
void compute_all( float alphamax, int alpha_num_intervals, float betamin,
int num_iterations, float betamax, int beta_num_intervals, int num_seedpoints,
float threshold, bool output_csv, std::vector<float> seedpoints) {
float alphamin,
float alphamax,
int alpha_num_intervals,
float betamin,
float betamax,
int beta_num_intervals,
int num_seedpoints,
bool output_csv,
std::vector<float> seedpoints
) {
// these are computed // these are computed
int alpha_num_params = alpha_num_intervals + 1; int alpha_num_params = alpha_num_intervals + 1;
float alpha_interval_size = (alphamax - alphamin) / (alpha_num_intervals); float alpha_interval_size = (alphamax - alphamin) / (alpha_num_intervals);
...@@ -69,18 +70,19 @@ void compute_all( ...@@ -69,18 +70,19 @@ void compute_all(
betasp[i] = betamin + i * beta_interval_size; betasp[i] = betamin + i * beta_interval_size;
} }
// Initialization and output of seedpoints // Initialization and output of seedpoints
std::cout << "Following seedpoints are used for computation:" << std::endl; std::cout << "Following seedpoints are used for computation:" << std::endl;
aligned_vector<float> x_start(num_seedpoints); aligned_vector<float> x_start(num_seedpoints);
aligned_vector<float> y_start(num_seedpoints); aligned_vector<float> y_start(num_seedpoints);
for (int i = 1; i < num_seedpoints - seedpoints.size() + 1; ++i) { for (int i = 1; i < num_seedpoints - seedpoints.size() + 1; ++i) {
x_start[i - 1] = 0.5f * static_cast<float>(i) / (num_seedpoints - seedpoints.size() + 1); x_start[i - 1] =
// y_start[i - 1] = 0; 0.5f * static_cast<float>(i) / (num_seedpoints - seedpoints.size() + 1);
// y_start[i - 1] = 0;
std::cout << x_start[i - 1] << ", "; std::cout << x_start[i - 1] << ", ";
} }
for (int i = 0; i < seedpoints.size(); ++i) { for (int i = 0; i < seedpoints.size(); ++i) {
x_start[num_seedpoints - seedpoints.size() + i] = seedpoints[i]; x_start[num_seedpoints - seedpoints.size() + i] = seedpoints[i];
// y_start[num_seedpoints - seedpoints.size() + i] = 0; // y_start[num_seedpoints - seedpoints.size() + i] = 0;
std::cout << x_start[num_seedpoints - seedpoints.size() + i] << ", "; std::cout << x_start[num_seedpoints - seedpoints.size() + i] << ", ";
} }
std::cout << '\n'; std::cout << '\n';
...@@ -90,7 +92,7 @@ void compute_all( ...@@ -90,7 +92,7 @@ void compute_all(
auto time_start = std::chrono::system_clock::now(); auto time_start = std::chrono::system_clock::now();
// Computation // Computation
#pragma omp parallel for schedule(dynamic) #pragma omp parallel for schedule(dynamic)
for (int b = beta_num_params - 1; b >= 0; b--) { for (int b = beta_num_params - 1; b >= 0; b--) {
for (int a = 0; a < alpha_num_params; a++) { for (int a = 0; a < alpha_num_params; a++) {
...@@ -103,17 +105,17 @@ void compute_all( ...@@ -103,17 +105,17 @@ void compute_all(
std::chrono::duration<float>(time_end - time_start).count(); std::chrono::duration<float>(time_end - time_start).count();
std::cout << "TIME for computation: " << elapsed_seconds << std::endl; std::cout << "TIME for computation: " << elapsed_seconds << std::endl;
time_start = std::chrono::system_clock::now(); time_start = std::chrono::system_clock::now();
write_png("picture.png", result.data(), threshold, alpha_num_params, beta_num_params); write_png("picture.png", result.data(), threshold, alpha_num_params,
beta_num_params);
time_end = std::chrono::system_clock::now(); time_end = std::chrono::system_clock::now();
elapsed_seconds = std::chrono::duration<float>(time_end - time_start).count(); elapsed_seconds = std::chrono::duration<float>(time_end - time_start).count();
std::cout << "TIME for picture: " << elapsed_seconds << std::endl; std::cout << "TIME for picture: " << elapsed_seconds << std::endl;
// Generate output // Generate output
if (output_csv) { if (output_csv) {
time_start = std::chrono::system_clock::now(); time_start = std::chrono::system_clock::now();
// Output result into .csv // Output result into .csv
std::string file_result = "result.csv"; std::string file_result = "result.csv";
std::ofstream ostrm_csv(file_result); std::ofstream ostrm_csv(file_result);
ostrm_csv << "alpha beta value\n"; ostrm_csv << "alpha beta value\n";
...@@ -124,9 +126,9 @@ void compute_all( ...@@ -124,9 +126,9 @@ void compute_all(
<< '\n'; << '\n';
} }
} }
time_end = std::chrono::system_clock::now(); time_end = std::chrono::system_clock::now();
elapsed_seconds = std::chrono::duration<float>(time_end - time_start).count(); elapsed_seconds =
std::cout << "TIME for csv: " << elapsed_seconds << std::endl; std::chrono::duration<float>(time_end - time_start).count();
std::cout << "TIME for csv: " << elapsed_seconds << std::endl;
} }
} }
#ifndef COMPUTE_H #ifndef COMPUTE_H
#define COMPUTE_H #define COMPUTE_H
#include <boost/align/aligned_allocator.hpp>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <random>
#include <sstream>
#include <vector> #include <vector>
#include <png.h> #include <boost/align/aligned_allocator.hpp>
#include "colormaps.hpp"
#include "picture.hpp"
template <typename T> template <typename T>
using aligned_allocator = boost::alignment::aligned_allocator<T, 64>; using aligned_allocator = boost::alignment::aligned_allocator<T, 64>;
template <typename T> template <typename T>
using aligned_vector = std::vector<T, aligned_allocator<T>>; using aligned_vector = std::vector<T, aligned_allocator<T>>;
constexpr float PI = 3.14159265358979323846264338327950288419716939f; float compute(float alpha, float beta, const aligned_vector<float>& seed_x,
constexpr float TWO_PI = 2 * PI; const aligned_vector<float>& seed_y, int num_iterations,
float compute(float alpha, float beta, aligned_vector<float> seed_x,
aligned_vector<float> seed_y, int num_iterations,
float threshold); float threshold);
void compute_all( void compute_all(int num_iterations, float threshold, float alphamin,
int num_iterations, float alphamax, int alpha_num_intervals, float betamin,
float threshold, float betamax, int beta_num_intervals, int num_seedpoints,
float alphamin, bool output_csv, std::vector<float> seedpoints);
float alphamax,
int alpha_num_intervals,
float betamin,
float betamax,
int beta_num_intervals,
int num_seedpoints,
bool output_csv,
std::vector<float> seedpoints
);
#endif #endif // COMPUTE_H
#include "picture.hpp" #include "picture.hpp"
#include <iostream>
#include <vector>
#include <png.h>
#include "colormaps.hpp"
// all functions for picture transformation and output: // all functions for picture transformation and output:
// function: map result to color vector // function: map result to color vector
bool write_png(const char * filename, const float *result, float threshold, int width, int height) { bool write_png(const char *filename, const float *result, float threshold,
int width, int height) {
std::vector<unsigned char> colors_gray(width * height); std::vector<unsigned char> colors_gray(width * height);
std::vector<unsigned char> colors_rgb(3 * width * height); std::vector<unsigned char> colors_rgb(3 * width * height);
......
#ifndef PICTURE_H #ifndef PICTURE_H
#define PICTURE_H #define PICTURE_H
#include <boost/align/aligned_allocator.hpp> bool write_png(const char *filename, const float *result, float threshold,
#include <vector> int width, int height);
#include <cmath>
#include <iostream>
#include <cstring>
#include <png.h>
#include "colormaps.hpp"
bool write_png(const char * filename, const float *result, float threshold, int width, int height);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment