Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: September 18, 2019, 1:11 am

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bit flipping
#21
RE: Bit flipping
(April 24, 2016 at 3:22 am)Mathilda Wrote:
(April 23, 2016 at 11:40 pm)Tiberius Wrote: What was her reasoning for making the code so efficient? I mean, it's great to write efficient code, but that's usually something you do in advanced programming classes rather than a discrete math class.

Bloody Mathematicians always write the worst code. Literally. You try refactoring their code and it's all variable names with single letters that you can't search for to check whether there is a side effect. Or non descriptive short function names that give no clue as to what the function does. The mindset of a mathematician is that you automatically know everything about their code.

The lecturer should be sent on a software engineering course.

I should have clarified, she's the Computer Science Department Chair, and this is Discrete Maths for Computer Science, so everything is angled towards that bent.
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great

PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Reply
#22
RE: Bit flipping
(April 24, 2016 at 3:41 am)pocaracas Wrote: The craziest thing I've seen is the equivalent of a function call as a pre-compiler define. As long as you keep variable names consistent...it works.

These are common in C (specifically the gcc compiler) , and they work exactly the same as ordinary functions - by the time they go from thr pre-compiler to the compiler, they are ordinary functions.

What language/compiler are you talking about?

The weirdest thing I've ever seen is everything written in Perl, ever, that was not used for listing rubbish. I have had to wrote - not by choice - far more Perl than I would wish to admit to.
Reply
#23
RE: Bit flipping
(April 24, 2016 at 3:41 am)pocaracas Wrote: I've had to write code for real time control...and have seen similar code written by someone with far more experience than me.
I tell you, it's worth knowing how to save CPU cycles, memory, stack, etc...

In anything CPU intensive and/or long-running, absolutely.

A lot of code is so I/O bound that non-I/O related code is often not worth much optimization. These days it's cheaper to just throw hardware at the problem in general purpose computing.

With the kind of work you do, the datasets you work with, you probably can use all the optimization you can get. I do boring business software, very little is worth the trouble, though I am currently working on a project where it matters because the unoptimized solution would require over a hundred servers. Even then we opted for a third party solution rather than roll our own.
Reply
#24
RE: Bit flipping
(April 24, 2016 at 4:46 am)Cthulhu Dreaming Wrote:
(April 24, 2016 at 3:41 am)pocaracas Wrote: The craziest thing I've seen is the equivalent of a function call as a pre-compiler define. As long as you keep variable names consistent...it works.

These are common in C (specifically the gcc compiler) , and they work exactly the same as ordinary functions - by the time they go from thr pre-compiler to the compiler, they are ordinary functions.

What language/compiler are you talking about?
C++, it was.
And the purpose of it was to prevent function calls, added stack, and variable copying/passing.
We may think of those as "fast" events, but when every CPU cycle is precious, any trick is valid... Even if the CPU is an Octa-core, with hyperthreading and churning at some 3.6 GHz (a Xeon, I think it was).


Quote:The weirdest thing I've ever seen is everything written in Perl, ever, that was not used for listing rubbish. I have had to wrote - not by choice - far more Perl than I would wish to admit to.

I've only had to adapt a simple script in Perl, so I can't say much about it.
Reply
#25
RE: Bit flipping
(April 24, 2016 at 5:42 am)pocaracas Wrote:
(April 24, 2016 at 4:46 am)Cthulhu Dreaming Wrote: These are common in C (specifically the gcc compiler) , and they work exactly the same as ordinary functions - by the time they go from thr pre-compiler to the compiler, they are ordinary functions.

What language/compiler are you talking about?
C++, it was.
And the purpose of it was to prevent function calls, added stack, and variable copying/passing.
We may think of those as "fast" events, but when every CPU cycle is precious, any trick is valid... Even if the CPU is an Octa-core, with hyperthreading and churning at some 3.6 GHz (a Xeon, I think it was).


Quote:The weirdest thing I've ever seen is everything written in Perl, ever, that was not used for listing rubbish.  I have had to wrote - not by choice - far more Perl than I would wish to admit to.

I've only had to adapt a simple script in Perl, so I can't say much about it.

I'm guessing those pre-processor macros define inline functions - from what you've described.

I never personally got into C++, I did a little bit professionally but I'm far from expert. I would guess 80% of my career has been ANSI C, with most of the rest being Perl and Java.

I definitely agree that in your line of work avoiding a couple of stack operations, etc should be eschewed for keeping it in registers. I can imagine you have data analysis jobs that take hours or days to run. Every optimizion counts when you iterate over that much data.

