Skip to content

Commit eee8c5c

Browse files
author
Chris Sullivan
committed
fixed indentation
1 parent cdcced2 commit eee8c5c

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

example.cc

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,46 @@ using namespace std;
99

1010

1111
void scale(int i, double* a, double* b) {
12-
a[i]=4*b[i];
12+
a[i]=4*b[i];
1313
}
1414

1515
int main () {
1616

17-
ThreadPool pool(8);
18-
19-
int N = 1e9;
20-
auto a = (double*)calloc(N,sizeof(double));
21-
auto b = (double*)calloc(N,sizeof(double));
22-
for (int i=0; i<N; i++) { b[i] = i; }
23-
24-
25-
// cold start for timing purposes
26-
pool.ParallelFor(0,N,scale,a,b);
27-
28-
int ntrials = 10;
29-
double tperformance = 0.0;
30-
cout << "Callable: c-function pointer\n";
31-
for (int i=0; i<ntrials; i++)
32-
{
33-
Timer timer([&](int elapsed){
34-
cout << "Trial " << i << ": "<< elapsed*1e-6 << " ms\n";
35-
tperformance+=elapsed;
36-
});
37-
pool.ParallelFor(0,N,scale,a,b);
38-
}
39-
cout << "Average: " << tperformance*1e-6 / ntrials << " ms\n\n";
40-
41-
tperformance = 0.0;
42-
cout << "Callable: lambda function (without capture) \n";
43-
for (int i=0; i<ntrials; i++)
44-
{
45-
Timer timer([&](int elapsed){
46-
cout << "Trial " << i << ": "<< elapsed*1e-6 << " ms\n";
47-
tperformance+=elapsed;
48-
});
49-
pool.ParallelFor(0,N,[](int k, double* a, double* b) {return a[k] = 4*b[k];},a,b);
50-
}
51-
cout << "Average: " << tperformance*1e-6 / ntrials << " ms\n\n";
52-
53-
return 0;
17+
ThreadPool pool(8);
18+
19+
int N = 1e9;
20+
auto a = (double*)calloc(N,sizeof(double));
21+
auto b = (double*)calloc(N,sizeof(double));
22+
for (int i=0; i<N; i++) { b[i] = i; } // initialize
23+
24+
25+
// cold start for timing purposes
26+
pool.ParallelFor(0,N,scale,a,b);
27+
28+
int ntrials = 10;
29+
double tperformance = 0.0;
30+
cout << "Callable: c-function pointer\n";
31+
for (int i=0; i<ntrials; i++)
32+
{
33+
Timer timer([&](int elapsed){
34+
cout << "Trial " << i << ": "<< elapsed*1e-6 << " ms\n";
35+
tperformance+=elapsed;
36+
});
37+
pool.ParallelFor(0,N,scale,a,b);
38+
}
39+
cout << "Average: " << tperformance*1e-6 / ntrials << " ms\n\n";
40+
41+
tperformance = 0.0;
42+
cout << "Callable: lambda function (without capture) \n";
43+
for (int i=0; i<ntrials; i++)
44+
{
45+
Timer timer([&](int elapsed){
46+
cout << "Trial " << i << ": "<< elapsed*1e-6 << " ms\n";
47+
tperformance+=elapsed;
48+
});
49+
pool.ParallelFor(0,N,[](int k, double* a, double* b) {return a[k] = 4*b[k];},a,b);
50+
}
51+
cout << "Average: " << tperformance*1e-6 / ntrials << " ms\n\n";
52+
53+
return 0;
5454
}

0 commit comments

Comments
 (0)