SHA256
lab happens
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#include <ostream>
|
||||
#include <thread>
|
||||
#include <omp.h>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <concepts>
|
||||
unsigned g_threads = std::thread::hardware_concurrency();
|
||||
const unsigned max_threads = g_threads;
|
||||
|
||||
unsigned get_num_threads(){
|
||||
return g_threads;
|
||||
}
|
||||
|
||||
void set_num_threads(const unsigned T){
|
||||
if(T==0 || T > max_threads)
|
||||
return ;
|
||||
g_threads = T;
|
||||
omp_set_num_threads(T);
|
||||
}
|
||||
|
||||
struct measurement{
|
||||
unsigned T;
|
||||
double time;
|
||||
double speedup;
|
||||
unsigned result;
|
||||
};
|
||||
|
||||
template <std::invocable<const unsigned* , size_t> f >
|
||||
std::vector<measurement> measure_time (f, const unsigned* V, size_t n)
|
||||
{
|
||||
std::vector<measurement> ret;
|
||||
const unsigned max_threads = gen_num_threads();
|
||||
for(unsigned T = 1;T<=max_threads();T++){
|
||||
set_num_threads(T);
|
||||
double t0 = omp_get_wtime();
|
||||
const unsigned result = f(V, n)
|
||||
double t1 = omp_get_wtime();
|
||||
ret.push_back(measure{
|
||||
.T = T,
|
||||
.time = t1-t0,
|
||||
.result = result,
|
||||
.speedup = ret.size()>0? ret.back()/ret[0] : 1
|
||||
});
|
||||
}
|
||||
sen_num_threads(max_threads);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void to_csv(std::ostream& os, const std::vector<measurement> & m ){
|
||||
os << "T, time, speedups, result, \n";
|
||||
for ( auto i : m){
|
||||
os << i.T<<", "<<i.time<<", "<<i.speedup<<", "<<i.result<<"\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user