CppCast - Parallel Ranges

Episode Date: July 26, 2018

Rob and Jason are joined by Christopher Di Bella to discuss using Ranges with Parallel algorithms and much more. Christopher Di Bella is a Staff Software Engineer for Codeplay’s ComputeCpp R...untime Technology and a C++ teacher. He advocates for including the Concepts TS and the Ranges TS in C++20. Chris spends his days working on ComputeCpp, Codeplay’s implementation of SYCL, a Khronos Standard for heterogeneous programming in C++; the Khronos implementation for the Parallel STL (using SYCL); and researching Parallel Ranges, which is an attempt to fuse ranges together with the parallel STL. Chris was previously a software developer for Nasdaq, and a tutor for UNSW Sydney’s advanced C++ and compiler courses. In his spare time, Chris enjoys poking at things involving Ranges, snowboarding, playing games, and watching films. News Italian C++ Conference Videos Available Conan 1.6 Release Webview proposal C++/CLI support comes to ReSharper C++ Christopher Di Bella @cjdb_ns Christopher Di Bella's GitHub Links cpp.standardisation.au@gmail.com Generic Programming 2.0 with Concepts and Ranges P0836R1 Introduce Parallelism to the Ranges TS SYCL Parallel STL Sponsors PVS-Studio February 31 Patreon CppCast Patreon Hosts @robwirving @lefticus

Transcript
Discussion (0)
Starting point is 00:00:00 Episode 160 of CppCast with guest Chris DiBella, recorded July 25th, 2018. today at viva64.com. In this episode, we discuss the WebView proposal and ReSharper updates. And we talk to Chris DiBella. Chris talks to us about using ranges with parallel algorithms. Welcome to episode 160 of CBPcast, the first podcast for C++ developers by C++ developers. I'm your host, Rob Irving, joined by my co-host, Jason Turner. Jason, how are you doing today? I'm all right, Rob. How are you doing? I'm doing host, Rob Irving, joined by my co-host, Jason Turner. Jason, how are you doing today? I'm all right, Rob. How are you doing? I'm doing okay now.
Starting point is 00:01:34 I had to reinstall Windows and everything on my work laptop for the past few days, so that's always fun times, but I think everything's working now. Yeah, and one of the main headaches is Skype, since that's important to us. Yeah, Skype is important. But I got the old version of Skype, which I much prefer over the new version. Anyway, at the top of the episode, I threw in a piece of feedback. This week, we got an email from Ricardo. And he writes, first of all, kudos for such a great show. On episode 159, Dimitri and you guys went over formal verification being
Starting point is 00:02:08 unuseful in the industry except inside NASA and briefly in universities needing to ramp up software engineering content within a computer science curriculum. And he says he doesn't assume either of us have disdain for those topics, but he respectfully disagrees. Formal verification is of paramount importance he supposes neither would want to embark on an airplane whose avionics or implemented an ad hoc should but then fix it way there's a vast number of examples um anything that deals with life and possibly anything else with a hard requirement of
Starting point is 00:02:38 determinism from the software part and being unaware of formal verification leads to ad hoc methods that will be lacking in many aspects and he ends with saying as to whether computer science degrees should feature more content from software engineering that's questionable either course serves a different purpose as many others do such as data science software security and so on yeah i think we we did pretty briefly talk about formal verification i don't remember exactly what it was we were saying but i know we we've had this topic brought up to us before and been asked if we could do an episode on it and yeah we need to find someone who could do an episode on this with us sure yeah because i i have heard that formal verification is very important in um you know in airline
Starting point is 00:03:22 software which makes sense to me. And I remember discussing at one point that I think it's not used in most of the car manufacturing industry's software and probably should. I think that's something we maybe have talked about before. That I'm not sure. I don't recall. But yeah, it sounds like an interesting topic i would like to know more about it i definitely don't have any disdain for it i just need to know more about it yeah well i think i i will say i think in that episode with dimitri when we're discussing this
Starting point is 00:03:56 we kind of glossed over and conflated the two different disciplines between computer science and software engineering like i i have a science degree, which is a more mathematical-based degree. And I know that there are programs that are more software engineering, where you actually talk about creating software, not just the theory behind it. Well, we'd love to hear your thoughts about the show as well. You can always reach out to us on Facebook, Twitter, or email us at feedback at cpcast.com. And don't forget to leave us a review on iTunes. Joining us today is Chris DiBella.
Starting point is 00:04:27 Chris is a staff software engineer for CodePlay's ComputeCVP runtime technology and a C++ teacher. He advocates for including the concepts TS and the ranges TS in C++20. Chris spends his day working on ComputeCVP, CodePlay's implementation of SYCL, a Kronos standard for heterogeneous programming in C++, the Kronos implementation for the parallel STL, and researching parallel ranges, which is an attempt to fuse ranges together with the parallel STL. Chris was previously a software developer for NASDAQ and a tutor for UNSW's Sydney Advanced C++ and Compiler courses.
Starting point is 00:05:02 In his spare time, Chris enjoys poking at things involving ranges, snowboarding, playing games, and watching films. Chris, welcome back to the show. Thanks, it's great to be back. So when we... I'm sorry, go ahead. Sorry, go on. When we last had you on, you were just in the process of making this move from Sydney to Codeplay in Edinburgh. And has everything gone well?
Starting point is 00:05:24 Yeah, everything's gone well. It's been pretty much a year now since I've been in Edinburgh. And has everything gone well? Yeah, everything's gone well. It's been pretty much a year now since I've been in Edinburgh, and the culture's very much the same. There's a few differences, but not terribly different. It's a bit surreal still being on the other side of the planet to most of my friends and family, but I've been able to build a lot of new friendships, and working for Coplay has just been great for learning so much,
Starting point is 00:05:51 and it really has been a positive move overall. I'm guessing it's harder to find Vegemite. You'd be surprised. The Tesco that I live from sell Vegemite, so that's not the thing that's hard. It's the Tim Tams that I'm very disappointed with. They only sell them in London. Tim Tams.
Starting point is 00:06:09 Is that a, what is that? Um, so it's a, it's a biscuit that's, uh, I think it's got like, it's definitely a chocolate biscuit, not, not a cookie. Um, and, uh, it's a bit difficult to describe because when you, um, when you bite into it, it's chocolate inside, like a chocolate sort of wafer, uh, if that makes sense. Um, and it's, uh, very much something that, um, Australians identify with as being one of our, uh, tea and, uh, and coffee sort of foods or as a dessert. And one of the nicest things about Tim Tams is that you can drink through them,
Starting point is 00:06:51 drink a tea or a coffee through them like a straw. You may have heard of a Tim Tam slam. That's what it's kind of been popularized as. And, yeah, so they're very tasty. Definitely go for the double choc Tim Tams over the regular Tim Tams. They're much creamier. If I remember, I'll bring some to CppCon and you can try them out. That'd be great.
Starting point is 00:07:13 So you can get them in London, you say? Yes, I can have them mailed from London to Edinburgh. I'm looking, since we have video here, which I don't know if all of our listeners know that, but we often have video on for the sake of being able to interact with each other. And I'm looking behind you. I don't see like five crates of Tim Tams or anything. I'm slightly disappointed. Uh, the, um, the ones that I have here in London are, um, I was like, yeah, in London, they're, uh, really expensive. It's, um's sort of like three or four pounds a packet, whereas I can get them for less than half that price in Sydney. So when I go back to Sydney next time, I'll get stopped.
Starting point is 00:07:54 So when I come back from Sydney next time, I'll get stopped by border security, and they'll just see a suitcase full of Tim Tams. Yeah, you'll probably be charged some import duty or something if you do that, but that's funny. Okay. Well, Chris, we have a couple news articles to discuss. Feel free to comment on any of these, and then we'll start talking to you more about the work you're doing with the Standards Committee and a couple other topics, okay? Sure.
Starting point is 00:08:21 Okay. So this first one is the Italian C++ conference, which happened recently, now has their videos online. I don't think we've talked about the Italian C++ conference before. I think it's like a one-day conference run by the Italian C++ user group. But it's great that they were able to record all their videos, put them up online. I think most of them are in English. Uh, so you don't need to speak Italian to watch most of these videos and, uh, great, great conference. And, uh, I think I've met some of the organizers for this one, uh, at, uh, the Microsoft MVP event. Oh, okay. Yeah. And, uh, I think some of the, I mean, I think in years past,
Starting point is 00:09:02 some of the talks were in Italian and I didn't go through all of these. Oh, well, here's one title that's clearly in Italian, so I don't even know what it says. I think it's a total of 11 talks, and I think the Reddit listings said three of them were in Italian, maybe? Yeah. Okay. I'm sorry, go ahead.
Starting point is 00:09:23 I was just going to say, the talk's all very interesting. And when I shared the link with some colleagues, and one person thought that everything was going to be in Italian, and that ensued with a very interesting conversation about C++, but where everything is in Italian instead of English. Yeah, I don't know the culture in Italy, but every European that I've interacted with, regardless of what language they speak,
Starting point is 00:09:51 I just haven't interacted with very many Italian C++ programmers, they all insist that everything in the code must be English. Like, even the comments. Like, it can be a team of nothing but Dutch workers. They're like, no, put your comments in English. Interesting. I mean, that's of all the people that i've talked to of course in a lot in the european world where there's uh uh people from a bunch of different countries that all work at the same office i know that's just mandated that everything's in english in those cases with every company i've ever talked to kind of crazy from my perspective that's funny okay uh next thing we have is another release
Starting point is 00:10:30 from conan this is uh the 1.6 release uh justin do you have a chance to go through this and see what the the big updates were i looked through it but honestly the updates don't mean a whole lot to me because i haven't spent so much time with Conan. The only thing that stood out is it appears that they've got some more support for using LLVM backend with Visual Studio. Okay, I see that. Yeah, and they do list several new features here. Like you said, I guess I haven't used Conan much myself, so I can't speak to any of these features specifically but glad to see they're still working on updates yes and then the next thing um we we talked a lot about 2d graphics um a few weeks ago with uh with guy davidson um there was a new proposal, Stood WebView.
Starting point is 00:11:25 And this was basically made kind of in response to the 2D graphics discussion, kind of as an alternative. And it's basically adding a web view, you know, the ability to render HTML to C++ in a proposal. And a lot of the people on Reddit seem to be thinking it's a joke, but it's a very serious proposal written by someone who has a lot of experience with the Standards Committee, right? Yeah. Yes.
Starting point is 00:12:02 And yeah, most of the people seem to think this is a couple months late for april the first yeah it didn't really feel like a um like a joke when i was reading through it i mean i i know that how's a very senior person very serious person on the uh on the c++ committee so maybe that influenced the tone in which i read it but um i really did feel like he collected some of the feedback from the Rapperswil meeting and then gone away, had a bit of a think about it and made a proposal that he felt was a good sort of follow-up to what happened in the graphics evening session at Rapperswil. So is there anything from the standard
Starting point is 00:12:45 that specifically stood out to you, Chris, or from this proposal, I mean, if you read it in depth enough for that? I read it a couple of times, and it felt like it was saying that we should, because the C++ Standards Committee has a lot to work with, and we're not all experts on how things in in gui's work we should probably
Starting point is 00:13:07 defer that to other standards bodies such as w3c who can handle things like that and then we just provide an interface for it and i thought that was a a very nice way of doing it don't get me wrong i i'm not an expert in graphics so i can't really weigh in on on anything but i do feel like graphics does have a place in uh in c++ and in having some sort of standard interface i feel like the the motivations there uh are good and i know that's a quite a controversial opinion but i um i do think that we should have it and this this may be a bit more of a palatable way to get something standardized. Interesting.
Starting point is 00:13:53 Yeah. It seems like still like so much to add into the C++ standard, even if we're kind of leaning on existing standards bodies like W3C, which is in charge of HTML. Yeah, just putting HTML support of any kind into C++. Seems like a lot. I don't know. Well, the way that I think it should happen is that we should go through a TS
Starting point is 00:14:21 before we get to putting it into the actual C++ standard, primarily so that we can just get a bit of experience and it doesn't need to be as high quality as what's going to go into the international standard, which is what most people refer to as standard C++. Right. Because then, you know, we can experiment. We can say, well, this thing didn't work.
Starting point is 00:14:47 We can just drop that or this did work, but maybe we should tweak it a little bit. Well, and on the topic of, you know, big things and things that are already kind of standardized or pseudo-standardized, someone on the Reddit discussion suggested, well, why don't we just standardize Qt because it's already used by so many people in the C++ world. And Hal commented on this and he said there is 12,984
Starting point is 00:15:13 functions in Qt currently. And if we were to be generous or optimistic and say 10 minutes per function for the committee to spend time on each one to get it into the standards body. And this is also speaking to what Rob was saying with how big of something that we add to the standard. He estimates that it would take 30 complete meetings with the standards committee doing nothing else except for reviewing the functions in Qt for it to be possible to add it to the standard. So perhaps there needs to be some sort of side channel or something like this. And this is also kind of what Guy was talking about with like the British standards body accepting the 2D proposal. I don't know. I have no idea where any of this is going to lead ultimately yeah okay um and then the next
Starting point is 00:16:06 article we have uh last one is uh from jetbrains c++ cli support coming to resharper c++ and uh this is something that i'm excited about i like i said i just reinstalled uh everything on my windows machine and i installed resharSharper C++, and this is, I guess, a preview version that they just announced, so it's not in the version I just installed, but I might go ahead and install the preview version, or if not, I'm looking forward to it coming out officially, because I work in both C Sharp and C++, so C++ CLI is somewhere where I do spend a decent amount of time, and it would be nice to get ReSharper there. All right, Rob, I'm going to ask you a question here, and you already know
Starting point is 00:16:49 that I talked about this a little bit before we started the show. I read this, and I said, wasn't C++ CLI completely replaced with the WinRT stuff that Kenny Cares is doing? I mean, Microsoft would like that to be the case, but if you're still making an application that targets Windows 7, you can't use any of that stuff that Kenny was talking about. If you're still targeting Windows 7 and you want to make use C Sharp and C++ together in an application, then you're still going to be using C++ CLI, most likely. If you're only targeting Windows 10, then yeah, you can go ahead and use the stuff Kenny works on,
Starting point is 00:17:28 the UWP stuff. So is it specifically Windows 10? I mean, you skipped over Windows 8 in there. Is there 8 or 8.1 support those APIs? 8, I believe, is when it was introduced, the UWP stuff, but I'm not sure if they're still actively targeting 8 with the stuff Kenny's working on. I'm honestly not sure. Okay.
Starting point is 00:17:49 Yeah, I was going to ask a similar question to Jason, because I haven't heard anything about C++ CLI for many years now. But I suppose, Rob, your reasoning there is similar to people who are still stuck on GCC 4.4, for example. Yeah. You know, they're limited to C++ 03. Right. Yeah, absolutely. I mean, there's lots of people who might still be using
Starting point is 00:18:13 older version of Windows, or maybe you don't even care about older version of Windows, but you'd rather use WPF over UWP than you're going to be using C++ CLI. Yeah. Yeah, and it just sounds like you're making up acronyms to me because it's been so long since I've been in the Windows-specific world. Windows what? Something forms? What are those things?
Starting point is 00:18:32 WinForms WPF, which is Windows Presentation Framework, I think. Okay. Anyway, so we were just talking a little bit about standardization. Chris, do you want to tell us about the work you've been doing with Standards Committee? So I've helped co-author a handful of papers, mostly pertaining to things to do with ranges. For example, there's the memory algorithms that you have in C++17. With Kesi Carter, we co-authored a paper that looked at getting those alongside the rest of the ranges TS
Starting point is 00:19:10 because they weren't considered. I'll talk more about that in a little bit. The other paper that I would say is, quote, big, unquote, is the parallel ranger stuff. Again, I'll talk about that in a little bit. The thing that I think is really important to discuss at the moment is getting Stands Australia involved with the Stands Committee. So at the moment, Stands Australia isn't really involved at all with C++.
Starting point is 00:19:40 And just for people who aren't terribly familiar with the organizational side of the Standards Committee, I'll quickly do a breakdown. But the Standards Committee is formerly known as ISO, IEC, JTC1, SC22, WG21. Quite a mouthful, so most people condense that down to just WG21. Now, ISO is the International Organization for Standardization, which is comprised of 162 different countries, national standard organizations, which are called national standard bodies or national bodies for short. And ISO is run out of Geneva in Switzerland. And ISO breaks down their standards groups into technical committees, which are like the grandparent of particular things, and they're called TC's. Then you have subcommittees, which are SC's, and then working groups, which are WG's. And these committees and groups are made up of experts appointed by each
Starting point is 00:20:40 country's national body. And national bodies can either be observing members or participating members. The difference being that participating members actively develop international standards and they must be active for basically every meeting and every ballot that goes out for voting. Whereas the O members or observing members are bodies that want to follow it, but they may not want to actually be actively participating. And the IEC part of ISO IEC is the International Electrotechnical Commission, which publishes international standards for electrical, electronic and related technologies. They are separate to ISO, but they work together in what's called the Joint Technical Committee 1, which is strictly for information technology standards. And so it's a technical committee owned by both ISO and IEC. And then a child of JTC1 is SC22, which is the subcommittee for programming languages. And this is where the C++ working group fits in.
Starting point is 00:21:49 So SC22 is also home for COBOL, FORTRAN, AIDA, C, and sorry, Prolog and programming language vulnerabilities. And C and C++ both fit in there as separate working groups. And then, so this is where I'd like to see Stens Australia come in. So Stens Australia is the national body for Australia. And so far, there isn't really much of a presence there in any of the programming language subcommittee. And it'd be really good if we could have a group of experts
Starting point is 00:22:27 representing Australia in this subcommittee, particularly WG21, which is for C++, because C++ is used all around the world. It's used on digital image systems that are even on Mars. So, you know, it's literally out of this world. And so I think it would be great if, you know, we had extra representation across the world because there are C++ developers in Australia,
Starting point is 00:22:56 but there are also C developers in Australia as well. And programming language vulnerabilities is something that everyone should be caring about regardless of which language they're using. So what does it take to get someone into the C++ national body representing Australia? Do you just need to have a C++ expert in Australia start showing up to meetings, or is it a little bit more complicated than that? It's a lot more complicated than that um so what what happens is you have to in order for stens australia to say yes we will uh join this subcommittee uh what you need to do is you need to prove to them
Starting point is 00:23:34 that there's actually enough stakeholder interest in um in this particular area and so that means you've got to have academic bodies, people who are in the commercial industry, people who are part of regulatory bodies. I could go on. There's about a list of 20 different things, the boxes that I need to check and have contacts in a good number of those.
Starting point is 00:23:58 I don't have to have all the boxes checked, but I've got to have at least enough to convince whoever's reviewing this that yes, programming languages are something that Australia should care about and is industry-wide interest. And once that happens, then what happens is they form what's known as a mirror committee, which basically mirrors SC22 and the C++ Standards Committee and whatever other working groups people want to be a part of. And then we can start sending people to the standards meetings on behalf of Australia. You know, I must say, this all sounds about as straightforward as you would expect an international standards body to be. Yep.
Starting point is 00:24:41 It's an insane amount of work. And I'm kind of at the point where i can't progress any further until i have more people who are interested and so i'm actively looking for people who are wanting to uh join an australian standards body and um i think the the two kinds of people that can join are people who are either living in aust or people who are Australian. So I think they're the two kinds of people who can join Stans Australia. So if I may try to make sure I understand this, officially, there is no, I guess, for lack of a better word, legal representation of australia in the c++ standards committee so a australian cannot be a voting attendee of a standards meeting they can't vote
Starting point is 00:25:32 on behalf of australia but if they are a part of say ansi which is the american uh body then they can vote through ansi or uh if they're a part of BSI, which is the British one, then they're allowed to vote through Britain, but they can't vote for Australia. Right. Okay. Do you, off chance, just out of curiosity, know how many countries do currently have official representation in that working group?
Starting point is 00:25:59 I don't know how many there are, but I can tell you it's fewer than 60. It's got to be at most 59, because IEC only has 60 members and uh c plus plus is part of a joint thing between the two so okay by deduction i guess i've concluded that there can only be at most 60 countries interested in c plus plus um and because australia's not in it then take them out it's at most 59 uh but i don't know how many countries are actually involved now 60 is a fairly big number i mean there's what 200 and something recognized independent nations or whatever right now something like that
Starting point is 00:26:41 depending on who you ask it is a quite a large number of countries. So if you're listening to the show, if you use people's boss every day and you're from Australia, should they just reach out to you or, or what should someone do if they want to help with this effort to get national Australia involved? I think reaching out to me in any medium that you already have is fine. I will also provide CPP Cast with the email that I set up
Starting point is 00:27:13 for getting in touch with people because I set one up just to get things that are focused on that to stay in that sort of an area. But if you already have an email, just feel to to drop me a line already okay well when we had you on the first time uh we talked a lot about concepts and ranges i think um do you want to tell us a little bit about the work you're doing with ranges at codeplay so at codeplay we're doing a bit of research with um with looking at how we can merge um merge ranges with parallelism or not even parallelism it's more heterogeneous computing which is getting code to run on multiple devices so you may have a gpu a cpu an fpga and a dsp and you have code that's all part of the same program that's executing different parts on these different devices.
Starting point is 00:28:08 And through some research, we've discovered that Rangers actually gives you some performance benefits for free. So using the normal parallel STL, what you'd need to do is you'd need to have some sort of buffer if you wanted to communicate between algorithms. But the way that ranges lets you do things is that you can compose things using these new things called views. And if you're not familiar with what a view is, you should take a look at Eric Niebler's 2015 CPPCon keynote, which talks all about ranges, views, and actions. And using those, we can compose a description of what an algorithm is before it's actually computed, because views are lazy in their nature. And so we go about describing everything that we want to happen,
Starting point is 00:29:06 but we don't actually have anything happen straight away. And then once we've finished our description of what we want to happen, we then say, go ahead and do that. And that means that we can eliminate a lot of the latency. We don't have to have buffers. We don't have to transfer data from the host, which is typically a CPU, to a device, which may be a GPU or an FPGA or a DSP,
Starting point is 00:29:33 do the computation and then send it back to the host and then send the data we just computed back to the device to do the second computation and then send it back to the host and then send it back to the device to do the second computation and then send it back to the host and then send it back to the device for a third computation and rinse and repeat what's going to happen is we're going to fold everything into just one giant description of what we want to happen send it across with the data everything happens on the device and then it's sent sent back to the host exactly once and you're done now is this all uh
Starting point is 00:30:07 this process of building this description of what you want to do is this all something that you're doing at compile time as you're setting up this views of views of things or is this something that has to happen more at runtime so when you're building your description what you're going to do is you're going to do that at compile time things will there will be runtime components for example if you have a a vector of integers and you want and so that if you have that vector that's going to be the runtime component but saying that you uh you want to consider that vector alongside a single scale and you just want to have a thousand scale a thousand um sorry say you have a vector of a thousand elements and you want to pair every single element with the number 10 using uh using views you can actually compose that by saying you want to zip that vector or that range with a single value that's repeated for every element in the vector.
Starting point is 00:31:11 And then you can hand that along to something else that then will perform an operation. So that zip, that view of the world, becomes some compiled time thing that's probably unnameable and then you execute it execute it that's correct yes okay and now you're talking about fpgas and uh gpus and cpus and i wanted to clarify are you talking about like heterogeneous parallelism so that you might send something off and it would use all of these different devices at the same time or are you just
Starting point is 00:31:43 talking about choosing one of them to send things off to? Or some combination? I'm not as much of an expert on heterogeneous computing as some of my other colleagues that will be appearing very soon. But my understanding is that heterogeneous computing could be one or both of what you've just said, Jason.
Starting point is 00:32:06 So you could have it so that way you've got some sort of device that is very highly specialized for a particular operation. And so that one there will just do that one thing and then send everything back. And then you may send it to another device that's highly specialized. Or you could have things happening on multiple devices. But at the moment, my understanding is it's more of the former than the latter. Okay. So just one way of describing something and then choosing how you want to run it. Essentially.
Starting point is 00:32:36 With views specifically, we would have to have everything on a single device because what happens is you have an execution policy that really understands how one device works and it's suited for that particular device uh so well sorry so you're gonna say uh go ahead and finish your thought and then i'll come back to the execution policy so um what we uh what we have is with uh with a parallel stl STL, you have the regular component of the STL algorithms, which take the input component of the algorithm as iterator pairs, and then you'll have some sort of output or a lambda if that's relevant to the algorithm. And then what you'll have before all that
Starting point is 00:33:25 is what's known as an execution policy that describes how the parallel STL should interpret your algorithm. Should it be sequenced? Should it be happening in parallel? Should it be happening in some sort of parallel and unsequenced way, which is commonly known as vectorization.
Starting point is 00:33:47 And then implementers of the Parallel Steel are also free to provide their own execution policies. And for parallel ranges, we provide our own execution policy that has a lot of contextual data. So that way, the device is going to understand things and you don't accidentally send things to and from the device repeatedly, but this means that you're locked to using a specific execution policy for the device. You can't change it. So, uh, okay. So I'm curious about this, uh, uh, uh, uh, execution policy, but I kind of want to see if I can phrase this question in a way that makes sense.
Starting point is 00:34:29 So to me, one of the advantages of ranges is this kind of cleaner composability that you can take the output of something and immediately pass it into something else. You don't have to do this begin and end nonsense on it. And, you know, obviously you might have to pass in lambdas or whatever you want the operation to be also. And now I'm trying to imagine, like, if you've composed a bunch of different things and you've got this execution policy, do you pass like one execution policy in and it gets propagated to all the other things? Or do you have to choose which execution policy you want each composed portion of the view to execute? How does that like practically look? Okay. So that, that's a bit of my fault. I didn't explain that bit clearly. Sorry about that. So what happens is you, you build up this description where you say, I want to zip the repeated scalar with this, with this input range, and then you, you finish your description and that doesn't have any notion of parallelism or the execution policy. What you then do is you are given back a range. It hasn't been evaluated at all, but you're given back this view.
Starting point is 00:35:34 Right. So it is then passed to a parallel algorithm. And what that does is you give it the execution policy and you give it the range and then it goes, well, you're a lazy view. It's time for you to do some work. And then it takes that range and does things with it. Okay. I guess I was conflating these things or something in my mind.
Starting point is 00:35:59 Yeah. I see what you're saying. I wanted to interrupt the discussion for just a moment to bring you a word from our sponsors. PVS Studio is a static code analyzer that can find bugs in the source code of C, C++, and C-sharp programs. The analyzer is able to classify errors according to the common weakness enumeration, so it can help remove many defects in code before they become vulnerabilities. The analyzer uses many special techniques to identify even the most complex and non-obvious bugs. For example, data flow analysis mechanisms, which is implemented in the tool, has detected a very interesting bug in the protobuf project. You can read about this bug
Starting point is 00:36:34 in the article February 31st. The link is under the description of this podcast episode. The analyzer works under Windows, Linux, and macOS environments. PVS Studio supports analysis of projects that are intended to be built by such common compilers as Visual C++, GCC, Clang, ARM Compiler, and so on. The analyzer supports different usage scenarios. For example, you can integrate it with Visual Studio and with SonarCube. The Blame Notifier tool can notify developers about errors that PVS Studio detects during night run by mail. You can get acquainted with PVS Studio detects during night run by mail. You can get acquainted with PVS Studio features in detail on viva64.com.
Starting point is 00:37:17 You're also going to be giving a talk about ranges and concepts at CppCon this year, right? So I'm giving a talk about parallel ranges at Pacific++, and I'm giving a class at CppCon that is completely on concepts and ranges. So the class is titled Generic Programming 2.0 with Concepts and Ranges. And so that there is... It's going to dive into what concepts are and how we can use them,
Starting point is 00:37:44 and it's going to also talk about how we can make generic programming a lot easier using concepts and specifically using ranges and how they apply to algorithms and also what it is that builds up an algorithm, sorry, what it is that builds up an algorithm? Sorry, what word is that builds up a concept which is relevant to a specific set of algorithms? Okay, so between, I mean, effectively, we're kind of talking about C++20, right? Because ranges don't exist yet and concepts don't exist in C++17 yet.
Starting point is 00:38:23 So what tools do your students need to actually be able to use the techniques that you're going to be talking about? So I'm going to be providing a Docker image because with Docker, I can provide the right version of GCC. It's no longer experimental per se, But it's shipping with GCC. It has been shipping for a while. But you've got to turn on a special flag. So we'll be using a Docker image that will have the right version of GCC,
Starting point is 00:39:01 which will be the latest one. I think that'll be eight by the time the class rolls around unless gcc have changed their release pattern recently i think that sounds correct okay cool then there'll be the the library cmc stl2 which is the the reference implementation for the ranges ts and that's what we'll be using for a large part of the class but then for a small section we'll probably need to switch over to range v3 which is sort of like a it's a C++11 friendly version of the ranges TS with plus or minus a few extra things. For example there's actions which are range adapters like views,
Starting point is 00:39:46 but unlike views, which are lazy, actions operate eagerly. And so in order to talk about actions, which are still very relevant to using ranges, we'll need to switch over to range V3. And then I'll probably also just show that nanoRange is another range-based library as well, because that one there is an up-and-coming ranges library that is also, I've been using it in a personal project and it's been working out really well. Okay, so if you don't mind, I would like to take a quick step back and talk a little bit more about parallel and ranges. And I haven't used, well, I guess actually I want to take two steps back. The standards implementations are still lagging on the parallel STL for C++17, right?
Starting point is 00:40:36 And I've seen some reports from some of the implementers that talk on Twitter about how some of these algorithms are difficult to get good parallel performance from. And you said that you're seeing very promising results with parallelism and ranges. And I'm just curious if you've hit any of these things where you try to make something parallel and you're like, whoa, that was not worth it at all. We're just, you know, it's just destroying our performance here. So I personally haven't seen that. One of the other people who worked on parallel ranges may have seen that component. But a lot of the benefit with ranges coming to parallelism
Starting point is 00:41:19 isn't because ranges offer this thing for parallel programmers on the implementation of the algorithm as much as it gives users a way to combine everything into just one giant description and get the data across to the device. So that way they're not waiting on transferring data from one thing to another, which is where a big problem is.
Starting point is 00:41:45 There's a big bottleneck on latency when you're waiting for things to go across a bus. Okay. That's where we've been able to capitalize on our performance gains because we did some testing against a regular parallel STL and we were able to see up to three and a half times an improvement on various benchmarks.
Starting point is 00:42:12 We were able to see that kind of improvement because we were able to fuse everything together and send all the data across exactly once instead of sending it across once and then back and then forward and back the number of times that you need to do that for that particular benchmark okay so you can totally correct me if i'm oversimplifying this but it's sounding like you're almost using ranges like a dsl or something really like this is your description language inside c++ this is what we want to do and then that gives you everything you need to know at compile time to do the efficient things on the remote hardware or whatever. Yes, I think so.
Starting point is 00:42:54 You cut out for a little bit there, but that was the, from everything that I heard, which was most of it, I think. Yes, that's exactly a good way of summarizing it. Okay. Ranges as a DSL, basically. Essentially, yes. The way that I've explained it to people is that you have a shopping list and you write down what you want on the shopping list and then you go to the shop and get it. You don't go to the shops and get the one thing you need, then head home and then go back to the shops when you need the eggs to bake your cake and then head home and then get the vanilla flavoring and so on. Okay. So I currently, I have honestly no idea how ranges works with the current STL.
Starting point is 00:43:30 Like it, I don't know. I feel like if I'm hearing what you're saying, that there's a hole in the standard at the moment, but can I today take some, make a bunch of views, do my whatever with ranges and then pass that to a C++17 parallel algorithm today with the way the standard's currently written? I don't think that's the case because we have to provide our own SQL execution policy. And so just very quickly, at a very high level,
Starting point is 00:44:00 SQL is a C++ library for OpenCL that allows heterogeneous programming. And so we provide our own execution policy that provides all of the context there that's necessary for working on, say, a GPU, for example, and I've not actually tried it parallel ranges with, we'd say the Intel parallel STL to see whether or not the fusion is, is happening there as well. Okay. Yeah. It kind of, I don't know. It sounds like a missing piece somehow, if ranges can't play nicely with all the work that went into parallelism for C++17?
Starting point is 00:44:53 That would be a, so there is a proposal for parallel ranges that we're working on at the moment. And I think maybe for the next iteration of that paper, I don't know if it'll be for the upcoming San Diego meeting or if it'll be for Kona next year. But it sounds to me a good idea to now go away, take all the parallel ranges benchmarks that we've got and try it against the Intel Parallel Steel or the upcoming MSVC Parallel Steel. Have they completed their one? I can't remember. I don't, I think I would have heard if it was done.
Starting point is 00:45:30 So I don't think it's done, but I know an awful lot of work has gone into it. Yeah. So I think what I, what I, what I push for when I've got a bit more time to work on this is to actually start seeing if that's the case and then publish the findings in this particular proposal okay okay so that all started with our you know you're going to be giving a class as bpcon but you're also going to be uh giving a talk it's bpcon too right yes uh what's that talk going to be on that talk at the moment is title at the moment there were a few uh feedback uh it's in the feedback section when you um when you get your
Starting point is 00:46:13 acceptance letter you get some feedback and a few people had said i feel like this talk should be called something else um but i haven't thought of what something else should be yet uh but at the moment it's it's titled fun for all teaching c++ and when i was on last last year we did talk a fair amount about education and c++ uh and so what this talk is it started out as me wanting to deliver an open content session that i'd given at CPPCon 2017. And then again, as a C++ Edinburgh talk in December, I wanted to deliver that at CPPCon 2018.
Starting point is 00:46:56 But John got in touch with me and he said something to the effect of, look, I think this talk is great, but I think you've got a very classroom-oriented description here. Have you considered broadening that a little bit to talk about lunchtime sessions and week-long courses and so on? And I guess I had to stop and think about it for a moment. And Jason, I don't know if you ever taught in the university sort of framework, but I imagine that having a full semester to teach C++ is vastly different to what you're doing in just two or three days.
Starting point is 00:47:44 Yes, I would imagine that would be vastly different. So when, when Kate Gregory gave her stop teaching C talk a few years ago at CP Peacon, she, she mentioned that she had to make a class that was teaching C++ in a day. And I kind of did a spit take there because I thought C++ in a day is insane. But she's successfully managed to do that and you've successfully got classes running as well. So it's very obvious to me now, a few years later,
Starting point is 00:48:17 this is very possible. And so I haven't started working on this particular talk yet, but I'm going to be going through and seeing what can be delivered to help people make teaching C++ easier in multiple frameworks. or just a lunchtime knowledge-sharing talk, or if you do have the luxury of having a full 12 weeks to teach a class because you work at a university or a high school, then that'll be a little bit different. But I'm essentially going to be catering to a broader audience in this particular talk.
Starting point is 00:49:00 Okay. Sounds interesting. And you also were talking to us before the show started about an interesting experience you had at a different conference giving a talk recently do you want to tell us about that right so i was at a uh a conference called the wigner gpu day which is in budapest in hungary and so i was giving a talk on parallel ranges and the talk is incredibly visual. So there's a lot of code on screen with arrows pointing everywhere. And I was using a laser pointer and something I noticed was that a bunch of the talks were also like this. And so it's quite relying on eyesight here.
Starting point is 00:49:48 And there was a particular person who I'm fairly confident was blind. And so it kind of got me thinking, well, perhaps we should be looking at talks that also are able to cater for people who are vision impaired because not everyone will have the luxury of being able to see everything on screen. And even though they do fit into a minority, they should still be able to enjoy a larger portion of your talk and not miss out on what's happening in the really interesting sections, which may be what's happening on screen. And I haven't worked out a way to actually achieve this yet, but I do feel that, you know, things like coming onto CFPcast and talking about things
Starting point is 00:50:37 is a good way of getting practice of that. For example, here I've just had to talk about what parallel ranges are without showing you any of the code. Right. I have also received a comment on C++ Weekly on my YouTube channel from someone saying that they were vision impaired and they like listening to the video but would also be able
Starting point is 00:51:00 to, since it's a lot of live coding, be able to actually use their screen reader on the code. So I have to admit, I'm actually pretty terrible about remembering to put a Compiler Explorer link or something in the YouTube notes with that. But apparently that's for people who have Braille readers or screen readers, that's at least an option. I've seen a blind person actually give a talk, which is pretty interesting. And during his talk, he showed how he goes about his work as a programmer. And it's really interesting that he has a screen reader and it reads the code and kind of navigates him around the interface.
Starting point is 00:51:41 And it reads so fast that you and I couldn't make any sense of it. It reads like 5x speed or something, oh wow very fast so that he can be productive um but yeah it's really interesting i've i've seen that with demonstrations of how the uh the blind mode or whatever it's called for iphone works because someone who's vision impaired can use an iphone with literally the screen turned off all the time. So their battery lasts forever and it just reads what's on the screen and they can tap and say, I want that element,
Starting point is 00:52:10 that element, that element, whatever. And apparently are like more efficient than those of us who are actually looking at the screen. Right. Yeah. It's really interesting.
Starting point is 00:52:20 It's definitely something to think about when, when producing a talk. You know, it's, it's a hard problem to deal with but it's something we should all try to think of more especially with the amount of talks that get put online these days that's a good way for those people who do have impairments like that to access them right uh oh yeah sorry well is there anything else you want to talk about before we let you go Chris not particularly I think we covered everything
Starting point is 00:52:49 just Codeplay are always hiring so that's something that if you're interested in Hector Jenny's programming then definitely take a look at our website okay well it's been great having you on the show today and I'll put some links to
Starting point is 00:53:05 everything we talked about today on the show notes and look forward to seeing you at CppCon. Thanks Rob. I look forward to seeing both you and Jason at CppCon as well. See you there. Thanks so much for listening in as we chat about C++. I'd love to hear what you think of the podcast. Please let me know if we're discussing the stuff you're interested in,
Starting point is 00:53:23 or if you have a suggestion for a topic, I'd love to hear about that too. You can email all your thoughts to feedback at cppcast.com. I'd also appreciate if you like CppCast on Facebook and follow CppCast on Twitter. You can also follow me at Rob W. Irving and Jason at Leftkiss on Twitter. And of course, you can find all that info and the show notes on the podcast website at cppcast.com. Theme music for this episode is provided by podcastthemes.com.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.