4 ms·
I always find code samples of SIMD instructions to be so esoteric it makes it harder to follow that necessary. It's 2020, who uses variable names like 'acc', '
by grecy 6y ago
I always find code samples of SIMD instructions to be so esoteric it makes it harder to follow that necessary.
It's 2020, who uses variable names like 'acc', 'a' and 'b'?
There's also no real explanation of what 'a' and 'b' (or 'p1' and 'p2') actually are. It's just magic.
I get that it's just an example, but the example feels so useless it doesn't demonstrate why these SIMD calls are helpful at all.
- chrisseaton 6y ago> It's 2020, who uses variable names like 'acc', 'a' and 'b'? Mathematicians, scientists, engineers, artists. Have you read any numerical work? They often use one-letter variables, or otherwise very abbreviated variables. Sometimes they differentiate variables with the same letter using by using different fonts. Seems strange to us, but clearly it works for them! And then they keep doing the same thing when they translate to code. When I ask them they say they think our long variable names are unreadable. Maybe they're right and we're wrong? Who knows. They generally don't use tests, linting, CI, anything like that either. But again, clearly it works for them!
- superjan 6y agoIf you write code that does basic arithmatic, a and b will do just fine in my experience. If I’m implementing an existing algorithm, I like to stick as close to the algoritm’s symbol use as close as possible. I miss that I can’t use greek symbols like ϕ or σ as variables, but that’s just me probably.
- chrisseaton 6y agoWhen I try to implement an algorithm from a paper, I try to rename the variables from Greek letters in German fonts to have simple English names, but the scientist will say 'why are you making it more complicated!' I feel like we'll never understand each other!
- minerjoe 6y agoDepending on your programming language, you can definitely use those greek symbols as variables.
- sgillen 6y agoYup was just about to say this. That being said I usually avoid doing this even though I do a lot of numerical work. They are usually more of a pain to type out, and I don’t trust that they will show up properly on every text editor that it might wind up in.
- cinntaile 6y agoI believe you can do this in Julia and possibly other languages as well.
- zoomablemind 6y agoWhen transcoding the formulas from CAS (comptuer algebra), the Greeks are often already spelled out in English transliteration (phi, sigma). Even more, sometimes for clarity or performance reasons it may make sense to introduce interim variables, I often name those just as what they'd look like in formula, say, pi/2, would be PI_2; A*B is kept in AB, or AxB depending on context. So many times the encoded formulas end up hiding accidental errors resulting from a desire to use programmer's names. With scientific code, it's safer to stick to formulas, as it's just easier to eyeball them or outright copy and paste to/from CAS for cross-check. Of course, it's paramount to have proper test-cases to make sure the encoded formulas match to the expected results.
- OnlyOneCannolo 6y agoWhen people do this, they're usually following a convention where those short symbols are understood to mean certain things in that domain. If there's documentation describing what the code is doing and why it's doing it, that can be much more useful than longer variable names.
- The_rationalist 6y agoAcc means accumulator and is a standard name when using e.g a fold/reduce functor. That being said, single letters or non standard abbreviative variable names are a cancer to code clarity as the semantic of what they denote become unaccessible.
- creato 6y agoThere's no context here, why would it matter what the variables are? Do you really need 'a' and 'b' to be named 'add_operand_1' and 'add_operand_2' to understand what they are? Same with 'acc', is it not obvious what it is from the context? Unnecessarily long names can be less readable too. If a variable's lifetime is only a few lines long, and the meaning is obvious from the context, a single letter name might be best. As for the example: if you think a dot product is useless, then maybe SIMD really is not useful for you, and you can forget about it if you want.
- Const-me 6y agoSorry about the confusion. I’m not a professional writer, quite the opposite, I’m a professional programmer. acc stands for “accumulator”. p1 and p2 are two pointers, of type const float*. You’ll find more context on github, here’s the repository with these samples: https://github.com/Const-me/SimdIntroArticle https://github.com/Const-me/SimdIntroArticle