-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy path_test_ppl.cpp
More file actions
98 lines (79 loc) · 1.41 KB
/
_test_ppl.cpp
File metadata and controls
98 lines (79 loc) · 1.41 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @file _test_ppl.cpp
* @brief
*
* @author Yonhgwhan, Roh (somma@somma.kr)
* @date 2017/02/22 09:51 created.
* @copyright All rights reserved by Yonghwan, Roh.
**/
#include "stdafx.h"
#include <ppl.h>
#include <concurrent_queue.h>
#include <vector>
#include <queue>
#include "_MyLib/src/StopWatch.h"
bool test_for()
{
std::vector<int> a1 = { 1,2,3,4,5 };
std::vector<int> a2;
std::vector<int> a3 = { 1,2,3,4,5 };
for (int i=0; i<1024; ++i)
{
a2.push_back(i);
}
std::queue<std::vector<int> > q;
q.push(a1);
q.push(a2);
q.push(a3);
for (int i = 0; i < 3; ++i)
{
std::vector<int>& a = q.front();
for (auto& v : a)
{
log_info "tid=%u, %u",
GetCurrentThreadId(),
v
log_end;
}
q.pop();
}
return true;
}
bool test_ppl_parallel_for()
{
std::vector<int> a1 = { 1,2,3,4,5 };
std::vector<int> a2;
std::vector<int> a3 = { 1,2,3,4,5 };
for (int i = 0; i < 32; ++i)
{
a2.push_back(i);
}
Concurrency::concurrent_queue<std::vector<int> > q;
q.push(a1);
q.push(a2);
q.push(a3);
Concurrency::parallel_for_each(
q.unsafe_begin(),
q.unsafe_end(),
[&q](std::vector<int>& a)
{
for (auto& x : a)
{
log_info "tid=%u, %u",
GetCurrentThreadId(),
x
log_end;
}
log_info "tid=%u, done",
GetCurrentThreadId()
log_end;
});
return true;
}
///
bool test_ppl()
{
//test_for();
test_ppl_parallel_for();
return true;
}