Changed for loop in stencil.hpp to double loop, changed main script structure
This commit is contained in:
145
main.cpp
145
main.cpp
@ -1,4 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
@ -24,13 +25,6 @@
|
||||
using namespace std;
|
||||
using namespace ff;
|
||||
|
||||
char *getOption(char **begin, char **end, const std::string &option) {
|
||||
char **itr = std::find(begin, end, option);
|
||||
if (itr != end && ++itr != end)
|
||||
return *itr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
long long int fastflow(vector<string> images,
|
||||
vector<pair<int, int>> neighborhood, int iterations,
|
||||
std::function<char(std::vector<char>)> f,
|
||||
@ -176,15 +170,19 @@ char gameOfLife(vector<char> in) {
|
||||
// -----------------------------------------------------------------------------
|
||||
int main(int argc, char *argv[]) {
|
||||
int average_max = 5;
|
||||
int iter_for_num_workers = 128;
|
||||
|
||||
vector<string> images = {
|
||||
int iter_for_num_workers_images1 = 128;
|
||||
vector<string> images1 = {
|
||||
"../tests/empty2x2",
|
||||
"../tests/increasing4x6",
|
||||
"../tests/increasing300x200",
|
||||
"../tests/random400x2500",
|
||||
// "../tests/equation",
|
||||
// "../tests/equation2"
|
||||
"../tests/random400x2500"
|
||||
};
|
||||
|
||||
int iter_for_num_workers_images2 = 8;
|
||||
vector<string> images2 = {
|
||||
"../tests/equation",
|
||||
"../tests/equation2"
|
||||
};
|
||||
|
||||
vector<pair<int, int>> neig = {make_pair(-1, 1), make_pair(-1, 0),
|
||||
@ -195,7 +193,7 @@ int main(int argc, char *argv[]) {
|
||||
ofstream csvfile;
|
||||
csvfile.open("performance.csv");
|
||||
|
||||
for (std::string image : images) {
|
||||
for (std::string image : images1) {
|
||||
cout << endl
|
||||
<< "\033[1;31mProcessing: \t" << image << "\033[0m" << endl;
|
||||
|
||||
@ -204,39 +202,37 @@ int main(int argc, char *argv[]) {
|
||||
csvfile << std::filesystem::file_size(image) << "\n";
|
||||
|
||||
csvfile << "\n";
|
||||
csvfile << "Number of iterations,1,2,4,8,16\n";
|
||||
csvfile << "Number of iterations,1,2,4,8,16,32\n";
|
||||
csvfile << "fastflow:,";
|
||||
|
||||
cout << "\033[1;31mFastflow\033[0m" << endl;
|
||||
for (int iterations : {1, 2, 4, 8, 16}) {
|
||||
for (int iterations : {1, 2, 4, 8, 16, 32}) {
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(
|
||||
fastflow({image}, neig, iterations, &gameOfLife, 0));
|
||||
}
|
||||
csvfile << std::accumulate(results.begin(), results.end(), 0) /
|
||||
average_max
|
||||
csvfile << *std::min_element(results.begin(), results.end())
|
||||
<< ",";
|
||||
}
|
||||
csvfile << "\n";
|
||||
|
||||
csvfile << "stdthread:,";
|
||||
cout << "\033[1;31mStdthread\033[0m" << endl;
|
||||
for (int iterations : {1, 2, 4, 8, 16}) {
|
||||
for (int iterations : {1, 2, 4, 8, 16, 32}) {
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(
|
||||
stdthreads({image}, neig, iterations, &gameOfLife, 0));
|
||||
}
|
||||
csvfile << std::accumulate(results.begin(), results.end(), 0) /
|
||||
average_max
|
||||
csvfile << *std::min_element(results.begin(), results.end())
|
||||
<< ",";
|
||||
}
|
||||
csvfile << "\n";
|
||||
|
||||
// ------------------------------------------------------------------ //
|
||||
csvfile << "Number of Workers,sequential,fastflow,stdthreads,";
|
||||
csvfile << "Iterations:," << iter_for_num_workers << "\n";
|
||||
csvfile << "Iterations:," << iter_for_num_workers_images1 << "\n";
|
||||
cout << "\033[1;31mDifferent number of workers\033[0m" << endl;
|
||||
|
||||
int hardware_concurrency = std::thread::hardware_concurrency();
|
||||
@ -255,10 +251,9 @@ int main(int argc, char *argv[]) {
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(sequential(
|
||||
{image}, neig, iter_for_num_workers, &gameOfLife));
|
||||
{image}, neig, iter_for_num_workers_images1, &gameOfLife));
|
||||
}
|
||||
csvfile << std::accumulate(results.begin(), results.end(), 0) /
|
||||
average_max;
|
||||
csvfile << *std::min_element(results.begin(), results.end());
|
||||
}
|
||||
csvfile << ",";
|
||||
|
||||
@ -268,11 +263,10 @@ int main(int argc, char *argv[]) {
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(fastflow({image}, neig,
|
||||
iter_for_num_workers,
|
||||
iter_for_num_workers_images1,
|
||||
&gameOfLife, max_workers));
|
||||
}
|
||||
csvfile << std::accumulate(results.begin(), results.end(), 0) /
|
||||
average_max;
|
||||
csvfile << *std::min_element(results.begin(), results.end());
|
||||
}
|
||||
csvfile << ",";
|
||||
|
||||
@ -282,11 +276,102 @@ int main(int argc, char *argv[]) {
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(stdthreads({image}, neig,
|
||||
iter_for_num_workers,
|
||||
iter_for_num_workers_images1,
|
||||
&gameOfLife, max_workers));
|
||||
}
|
||||
csvfile << std::accumulate(results.begin(), results.end(), 0) /
|
||||
average_max;
|
||||
csvfile << *std::min_element(results.begin(), results.end());
|
||||
}
|
||||
csvfile << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
for (std::string image : images2) {
|
||||
cout << endl
|
||||
<< "\033[1;31mProcessing: \t" << image << "\033[0m" << endl;
|
||||
|
||||
csvfile << ",Name,Size(B)\n";
|
||||
csvfile << "Image," << image << ",";
|
||||
csvfile << std::filesystem::file_size(image) << "\n";
|
||||
|
||||
csvfile << "\n";
|
||||
csvfile << "Number of iterations,1,2,4,8\n";
|
||||
csvfile << "fastflow:,";
|
||||
|
||||
cout << "\033[1;31mFastflow\033[0m" << endl;
|
||||
for (int iterations : {1, 2, 4, 8}) {
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(
|
||||
fastflow({image}, neig, iterations, &gameOfLife, 0));
|
||||
}
|
||||
csvfile << *std::min_element(results.begin(), results.end())
|
||||
<< ",";
|
||||
}
|
||||
csvfile << "\n";
|
||||
|
||||
csvfile << "stdthread:,";
|
||||
cout << "\033[1;31mStdthread\033[0m" << endl;
|
||||
for (int iterations : {1, 2, 4, 8}) {
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(
|
||||
stdthreads({image}, neig, iterations, &gameOfLife, 0));
|
||||
}
|
||||
csvfile << *std::min_element(results.begin(), results.end())
|
||||
<< ",";
|
||||
}
|
||||
csvfile << "\n";
|
||||
|
||||
// ------------------------------------------------------------------ //
|
||||
csvfile << "Number of Workers,sequential,fastflow,stdthreads,";
|
||||
csvfile << "Iterations:," << iter_for_num_workers_images2 << "\n";
|
||||
cout << "\033[1;31mDifferent number of workers\033[0m" << endl;
|
||||
|
||||
int hardware_concurrency = std::thread::hardware_concurrency();
|
||||
|
||||
vector<int> list_max_workers = vector<int>();
|
||||
for (int i = 1; i < hardware_concurrency; i*=2) {
|
||||
list_max_workers.push_back(i);
|
||||
}
|
||||
list_max_workers.push_back(hardware_concurrency);
|
||||
|
||||
for (int max_workers : list_max_workers) {
|
||||
csvfile << max_workers << ",";
|
||||
|
||||
if (max_workers == 1) {
|
||||
cout << "\033[1;31mSequential\033[0m" << endl;
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(sequential(
|
||||
{image}, neig, iter_for_num_workers_images2, &gameOfLife));
|
||||
}
|
||||
csvfile << *std::min_element(results.begin(), results.end());
|
||||
}
|
||||
csvfile << ",";
|
||||
|
||||
cout << "\033[1;31mFastflow with " << max_workers
|
||||
<< " workers\033[0m" << endl;
|
||||
{
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(fastflow({image}, neig,
|
||||
iter_for_num_workers_images2,
|
||||
&gameOfLife, max_workers));
|
||||
}
|
||||
csvfile << *std::min_element(results.begin(), results.end());
|
||||
}
|
||||
csvfile << ",";
|
||||
|
||||
cout << "\033[1;31mStdthread with " << max_workers
|
||||
<< " workers\033[0m" << endl;
|
||||
{
|
||||
vector<long long int> results;
|
||||
for (int i = 0; i < average_max; ++i) {
|
||||
results.push_back(stdthreads({image}, neig,
|
||||
iter_for_num_workers_images2,
|
||||
&gameOfLife, max_workers));
|
||||
}
|
||||
csvfile << *std::min_element(results.begin(), results.end());
|
||||
}
|
||||
csvfile << "\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user