IBM

Compiling xlC with C++11 support
- Page 1

So, I write in C# every day at work, but thought to myself a few weeks back I'd try and get back to C/C++ that I studied back around the late 1990s (but never used).
I followed a few examples and got carried away on one on factorials, which I turned into a lotto draw program to try and predict the most common numbers drawn and in actual fact, by the time I'd finished, the factorials part had gone lol. I doubt it will ever produce the correct numbers but it was a fun exercise.

This program works fine when compiled and run with Visual Studio 2013 on Windows Intel but I wanted it to compile and run on IBM AIX xlC 13.0. Programming in Windows is pretty easy in that all I worry about is the .net version I'm building in and the relevant references.

In the program I reference stoi which I know is a C++11 standard and by rights the version of xlC should support, if I compile with the correct arguments. Alas it doesn't or more probable, I'm doing something wrong.

a bit OT, about including-troubles (what have I to include <WTF?>? have I included <What.The.Frog> I need? -> so boring to care about!) I am working on a special tool that automagically produces
inter-module-dependencies

Pros and cons, a shortening of the Latin expression "pro et contra" (for and against)

PROs
: you can forget these troubles, it will automagically generate interfaces, dependencies, so you can be focused on the project

CONs
: it requires the project to be written in a specific way, strictly compliant with {
MISRA
&&
DO178A
&&
MIL-STD
&&MY(2) } (1)

If I will ever design a
SafeC compiler
these features will be included by default (can I ask for funds on
Kickstarter
?)

(1) because I am too lazy to support whatever can be written with the full C grammar
(2) MY, my way, I have other directives and rules that need to be applied, early discussed
here
, LOL

ClassicHasClass wrote:
Sounds like an issue with the standard library? Are you not including the right header?

stoi
is a function introduced with C++11.

I don't know the options the OP is passing to the compiler. But I believe xlC needs the "–qlanglvl=extc1x" flag to activate the C++11 features in the compiler. But I don't know if
stoi
is supported, since last I checked xlC only had partial coverage for the C++11 standard (I could be wrong). If that is the case, the OP can still use
atoi
or
stringstream
which do not depend on C++11.

"Was it a dream where you see yourself standing in sort of sun-god robes on a
pyramid with thousand naked women screaming and throwing little pickles at you?"

Instead of blowing against the wind, I changed my super lotto program to work on IRIX, AIX & Windows using ostringstream to convert the INTs to Strings.

First off the board was the random seeding issue. which I had implemented wrong in the first place but it did leave me wondering..
Basically the program:
Generates as many random lottery draws of 6 numbers as inputted by the user.
Adds a count of each number drawn.
Calculates the highest drawn 6 & the lowest drawn 6.
At first this was done through a loop which went through the list sequentially, but that proved to be biased towards the end numbers in the loop, so say number 1,4,5,6,7,8,10 had been drawn 100 times, number 1 would always be pushed off the list. To counter this, each number taken from the list index was also a random number, so 10 could be checked first and maybe 1 last.
Each time a random number was obtained, a new seed was created and this was my mistake.
The IRIX, AIX compile would always get stuck finding the last 2 entries in the list index whilst sorting, yet the windows always worked fine, this had me scratching my head with possible timing issues. I had a loop to delay the time for the new seed by 1 second, and yet it was never able to sort the last 2 numbers.
I changed this to produce a single seed at the beginning, all was well and I was able to remove any sleeps, pauses or loops. To speed things up further, I may remove each entry checked from the list and reduce the random number for the list index sorting.

The AIX can produce a 10,000 lotto sample in about 4 mins, as does the windows machine which is an i7 - Quite impressive I thought. The SGI (300MHz Octane2 - 1.5 GB of memory) is still running and has taken half an hour so far.

Below is the code taken from the windows machine because I'm on it right now. It's exactly the same apart from a few headers in and out.
I may do some time trials on my machines and maybe win the lotto in the process.

Well, from a simple programming perspective rather than a performance optimising perspective, you need to learn the wonders of arrays a bit more and how they can cut down on repetition of code. You've used them a bit, but you could shorten that code by a good hundred lines or more by replacing loads of your other variables with arrays and then optimising other passages of code accordingly.

This isn't going to fix the IRIX performance of it I don't think, but it'll make it a lot more concise and easy to edit. Note that as I'm used to using a C++ compiler to do my coding, you may need to change the bool bit to an int, or use a C library if you're wanting to use pure C here.

This one will improve performance slightly as you're not having to create a variable, initialise it to zero, set it to another value, then destroy it every time you want to grab a random value. This is for starters anyway

Yup, that was implementing all your changes, changing everything to arrays etc.. I'm now running a 1,00000 sample draws. I've added the ability to add the number of draws as an argument so that I can #time ./a.out 1000000

IBM returned 1,000,000 in 40Minutes 53Seconds.
Octane returned 1,000,000 in 1Hour 45Minutes 37Seconds

ALAS.. the improvement wasn't as much, but still worth it.. I found a delay loop still in the old program.
The memory taken up are both very similar before 3744k after 3760k
Pre clean-up 10,000 1Minute 27Seconds
Post clean up 10,000 1Minute 19seconds

Must not forget that, it's a random program, so whatever algorithm, one could still take longer than the other.

Indeed..
I'd like to test if it utilizing both CPUs by restricting it to a single CPU, If I Recall Incorrectly.. what is the command runonone ? Am I thinking of a smoke/jaleo command?
It does use both CPUs we can see from top. Further testing with a new machine introduced: