task8
This commit is contained in:
parent
3763c53dab
commit
3882aee07a
71 changed files with 160045 additions and 0 deletions
2877
ex3/seq/thread_17/Doxyfile
Normal file
2877
ex3/seq/thread_17/Doxyfile
Normal file
File diff suppressed because it is too large
Load diff
48
ex3/seq/thread_17/Makefile
Normal file
48
ex3/seq/thread_17/Makefile
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#
|
||||
# use GNU-Compiler tools
|
||||
COMPILER=GCC_
|
||||
# alternatively from the shell
|
||||
# export COMPILER=GCC_
|
||||
# or, alternatively from the shell
|
||||
# make COMPILER=GCC_
|
||||
|
||||
# use Intel compilers
|
||||
#COMPILER=ICC_
|
||||
|
||||
# use PGI compilers
|
||||
# COMPILER=PGI_
|
||||
|
||||
# use CLANG compilers
|
||||
# COMPILER=CLANG_
|
||||
|
||||
|
||||
#SOURCES = main.cpp
|
||||
SOURCES = gh_main.cpp
|
||||
OBJECTS = $(SOURCES:.cpp=.o)
|
||||
|
||||
PROGRAM = main.${COMPILER}
|
||||
|
||||
# uncomment the next to lines for debugging and detailed performance analysis
|
||||
CXXFLAGS += -g
|
||||
LINKFLAGS += -g
|
||||
# needed for parallel threads in C++-17
|
||||
LINKFLAGS += -ltbb
|
||||
|
||||
#https://stackoverflow.com/questions/67923287/how-to-resolve-no-member-named-task-in-namespace-tbb-error-when-using-oned
|
||||
#dpcpp my_app.cpp -DPSTL_USE_PARALLEL_POLICIES=0 # for libstdc++ 9
|
||||
#dpcpp my_app.cpp -D_GLIBCXX_USE_TBB_PAR_BACKEND=0 # for libstdc++ 10
|
||||
|
||||
|
||||
# do not use -pg with PGI compilers
|
||||
|
||||
ifndef COMPILER
|
||||
COMPILER=GCC_
|
||||
endif
|
||||
|
||||
include ../${COMPILER}default.mk
|
||||
|
||||
|
||||
task:
|
||||
@pdflatex task
|
||||
@pdflatex task
|
||||
|
||||
1
ex3/seq/thread_17/compile.log
Normal file
1
ex3/seq/thread_17/compile.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
101
ex3/seq/thread_17/gh_main.cpp
Normal file
101
ex3/seq/thread_17/gh_main.cpp
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
// C++ Vorlesung xxx
|
||||
// C++-17: Threads, execution policies
|
||||
// Great web pages, great book by Filipek: https://www.bfilipek.com/2018/06/parstl-tests.html
|
||||
|
||||
/*
|
||||
g++ -O3 -std=c++17 gh_main.cpp -ltbb
|
||||
g++ -O3 -std=c++17 -pedantic -Weffc++ -Wall -Wextra -pedantic -Wswitch-default -Wfloat-equal -Wundef -Wredundant-decls -Winit-self -Wshadow -Wparentheses -Wshadow -Wunreachable-code -Wuninitialized -Wmaybe-uninitialized gh_main.cpp -ltbb
|
||||
---
|
||||
cppcheck --enable=all --inconclusive --std=c++11 --std=posix --suppress=missingIncludeSystem gh_main.cpp
|
||||
clang++ -O3 -std=c++17 -ltbb gh_main.cpp
|
||||
clang++ -std=c++17 -fsyntax-only -Wdocumentation -Wconversion -Wshadow -Wfloat-conversion -pedantic gh_main.cpp
|
||||
clang++ -std=c++17 -Weverything -Wno-c++98-compat -Wno-padded -ltbb gh_main.cpp
|
||||
clang++ -cc1 --help
|
||||
---
|
||||
icpc -O3 -std=c++17 -ltbb -Wall -Wextra -pedantic gh_main.cpp
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <execution> // execution policy
|
||||
#include <iostream>
|
||||
#include <list> // list
|
||||
#include <numeric> // accumulate
|
||||
#include <random>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
using namespace std::chrono; // timing
|
||||
|
||||
|
||||
/** \brief Prints the whole vector of base class pointers
|
||||
* \param[in,out] s output stream
|
||||
* \param[in] v vector
|
||||
* \return changed output stream
|
||||
*/
|
||||
template <class T>
|
||||
ostream& operator<<(ostream &s, const vector<T>& v)
|
||||
{
|
||||
for (const auto& it: v) // Reference is required with unique_ptr. No copy constructor for unique_ptr available!
|
||||
{
|
||||
cout << *it << " ";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "Threads C++17" << endl;
|
||||
|
||||
size_t const N = 1<<25;
|
||||
vector<double> v(N);
|
||||
//list<double> v(N); // execution::par not possible : missing 'operator-'
|
||||
iota(v.begin(), v.end(), 1);
|
||||
std::shuffle(v.begin(), v.end(), std::mt19937{std::random_device{}()});
|
||||
|
||||
auto const v_bak(v);
|
||||
|
||||
{
|
||||
v = v_bak;
|
||||
cout << "---- sort old ----" << endl;
|
||||
auto t1 = system_clock::now();
|
||||
sort(v.begin(), v.end());
|
||||
auto t2 = system_clock::now();
|
||||
auto duration = duration_cast<microseconds>(t2 - t1);
|
||||
cout << "sort old : " << static_cast<double>(duration.count()) / 1e6 << " sec." << endl;
|
||||
}
|
||||
|
||||
{
|
||||
v = v_bak;
|
||||
cout << "---- sort seq ----" << endl;
|
||||
auto t1 = system_clock::now();
|
||||
sort(std::execution::seq, v.begin(), v.end());
|
||||
auto t2 = system_clock::now();
|
||||
auto duration = duration_cast<microseconds>(t2 - t1);
|
||||
cout << "sort seq : " << static_cast<double>(duration.count()) / 1e6 << " sec." << endl;
|
||||
}
|
||||
|
||||
{
|
||||
v = v_bak;
|
||||
cout << "---- sort par ----" << endl;
|
||||
auto t1 = system_clock::now();
|
||||
sort(std::execution::par, v.begin(), v.end());
|
||||
//auto cnt = count(std::execution::par, v.begin(), v.end(), 17);
|
||||
auto t2 = system_clock::now();
|
||||
auto duration = duration_cast<microseconds>(t2 - t1);
|
||||
cout << "sort par : " << static_cast<double>(duration.count()) / 1e6 << " sec." << endl;
|
||||
}
|
||||
|
||||
{
|
||||
v = v_bak;
|
||||
cout << "---- sort par_unseq ----" << endl;
|
||||
auto t1 = system_clock::now();
|
||||
sort(std::execution::par_unseq, v.begin(), v.end());
|
||||
auto t2 = system_clock::now();
|
||||
auto duration = duration_cast<microseconds>(t2 - t1);
|
||||
cout << "sort par_unseq: " << static_cast<double>(duration.count()) / 1e6 << " sec." << endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
84
ex3/seq/thread_17/main.cpp
Normal file
84
ex3/seq/thread_17/main.cpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
// C++ Vorlesung xxx
|
||||
// C++-17: Threads, execution policies
|
||||
// Great web pages, great book by Filipek: https://www.bfilipek.com/2018/06/parstl-tests.html
|
||||
|
||||
/*
|
||||
g++ -O3 -std=c++17 main.cpp -ltbb
|
||||
g++ -O3 -std=c++17 -pedantic -Weffc++ -Wall -Wextra -pedantic -Wswitch-default -Wfloat-equal -Wundef -Wredundant-decls -Winit-self -Wshadow -Wparentheses -Wshadow -Wunreachable-code -Wuninitialized -Wmaybe-uninitialized main.cpp -ltbb
|
||||
---
|
||||
cppcheck --enable=all --inconclusive --std=c++11 --std=posix --suppress=missingIncludeSystem main.cpp
|
||||
clang++ -O3 -std=c++17 -ltbb main.cpp
|
||||
clang++ -std=c++17 -fsyntax-only -Wdocumentation -Wconversion -Wshadow -Wfloat-conversion -pedantic main.cpp
|
||||
clang++ -std=c++17 -Weverything -Wno-c++98-compat -Wno-padded -ltbb main.cpp
|
||||
clang++ -cc1 --help
|
||||
---
|
||||
icpc -O3 -std=c++17 -ltbb -Wall -Wextra -pedantic main.cpp
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <execution> // execution policy
|
||||
#include <iostream>
|
||||
#include <numeric> // accumulate
|
||||
#include <random>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
using namespace std::chrono; // timing
|
||||
|
||||
// Great web pages, great book by Filipek
|
||||
// https://www.bfilipek.com/2018/06/parstl-tests.html
|
||||
template <typename TFunc> void RunAndMeasure(const char *title, TFunc func)
|
||||
{
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
auto ret = func();
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
std::cout << title << ": " <<
|
||||
std::chrono::duration <double, std::milli>(end - start).count()
|
||||
<< " ms, res " << ret << "\n";
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
//std::vector<double> v(6000000, 0.5);
|
||||
std::vector<double> v(1<<30, 0.5);
|
||||
|
||||
RunAndMeasure("std::warm up", [&v]
|
||||
{
|
||||
return std::reduce(std::execution::seq, v.begin(), v.end(), 0.0);
|
||||
});
|
||||
|
||||
RunAndMeasure("std::accumulate", [&v]
|
||||
{
|
||||
return std::accumulate(v.begin(), v.end(), 0.0);
|
||||
});
|
||||
|
||||
RunAndMeasure("std::reduce, seq", [&v]
|
||||
{
|
||||
return std::reduce(std::execution::seq, v.begin(), v.end(), 0.0);
|
||||
});
|
||||
|
||||
RunAndMeasure("std::reduce, par", [&v]
|
||||
{
|
||||
return std::reduce(std::execution::par, v.begin(), v.end(), 0.0);
|
||||
});
|
||||
|
||||
RunAndMeasure("std::reduce, par_unseq", [&v]
|
||||
{
|
||||
return std::reduce(std::execution::par_unseq, v.begin(), v.end(), 0.0);
|
||||
});
|
||||
|
||||
RunAndMeasure("std::find, seq", [&v]
|
||||
{
|
||||
auto res = std::find(std::execution::seq, std::begin(v), std::end(v), 0.6);
|
||||
return res == std::end(v) ? 0.0 : 1.0;
|
||||
});
|
||||
|
||||
RunAndMeasure("std::find, par", [&v]
|
||||
{
|
||||
auto res = std::find(std::execution::par, std::begin(v), std::end(v), 0.6);
|
||||
return res == std::end(v) ? 0.0 : 1.0;
|
||||
});
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue