Previous | Next --- Slide 50 of 63
Back to Lecture Thumbnails
itoen

In C++ 20 a new overload of std::transform allowing for various execution policies is introduced. It's interesting to see that they clearly distinguish std::execution::parallel_policy (permitting multiple threads) and std::execution::unsequenced (permitting interweaving the unary_op function body within a thread, aka vectorization). These are also just abstractions that provide independence guarantees - how it is implemented is unknown and probably compiler/hardware dependent.

The documentation for it is fairly difficult to understand without having taken this class!

https://en.cppreference.com/w/cpp/algorithm/transform

arkhan

A "lightbulb" moment for me was when Kayvon explained the difference between a vector and a sequence, namely, that you can access vector elements individually and directly via indices, whereas with sequence you can only access elements through abstractions like map.

xhe17

Just a side note, in python, we could use either lambda function or list comprehension to execute this mapping idea. e.g. 1. 3 x every element in a list (lambda function): l = list(map(lambda x: 3 * x, l)) 2. 3 x every element in a list (list comprehension): l = [3 * x for x in l].

msere

It is interesting that C++ transform can have an output type different from the input type, and makes me wonder whether there is an intermediate representation of the data used by transform

mkarra

Is this map function analogous to SIMD? What is the relationship between the two concepts?

blipblop

@mkarra Since map applies the same function to all data elements in a sequence, I'd say it's analogous to SIMD. I think SIMD refers more specifically to hardware implementation of issuing some small allowed subset of instructions to 2^N-wide registers. Like problem 2 on our first homework. Map seems to be more general/high-level in the sense that sequence can be arbitrarily long, and the function can have any form.

Please log in to leave a comment.