You are not logged in.
I think Fortran is a good choice for computation. It works as its name suggests: just translating the formulas and no need to consider how your computer actually works.
The problem is: I can not find free libraries like GSL to do random number generating, minimization, etc. Some professors in our department are using sort of routines from Numberical Recipe, but many people say its performance is not good and it even has some errors. The MKL library from Intel looks complicated and it also lacks some minimization rountines I am looking for.
In C, GSL seems a very popular library for computation. I checked its manual and it contains all the things I need, but unfortunately there is no good interface for Fortran to use it.
So one solution is to switch to C. In fact C is my first language(almost 10 years ago), and every time I see some C code it just reminds me some good memories. I also appreciate the protability of C. So I would like to pick up C again if I have enough time to play around. However, pointers seem a lot of distraction and for now I just want to get things done quickly..
What's your opinion on this? Any idea will be appreciated and I particularly want to hear people from some computation backgrounds. (PS, I am in econ)
Offline
If you're just doing computation, I would probably suggest Python with NumPy (possibly supplemented by SciPy or StatPy -- not sure where you're going here). Keep in mind that Python is written in C and is pretty darn well optimized, possibly better optimized than the C programs you would have to write to get the equivalent computation done. From what I understand Python's performance at numeric calculations rivals C, although I have no personal experience here. There is also a GSL module for Python, PyGSL I think.
Offline
Hi, Trent, thanks for your response! I did try Python some time before. But the problem I am working on(dynamic programming) needs a lot of loops, which will slow down any interpreted language in the end I guess. That's why I need to go back to some low level language like Fortran or C.
I am thinking to combine C and Python to do the work in future. I am just not sure how long it will take for me to pick up C... and how it will work for my problem...
Offline
Have a look at this: www.sagemath.org.
It uses cython, which is, essentially, a compiled python, so in many cases much faster, and the whole project is directed at mathematics.
larch: http://larch.berlios.de
Offline
Cython is good thing, Sage is good too - but if it doesn't give you enough power, it might be good thing to move into cloud. There is very simple - also python based solution - PiCloud - where you can make all your calculations in cloud within minutes at price of single beer It's kind of layer on top of Amazon EC2, making managing your own Python app in cloud a snap, automatically uploads your code trough cloud and there are lots of python libraries already installed/optimized on each node - check http://www.picloud.com/ - I have package for it in AUR, but you still need to register to get API key to sign your tasks.
My GPG fingerprint: 7170 26A9 D477 9FC5 3940 7266 40F5 57B7 3149 6106
Offline
Second for Numpy. The concern with looping seems unwarranted. If anything, you will need much less looping. Case in point, the 1D Haar transform. The first inner for loop has been replaced with a pair of list slices, [0::2] and [1::2]. (Those give the even and odd elements, respectively.)
side note: All the heavy lifting is done with Blas and Lapack, both very fast C math libs. It should not be that much slower than straight C. I really need to do some benchmarking.
Numpy:
def haar1D(vec):
"[(-0.5 to 0.5)] -> [(-0.5 to 0.5)]"
w = len(vec)
while w > 1:
s = (vec[0:w:2] + vec[1:w:2]) / 2.0
d = (vec[0:w:2] - vec[1:w:2]) / 2.0
vec = n.concatenate((s, d, vec[w:]))
w = w / 2
return vec
Compared to the original C code (from http://www.cs.ucf.edu/~mali/haar/):
void haar1d(float *vec, int n)
{
int i=0;
int w=n;
float *vecp = new float[n];
for(i=0;i<n;i++)
vecp[i] = 0;
while(w>1)
{
w/=2;
for(i=0;i<w;i++)
{
vecp[i] = (vec[2*i] + vec[2*i+1])/sqrt(2.0);
vecp[i+w] = (vec[2*i] - vec[2*i+1])/sqrt(2.0);
}
for(i=0;i<(w*2);i++)
vec[i] = vecp[i];
}
delete [] vecp;
}
(I am reasonably certain the whole sqrt(2) thing was a bug. Have not found it in any other literature.)
Last edited by keenerd (2010-05-02 13:18:09)
Offline
In my experience, python has been way after C and FORTRAN in terms of speed at number cruching (having a big advantage in terms of time of coding). Have you tried with FGSL: http://www.lrz-muenchen.de/services/sof … l/fortran/. It is no complete, but may have all the bindings you need.
Also, I think normally MKL is a good alternative. I remember that some time ago the documentation came with good FORTRAN orientation. Maybe if you can grab an older document you will find examples, and a way to translate the syntax from C to FORTRAN. Are you sure they don't have minimization? or is that you are looking for a very specific way of doing it?
A third alternative that pops into my head is to use C++. If your problem are the pointers and the mess that comes with low level programming, you can try to use one of the several STL Containers, which are quite easy to use and still efficient with numbers. The down side is that probably you will have to copy them into normal arrays to use the GSL functions, but is not as bad as it seems.
Last edited by olvar (2010-05-02 13:16:25)
Offline
I am kind of partial to Octave. But how about the best of both worlds? Take a look at the Pytav module. https://launchpad.net/pytave
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
In my experience, python has been way after C and FORTRAN in terms of speed at number cruching (having a big advantage in terms of time of coding).
If you write your number-crunching functions in pure Python, then yes, it is much slower. If you write the number-crunching functions in C or another such language then compile them into a Python module using bindings, then no. You still take a hit on the control structures and anything else in pure Python, but that should be negligible if you've structured your program appropriately.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline