THESE FORUMS NOW CLOSED (read only)

  • 03 Feb 2023, 06:05
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Programing question  (Read 3273 times)

Scytale

  • Guest
Programing question
« on: 13 Feb 2007, 23:36 »

Here's something I'm throwing out to all the code monkeys that post here, I think theres a few anyway.

 I've just moved departments at work and I've been giving the task of upgrading an old engineering simulation model we have, the model currently runs on an IBM RS/6000 (RISC based AIX server). It's pretty intense, most fo the code is written in Fortran with smatterings of C and COBOL!!!.

There are a few requirements, the main one being that it has to run fast, it's a pretty complicated model it typically runs over about 10,000-20,000 itterations for a simulation, it's programmed to stop when a suitable value of convergence is met. The other big drama is accuracy and floating point precision. This thing is old, it has to be compiled using the compiler in Fortran '77 mode as it doesn't support fortran '90 for some reason. I believe all the floats are only 8bit. Also it has to accept it's inputs from .dat files, being that most of the data for it is now stored in proper databases I'd like to use SQL, which should speed it up a bit as well (fewer file read operations).

I'm pretty tempted to re-write the whole thing in C, since I'm pretty sure I can get it to run a lot faster (this means a lot of manual memory allocation etc). Obviously something this old and this big it's going to be a hassle. I have to admit thhough I'm only semi comfortable with C, i'd much rather work in a nice modern O.O language like say Java, I'm pretty sure this isn't a good idea.

So a couple of questions,

How does a RISC processor effect floating point precision, will this be more dependent on the architecture or the compiler, ideally I would like to make this model as portable as possible.

Java, is it complete ludicrous to expect a high level langauge like Java to be able handle all this intense number crunching.

has anyone done anything similar with upgrading programs written in Fortran, I'd never seen any Fortran code till this morning...


Logged

dennis

  • Asleep in the boner patch
  • ****
  • Offline Offline
  • Posts: 776
  • A sockful of quarters makes the medicine go down.
    • Lies! Truth!
Re: Programing question
« Reply #1 on: 14 Feb 2007, 05:06 »

This is pretty much out of my league. If you know any engineers there, talk to them. If they're over 30, chances are they love them some Fortran 77. I know they did in my department. Except I chose to learn C++.
Logged

JJMitchell

  • Guest
Re: Programing question
« Reply #2 on: 14 Feb 2007, 05:17 »

I would say that while Java is probably capable of doing it there might be better options.  c++ isn't a bad option of the ones you mentioned.

Beyond that I can't really give much advice other than to say my inner geek just had a little orgasm and I'm totally jealous that you have a job where this is a problem.
I'm off to setup some mortgage shit.  *pouts*
Logged

Scytale

  • Guest
Re: Programing question
« Reply #3 on: 14 Feb 2007, 05:48 »

I actually an engineer rather then a programmer and yeah a lot of the older guys do love Fortran, though they also speak fondly about Vax... I borrowed a big manual off my new boss actually...

C++ is a good option, though I don't think it will perform as well as C, should be easier to write though, the only thing I've ever written in C++ has been very simple GUI apps for fun (using GTK), my familiarity with it's library's is not that good, unlike C, which I used at Uni.

My sister who's a bigger geek then me and is studying for her masters in Comp Sci at the moment reccomended I use a functional langauge like Haskell or Lisp, they seem pretty powerful, especially for a lot of the stuff I'm trying to do like converging series and things but I'm pretty sure I'm going to have all sorts of difficulties with setting up the environment getting a working compiler etc.

I'm going t ospend a few days playing with it and getting to know the source code before I make any decisions.

Logged

JJMitchell

  • Guest
Re: Programing question
« Reply #4 on: 14 Feb 2007, 05:58 »

Actually I do some work in Scheme (a derivative of lisp) and can say that it is a very light weight language.  It is also a pita to get used to the syntax if you have done much other programming.
Logged

Catfish_Man

  • Pneumatic ratchet pants
  • ***
  • Offline Offline
  • Posts: 369
    • Assorted Stuff
Re: Programing question
« Reply #5 on: 15 Feb 2007, 08:33 »

Some random thoughts:

Fortran is still sometimes used for numerical code, iirc primarily because the lack of pointer aliasing makes it easy to optimize. If performance is truly critical, a) USE A PROFILER, b) see a, c) check your data structures and algorithms, d) investigate things like restrict, pure, and register, or getting out the inline asm.

POWER/PowerPC (RS/6000s are POWER based these days, no? If not, ignore me) has a fused multiply-add instruction, which is slightly higher precision and higher performance than a multiply then an add.

Higher level languages than C: It'll depend heavily on allocation patterns, amenability to JIT optimization, etc... impossible to say how it would perform without a great deal more information about its behavior. It's quite possible that garbage collection would actually be rather fast, since you don't need to use a non-pausing collector for noninteractive stuff like a simulation, and you could probably take advantage of the iterative nature (schedule a collection after each iteration or N iterations).

Be careful with the precision stuff; there are situations where higher precision isn't as important as matching the expected precision/behavior.

Functional languages (Haskell would be preferred to LISP derivatives imo): the main advantage you'll see from these is parallelization. If your algorithm is inherently serial I would not bother with them, although I admit Haskell does some really neat correctness checking with its type system. Certain types of problems are also just very easy/concise to express in functional languages (like, the code to say "make me a list of all the prime numbers" in Haskell is fairly trivial, and due to lazy evaluation does not actually use infinite memory). I still can't stand 'em in general. Hurts my object-oriented brain ;)
Logged