Of course you already know this, this is more meant for other readers.
Reply
#26
RE: Bit flipping
BTW, have you ever tried turning off hyperthreading? My IT guys run our virtual server hosts that way because the performance is supposed to be somewhat better. I'd guess it would have something to do with same core context switching overhead, but I'm not really a hardware guy anymore.
Reply
#27
RE: Bit flipping
(April 24, 2016 at 4:46 am)Cthulhu Dreaming Wrote: The weirdest thing I've ever seen is everything written in Perl, ever, that was not used for listing rubbish.  I have had to wrote - not by choice - far more Perl than I would wish to admit to.

My first job was a nightmare project written in Perl by someone who was learning to code. There was one line of documentation. It was called the hand-off system and apparently it handed off from CVS ... whatever handing off meant. No one really knew.

Worst thing about Perl programmers is when they say that Perl is great because you can do anything with it. Well perhaps, but I'd rather that Perl programmers didn't do anything and just stepped away from any computers and took up gardening instead.
Reply
#28
RE: Bit flipping
(April 24, 2016 at 7:21 am)Cthulhu Dreaming Wrote:
(April 24, 2016 at 5:42 am)pocaracas Wrote: C++, it was.
And the purpose of it was to prevent function calls, added stack, and variable copying/passing.
We may think of those as "fast" events, but when every CPU cycle is precious, any trick is valid... Even if the CPU is an Octa-core, with hyperthreading and churning at some 3.6 GHz (a Xeon, I think it was).



I've only had to adapt a simple script in Perl, so I can't say much about it.

I'm guessing those pre-processor macros define inline functions - from what you've described.

I never personally got into C++, I did a little bit professionally but I'm far from expert.  I  would guess 80% of my career has been ANSI C, with most of the rest being Perl and Java.

I definitely agree that in your line of work avoiding a couple of stack operations, etc should be eschewed for keeping it in registers.  I can imagine you have data analysis jobs that take hours or days to run.  Every optimizion counts when you iterate over that much data.

Of course you already know this, this is more meant for other readers.

When working on something that may take a long time to process, we use IDL or Python, or Matlab... much easier to code in... and, of course, it then takes longer to process (than if it was written in C... or even JAVA).

There are some applications that must run "in real time"... acquire data, process it and provide some output that drives something to act upon the plasma... and the processing must be accomplished in less than a preset time - we usually operate either with 50 or 100 microseconds.
For these, yes, we turned off hyperthreading, fixed the linux kernel (if it works with one, stick with it!), used cpu core isolation (with the isolcpu setting in GRUB) and assigned the process to run on those isolated CPUs with taskset.
Reply
#29
RE: Bit flipping
Yes... Perl can look like awk, sed, C-like languages, and probably more I can't remember. Nothing like having a project that uses multiple styles, often badly.

Larry Wall ought to be taken out to the server farm and be forced to enter PDP-11 bootstraps for an eternity.
Reply
#30
RE: Bit flipping
(April 24, 2016 at 7:38 am)pocaracas Wrote:
(April 24, 2016 at 7:21 am)Cthulhu Dreaming Wrote: I'm guessing those pre-processor macros define inline functions - from what you've described.

I never personally got into C++, I did a little bit professionally but I'm far from expert.  I  would guess 80% of my career has been ANSI C, with most of the rest being Perl and Java.

I definitely agree that in your line of work avoiding a couple of stack operations, etc should be eschewed for keeping it in registers.  I can imagine you have data analysis jobs that take hours or days to run.  Every optimizion counts when you iterate over that much data.

Of course you already know this, this is more meant for other readers.

When working on something that may take a long time to process, we use IDL or Python, or Matlab... much easier to code in... and, of course, it then takes longer to process (than if it was written in C... or even JAVA).

There are some applications that must run "in real time"... acquire data, process it and provide some output that drives something to act upon the plasma... and the processing must be accomplished in less than a preset time - we usually operate either with 50 or 100 microseconds.
For these, yes, we turned off hyperthreading, fixed the linux kernel (if it works with one, stick with it!), used cpu core isolation (with the isolcpu setting in GRUB) and assigned the process to run on those isolated CPUs with taskset.

All smart moves! Great
Reply



Possibly Related Threads...
Thread Author Replies Views Last Post
  Coin Flipping Poll Tiberius 15 4123 April 19, 2010 at 1:00 pm
Last Post: Violet



Users browsing this thread: 1 Guest(s)