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)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
find_package(Boost REQUIRED COMPONENTS program_options)
find_package(PNG REQUIRED)
find_package(OpenMP)
add_executable(dynamicsystems-cli cli.cpp compute.cpp picture.cpp)
add_library(dynamicsystems 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(OpenGL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${-lfltk_images} ${-lfltk_png}")
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
find_package(OpenMP)
if(OPENMP_CXX_FOUND)
target_link_libraries(dynamicsystems PRIVATE OpenMP::OpenMP_CXX)
endif()
add_executable(dynamicsystems-gui gui.cpp compute.cpp picture.cpp)
target_link_libraries(dynamicsystems-gui ${FLTK_LIBRARIES} ${OPENGL_LIBRARIES} ${PNG_LIBRARY})
add_executable(dynamicsystems-cli cli.cpp)
target_link_libraries(dynamicsystems-cli PRIVATE dynamicsystems)
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(FLTK_SKIP_OPENGL TRUE)
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()
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 (WIN32)
......
#include "compute.hpp"
#include <cassert>
#include <cmath>
#include <algorithm>
#include <chrono>
#include <fstream>
#include <iostream>
#include <string>
#include "picture.hpp"
float compute(float alpha, float beta, aligned_vector<float> seed_x,
aligned_vector<float> seed_y, int num_iterations,
constexpr float PI = 3.14159265358979323846264338327950288419716939f;
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) {
int num_seeds = seed_x.size();
assert(seed_y.size() == num_seeds);
......@@ -34,21 +46,10 @@ float compute(float alpha, float beta, aligned_vector<float> seed_x,
return d;
}
void compute_all(
int num_iterations,
float threshold,
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
) {
void compute_all(int num_iterations, float threshold, 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
int alpha_num_params = alpha_num_intervals + 1;
float alpha_interval_size = (alphamax - alphamin) / (alpha_num_intervals);
......@@ -69,18 +70,19 @@ void compute_all(
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;
aligned_vector<float> x_start(num_seedpoints);
aligned_vector<float> y_start(num_seedpoints);
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);
// y_start[i - 1] = 0;
x_start[i - 1] =
0.5f * static_cast<float>(i) / (num_seedpoints - seedpoints.size() + 1);
// y_start[i - 1] = 0;
std::cout << x_start[i - 1] << ", ";
}
for (int i = 0; i < seedpoints.size(); ++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 << '\n';
......@@ -90,7 +92,7 @@ void compute_all(
auto time_start = std::chrono::system_clock::now();
// Computation
// Computation
#pragma omp parallel for schedule(dynamic)
for (int b = beta_num_params - 1; b >= 0; b--) {
for (int a = 0; a < alpha_num_params; a++) {
......@@ -103,17 +105,17 @@ void compute_all(
std::chrono::duration<float>(time_end - time_start).count();
std::cout << "TIME for computation: " << elapsed_seconds << std::endl;
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();
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;
// Generate output
// Generate output
if (output_csv) {
time_start = std::chrono::system_clock::now();
// Output result into .csv
// Output result into .csv
std::string file_result = "result.csv";
std::ofstream ostrm_csv(file_result);
ostrm_csv << "alpha beta value\n";
......@@ -124,9 +126,9 @@ void compute_all(
<< '\n';
}
}
time_end = std::chrono::system_clock::now();
elapsed_seconds = std::chrono::duration<float>(time_end - time_start).count();
std::cout << "TIME for csv: " << elapsed_seconds << std::endl;
time_end = std::chrono::system_clock::now();
elapsed_seconds =
std::chrono::duration<float>(time_end - time_start).count();
std::cout << "TIME for csv: " << elapsed_seconds << std::endl;
}
}
#ifndef 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 <png.h>
#include "colormaps.hpp"
#include "picture.hpp"
#include <boost/align/aligned_allocator.hpp>
template <typename T>
using aligned_allocator = boost::alignment::aligned_allocator<T, 64>;
template <typename T>
using aligned_vector = std::vector<T, aligned_allocator<T>>;
constexpr float PI = 3.14159265358979323846264338327950288419716939f;
constexpr float TWO_PI = 2 * PI;
float compute(float alpha, float beta, aligned_vector<float> seed_x,
aligned_vector<float> seed_y, int num_iterations,
float compute(float alpha, float beta, const aligned_vector<float>& seed_x,
const aligned_vector<float>& seed_y, int num_iterations,
float threshold);
void compute_all(
int num_iterations,
float threshold,
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
);
void compute_all(int num_iterations, float threshold, 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);
#endif
#endif // COMPUTE_H
#include "picture.hpp"
#include <iostream>
#include <vector>
#include <png.h>
#include "colormaps.hpp"
// all functions for picture transformation and output:
// 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_rgb(3 * width * height);
......
#ifndef PICTURE_H
#define PICTURE_H
#include <boost/align/aligned_allocator.hpp>
#include <vector>
#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);
bool write_png(const char *filename, const float *result, float threshold,
int width, int height);
#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