Professional Documents
Culture Documents
Week11 Lec32
Week11 Lec32
STANDARD ALGORITHMS
Week11_Lec32
11/28/2023
AGENDA
Introduction
• What is Thrust? What are the C++ standard algorithms?
The Difference
• set_difference(Thrust, C++ standard algorithms)
thrust::reduce vs std::accumulate
• How to parallelize reductions
Thrust Algorithms with Stencils
• A super useful overload
Fancy Iterators
• thrust::counting_iterator & friends
4
INTRODUCTION
7
WHAT IS THRUST?
8
WHAT ARE THE C++ STANDARD ALGORITHMS?
9
RESOURCES
10
THE DIFFERENCE
13
thrust::sequence()
8
int main() {
thrust::device_vector<int> myVector(10);
thrust::sequence(myVector.begin(),
myVector.end()); thrust::sequence()
for (int i : myVector) {
std::cout << i << " ";
std::iota()
}
return 0;
}
9
Problem #1
What is
std::iota +
std::transform ?
10
Problem #1
What is
thrust:sequence +
thrust::transform ?
11
Problem #1
thrust::tabulate()
12
Problem #1
First 10
odd numbers
13
Problem #1
thrust::tabulate( odds.begin
(), odds.end(),
[] (auto e) { return e * 2 +
1; });
Output: 1 3 5 7 9 11 13 15 17 19
15