-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprange.cpp
More file actions
76 lines (63 loc) · 2.7 KB
/
prange.cpp
File metadata and controls
76 lines (63 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <stdlib.h>
//#include "challenges/mceliece/mce240sp.h"
#include "template_prange.h"
#include "challenges/mceliece/mce923sp.h"
#include "template_prange.h"
#include "instance.h"
#include "helper.h"
#include <omp.h>
#include <time.h>
int main(int argc, char* argv[])
{
if(argc > 2){
std::cerr << "Wrong number of input parameters! Usage: ./prange <nr_threads>. nr_threads is optional.\n";
return 1;
}
std::cout << "Starting multithreaded prange" << std::endl;
const uint32_t nr_threads = (argc == 2) ? atoi(argv[1]) : omp_get_max_threads();
const uint32_t seed0 = time(NULL);
srand(seed0);
const uint32_t seed1 = rand();
random_seed(seed1);
DecodingInstance I(h, s, n, k);
static constexpr ConfigTemplatePrange config(n, k, w, addRows, newN);
config.print();
const auto B = config.parse_weight_string(eW);
// instantiate sequentially prange instances outside the parallel region because the omp critical fix
// does not seem to fix the not-threadsafety of m4ri inits/frees...
std::vector<TemplatePrange<config>*> pranges(nr_threads);
for(int i = 0; i < nr_threads; i++)
pranges[i] = new TemplatePrange<config>(I, B);
// some info
std::cout << "seed0 = " << seed0 << std::endl;
std::cout << "seed1 = " << seed1 << std::endl;
std::cout << "Threads: " << nr_threads << std::endl;
// some timings etc
uint64_t overall_loops = 0;
auto start_real = timer_start(CLOCK_REALTIME);
auto start_CPU = timer_start(CLOCK_PROCESS_CPUTIME_ID);
#pragma omp parallel default(none) shared(pranges, overall_loops) num_threads(nr_threads)
{
auto id = omp_get_thread_num();
auto loops = pranges[id]->run();
#pragma omp atomic
overall_loops+=loops;
}
auto elapsed_real_ns = timer_end(start_real, CLOCK_REALTIME, true);
auto elapsed_CPU_ns = timer_end(start_CPU, CLOCK_PROCESS_CPUTIME_ID, true);
double elapsed_real_s = double(elapsed_real_ns) / double(1e9);
double elapsed_CPU_s = double(elapsed_CPU_ns) / double(1e9);
if(I.check())
std::cout << "Found solution after " << overall_loops << " loops" << std::endl;
else
std::cout << "Something went wrong, solution not correct!\n";
// in a multithreaded scenario cpu time can exceed wall time (each thread/core counts individually)
std::cout << std::fixed << "Real time: " << elapsed_real_s << "s" << std::endl;
std::cout << std::fixed << "CPU time: " << elapsed_CPU_s << "s" << std::endl;
mzd_print(I.error);
// sequentially delete instances so mzd_free does not throw errors right and left
for(int i = 0; i < nr_threads; i++)
delete pranges[i];
return 0;
}