-
Notifications
You must be signed in to change notification settings - Fork 0
/
th.cpp
executable file
·78 lines (60 loc) · 1.43 KB
/
th.cpp
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
77
78
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <deque>
#include <set>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <sstream>
#include <chrono>
#include <algorithm>
#include <random>
using namespace std;
struct Timer
{
std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
std::chrono::duration<float> duration;
Timer() {
start = std::chrono::high_resolution_clock::now();
}
/* when the function where this object is created returns,
this object must be destroyed, hence this destructor is called */
~Timer() {
end = std::chrono::high_resolution_clock::now();
duration = end - start;
float ms = duration.count() * 1000.0f;
std::cout << "Elapsed (c++ timer): " << ms << " ms." << std::endl;
}
};
const int T_ms = 10000;
const int N = 1000;
const int step = 100;
vector<double> dvec;
vector<vector<double>> J;
void sim(int a, int b) {
for (int j = a; j < b; j++) {
for (int i = 0; i < N; i++) {
J[i][j] += 1.0;
}
}
}
int main() {
Timer timer;
for (int i=0; i<N; i++){
J.push_back(dvec);
for (int j=0; j<N; j++) {
J[i].push_back(0.0);
}
}
for (int ti=0; ti < T_ms; ti++) {
#pragma omp parallel for
for (int i = 0; i < N; i += step) {
sim(i, i+step);
}
}
return 0;
}