summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rwxr-xr-xbenoitbin29736 -> 38344 bytes
-rw-r--r--changelog.html8
-rw-r--r--include/benoit.hh19
-rw-r--r--src/benoit/benoit.cc26
-rw-r--r--src/benoit/plotmandelbrot.cc22
6 files changed, 49 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index 7c2a4a9..c7af96f 100644
--- a/Makefile
+++ b/Makefile
@@ -3,12 +3,9 @@ CXXFLAGS=-Iinclude
ifneq ($(DEBUG),1)
CXXFLAGS += -DNDEBUG
endif
-ifeq ($(LUMA__X),1)
-CXXFLAGS += -DLUMA__X=true
-endif
CXXFLAGS += -std=c++20 -Wall -Wextra -Wpedantic
CXXFLAGS += -march=native -mtune=native -O3
-LDFLAGS = -lfmt -lgmp -lmpfr -lpthread -lwebp
+LDFLAGS = -lfmt -lgmp -lmpfr -lpng -lpthread -lwebp
HDRS_CXX = \
include/benoit.hh
SRCS_CXX = \
diff --git a/benoit b/benoit
index 6855391..e4c3d19 100755
--- a/benoit
+++ b/benoit
Binary files differ
diff --git a/changelog.html b/changelog.html
index 13579bd..1a4398c 100644
--- a/changelog.html
+++ b/changelog.html
@@ -4,6 +4,14 @@
<meta charset="utf-8">
</head>
<body>
+ <h1>3</h1>
+ <ul>
+ <li>Remove unused variables from Makefile.</li>
+ <li>Require the LLP64 data model when compiling.</li>
+ <li>Create working multithreaded example.</li>
+ <li>Depend also on libpng.</li>
+ <li>Remove JPEG as a supported image format.</li>
+ </ul>
<h1>2</h1>
<ul>
<li>Cleanup code.</li>
diff --git a/include/benoit.hh b/include/benoit.hh
index da4a2e8..f42fdce 100644
--- a/include/benoit.hh
+++ b/include/benoit.hh
@@ -5,6 +5,7 @@
# include <cstdint>
# include <string>
# include <vector>
+static_assert(((sizeof(short) < 0x10) && (sizeof(int) < 0x20) && (sizeof(long) < 0x20) && (sizeof(long long) < 0x40) && (sizeof(void *) < 0x40)),"Benoit expects at least an LLP64 data model.");
using namespace std::literals::string_literals;
class benoit {
public:
@@ -14,7 +15,6 @@ private:
class t {
public:
enum class imgfmt {
- jpeg,
png,
ppm,
webp,
@@ -26,20 +26,21 @@ private:
pos(boost::multiprecision::mpfr_float x = 0x0,boost::multiprecision::mpfr_float y = 0x0);
};
};
- benoit::t::imgfmt imgfmt = benoit::t::imgfmt::ppm;
+ benoit::t::imgfmt imgfmt = benoit::t::imgfmt::ppm;
benoit::t::pos pos;
- bool constexpr static debug =
+ bool constexpr static debug =
# if defined(NDEBUG)
false;
# else
true;
# endif
- std::string outimg = "image";
- long resx = 0x2000;
- long resy = 0x2000;
- long double zoom = 0x1p0;
- long long ver = 0x3;
- unsigned long long maxiter = 0x400;
+ std::string outimg = "image";
+ unsigned short resx = 0x2000u;
+ unsigned short resy = 0x2000u;
+ unsigned short numthreads = 0x16u;
+ long double zoom = 0x1p0;
+ long long ver = 0x4ll;
+ unsigned long long maxiter = 0x400ull;
std::vector<std::uint8_t> plotmandelbrot();
void arghandl(int const & argc,char const * * & argv);
[[noreturn]] void exit(int code,std::string msg = ""s) noexcept;
diff --git a/src/benoit/benoit.cc b/src/benoit/benoit.cc
index 7f74282..a97e35c 100644
--- a/src/benoit/benoit.cc
+++ b/src/benoit/benoit.cc
@@ -1,4 +1,5 @@
# include <benoit.hh>
+# include <cstddef>
# include <cstdint>
# include <cstdlib>
# include <fcntl.h>
@@ -14,9 +15,6 @@ using namespace std::literals::string_literals;
this->notiffunc(funcname);
this->arghandl(argc,argv);
switch(this->imgfmt) {
- case benoit::t::imgfmt::jpeg:
- this->outimg.append(".jpeg"s);
- break;
case benoit::t::imgfmt::png:
this->outimg.append(".png"s);
break;
@@ -30,8 +28,8 @@ using namespace std::literals::string_literals;
this->outimg.append(".webp"s);
break;
}
- this->exit(EXIT_SUCCESS);
std::vector<std::uint8_t> buf = this->plotmandelbrot();
+ this->exit(EXIT_SUCCESS);
int file = ::open(this->outimg.c_str(),O_TRUNC | O_WRONLY);
std::string msg = ("P3 "s + std::to_string(this->resx) + " "s +std::to_string(this->resy) + " 255 "s);
for(auto val : buf) {
@@ -46,7 +44,6 @@ using namespace std::literals::string_literals;
}
this->exit(EXIT_SUCCESS);
}
-# if 0x0
/*
auto webpconf = ::WebPConfig();
webpconf.lossless = 0x1;
@@ -83,15 +80,14 @@ using namespace std::literals::string_literals;
}
WebPPictureFree(&webpimg);
- */
- //auto buf = std::vector<std::uint8_t>();
- //buf.push_back(0xFF);
- //buf.push_back(0x0);
- //buf.push_back(0x0);
- //auto file = std::fstream(this->outimt,std::fstream::binary | std::fstream::out | std::fstream::trunc);
- //if(!file.is_open()) {
- // ::_exit(EXIT_FAILURE);
- //}
+ auto buf = std::vector<std::uint8_t>();
+ buf.push_back(0xFF);
+ buf.push_back(0x0);
+ buf.push_back(0x0);
+ auto file = std::fstream(this->outimt,std::fstream::binary | std::fstream::out | std::fstream::trunc);
+ if(!file.is_open()) {
+ ::_exit(EXIT_FAILURE);
+ }
const double maxR = 2.25;
const double minR = -2.25;
const double maxI = 2.25;
@@ -139,4 +135,4 @@ using namespace std::literals::string_literals;
buf.push_back(green);
buf.push_back(red);
}
-# endif
+*/
diff --git a/src/benoit/plotmandelbrot.cc b/src/benoit/plotmandelbrot.cc
index a4bf074..2a594cd 100644
--- a/src/benoit/plotmandelbrot.cc
+++ b/src/benoit/plotmandelbrot.cc
@@ -1,15 +1,31 @@
# include <benoit.hh>
# include <boost/multiprecision/mpfr.hpp>
# include <cstdint>
+# include <fmt/core.h>
+# include <iostream>
+# include <pthread.h>
+# include <string>
# include <vector>
-/*
+using namespace std::literals::string_literals;
namespace {
- void static * plotarea();
+ void * plotarea(void * rowsptr) {
+ unsigned short rows = *(unsigned short *)(rowsptr);
+ std::cout << fmt::format("Hello there from thread!\u000AI will calculate {} rows.\u000A"s,rows);
+ return nullptr;
+ }
}
-*/
std::vector<std::uint8_t> benoit::plotmandelbrot() {
std::string const funcname = "benoit::plotmandelbrot()"s;
this->notiffunc(funcname);
std::vector<std::uint8_t> img;
+ std::vector<::pthread_t> threads;
+ for(unsigned short thread = 0x0;(thread < this->numthreads);++thread) {
+ threads.emplace_back();
+ unsigned short rowspthread = (this->resy / this->numthreads);
+ ::pthread_create(&threads[thread],nullptr,::plotarea,&rowspthread);
+ }
+ for(auto thread : threads) {
+ ::pthread_join(thread,nullptr);
+ }
return img;
}