Scytale

  • Guest
Re: Programing question
« Reply #6 on: 16 Feb 2007, 01:12 »

hmm cheers for the advice.

I've spent the last two days at work pouring over doccumentation and source code and I've just about got my head wrapped around it all now.

Being that most of the algorithms used were written by people a hell of a lot smarter then me I'll probably be leaving them alone, just porting them over wholesale (this model is pretty complicated, does stuff with fluid dynamics, gas kinetics and chemical equilibria etc). Luckily it's divided into a set of "sub modules", one part controlling temperatures, one part, chemical kinetics etc, means I can concentrate on porting it over 1 module at a time. C++ is looking like a good option at the moment as the OGS system it feeds into is also done in C++ theres a wrapper at the moment which handles the output for the fortran, theres a whole API set up for the OGS/Control room environment, complete with it's own 238 page manual :( !!! So by taking advantage of C or C++ I can leverage off that a bit, will make life a lot easier.

Logged

Fiddler

  • Guest
Re: Programing question
« Reply #7 on: 16 Feb 2007, 10:11 »

Without spending a lot of time with all this legacy code myself its kind of hard to give much useful advice but I'd say using C++ is appropriate and its not like you cant implement using C lib's too if thats what you know. 

Catfish knows his stuff too because everything he said is true, and I completely agree that the functional languages, while cool at times, are just a head ache if you are used to OO. 

If at all possible convince them to move the data into SQL databases instead of .dat files because that would seriously speed things up.  I cant really think of any reasons why they would'nt want the input to be straight from a database in this case.  Its alot easier to put new data into the system that way.  If they already use databases for everything using .dat files would just mean you'll end up having duplicate copies of the data in separate spots and then when you back it up your saving both those files as well, its just a lot of wasted memory and time either way.

C++ code is more my thing though.  Most of my work has been coding with it so any problems you have in that department I can actually give more useful answers for haha.
Logged

Scytale

  • Guest
Re: Programing question
« Reply #8 on: 20 Feb 2007, 03:28 »

I had a major breakthrough today I finally got the f%$# Fortran code to compile.

We had all these dramas in the office, the Fortran compiler we had (some insanely old POS) kept giving stack fault errors and wouldn't compile properly.

Work was prepared to buy me a new Fortran compiler, I protested, seemed like a waste of money for licensing etc.  A quick google search later and I have MinGW and the GNU Fortran compiler working, might I just say how much of a good idea MinGW is I've used Cygwin before but this is like 10* lighter only big drama was that posix signals aren't supported.  Another win for Free Software I say, i now have a working and free Fortran compiler and I can run Vi, so I have a nice IDE as well (I'd been using notepad to edit files for the last week  :x)...

Our IT department are incredibly anal and these PC's are locked the hell down so it virtually impossible to install any new software on them, going through official channels can take months, sometimes I just wish they'd let us have a few *nix boxes for development, would make things a lot easier imo...

Anyway now that Fortran version is working I have something to compare the output from the updated version of the model (which is comming along pretty well so far I think...) with.

Logged

Scytale

  • Guest
Re: Programing question
« Reply #9 on: 22 Mar 2007, 06:20 »

I thought I'd bump this topic again, because the model is comming along pretty, well and I'm now working on the database side of it, trying to hook the "back end" of the model into our database.

I've got a bit of a question about resizing dynamic arrays in C++ and was wondering if anyone here has any experience with this sort of thing, I'm pulling recordsets out of the database, obviously  I don't know in advance how many recordsets the select query will return (it's a dynamically generated query, calls on user input for dates etc), I've set up a struct to hold each row of data in as it's returned and thats working fine, performance is pretty decent at the moment. I can access each field of the row by manipulating the struct.

What I want to do is store these structs in a collection somewhere so I can manipulate them etc, at the moment the struct with a row's data goes out of scope and is over written as soon as the while loop re-iterates.

I've got a bit of a hack setup at the moment involving a pair of static arrays and calls to "new". This of course introduces the dreaded buffer overflow error. I'm considering inserting some straight C calls and whipping up the C "realloc" verion of a dynamic array, but I've notice C++ has a "vector" class defined in the standard template library, anyone used this before, if so whats the performance like?

Also a guy a work suggested using a linked list or some other datastructure like that to store the recordsets, It's a good idea but before I try to re-invent the wheel I thought I'd ask around and see whats out there.

Logged

Catfish_Man

  • Pneumatic ratchet pants
  • ***
  • Offline Offline
  • Posts: 369
    • Assorted Stuff
Re: Programing question
« Reply #10 on: 22 Mar 2007, 16:05 »

In general the STL version of any given data structure will be faster than one you write yourself, unless you're willing to put a good deal of time and expertise into optimizing it for your specific situation. The trick is looking at your access patterns, data set, and priorities and deciding which structure is best suited to the task.
Logged

Fiddler

  • Guest
Re: Programing question
« Reply #11 on: 23 Mar 2007, 09:23 »

Halfway through your post I was already thinking about the Vector class.  C++ Vectors arent as great as the Java versions just because the Vector class is a little older now.  But you'll get good performance out of them and it will make your code a lot cleaner thanks to Vector's data handling methods.  It has functions to handle pretty much everything your going to want to do with an unordered linked list so I'd reccomend it.
Logged
Pages: [1]   Go Up