2
$\begingroup$

I am writing a global climate simulation software system. My idea is the following :

At the top of everything, I interface to the OS using D, a very powerful language for compile time code generation. The D code gets environmental variables, finds necessary input data, and then according to the config files, initiates Lua codes.

Lua is a pretty fast language used in many games, and the good thing about it is that it offers certain dynamism, considering the the lanuage is not typed, variables can have any type - this is very nice to have to account for polymorphism. ( Iknow fortran can support polymorphism, but Lua is comfortable)

Finally I want to convert the polymorphic data back to static data just in time of computation and call Fortran or Python methods, or may be even C. For this, I will use pipes - or fifos, based on the requirements.

My question would be: can Fortran / C / Python handle pipe and fifo without loosing much of its speed?

$\endgroup$
5
  • $\begingroup$ + Welcome to the site. I've got a lot to say about performance, and mostly it is not to prejudge anything, but to wait and see what actually takes time, and then fix it, because it won't be anything you could guess. That said, since I/O is basically a system function, the only way any run-time library can slow it down is by spending time formatting/unformatting data. I do binary I/O if I/O is taking too much time. $\endgroup$ Commented Jul 21, 2014 at 13:29
  • $\begingroup$ The question is perhaps a little unclear. Why not just do everything from Lua? Or D if you need the performance? And why use sockets and not just call C/Fortran/python directly from Lua? A little more info would be nice :) $\endgroup$
    – LKlevin
    Commented Jul 21, 2014 at 15:22
  • $\begingroup$ I would prefer D for writing comfort - it is very capable of compile time code generation. $\endgroup$
    – Sean
    Commented Jul 21, 2014 at 18:33
  • $\begingroup$ Do you want to call Fortran/C/Python functions from Lua, or D? Most languages have a foreign function interface to C, so calling C functions typically isn't a problem, and then the operative question becomes, "Do I have to call Fortran and Python via C?" Cursory research suggests there are interfaces to call Python code from both D and Lua, and that you'd need to call Fortran code via C in both languages. Like LKlevin, I also don't understand why you want to use sockets. $\endgroup$ Commented Jul 21, 2014 at 18:48
  • $\begingroup$ I want to call C/ Fortan methods from Lua, and I know how to do it. But I will loose some performance on the interface. Question is, which language, when combined with Lua is the least lose of performance. $\endgroup$
    – Sean
    Commented Jul 21, 2014 at 21:27

2 Answers 2

6
$\begingroup$

This is probably not the answer you are looking for, but I wanted to state it anyway: Your choice of programming languages introduces two difficulties you will encounter as your program grows.

First, you will find that there is a cost to trying to couple different languages. They may interoperate, but there is always some quirk to it and as your software grows, you will find annoying incompatibilities (e.g., layout of structures, name mangling, etc), and they will turn out to cost you a significant amount of time, energy and patience. The fewer languages you couple, the less gray hair you will have in a year. That your program may be 5% slower will, in hindsight seem like a small price to pay.

Second, D and Lua may be fine languages, but they are not widely used. If this is a project that you are sure you will never share with anyone, then this is not a problem. If you anticipate that someone else will eventually collaborate on it, or work with it, you have to anticipate that they do not know D and/or Lua. They may also not agree with your choice and give you grief everytime they have to touch a piece of code written in these languages. You may have to train them in these languages, and you may have to live with the fact that if you wanted to distribute the software, you will lose a significant number of potential users because they are unwilling to deal with non-conventional languages they are not used to.

$\endgroup$
3
  • $\begingroup$ Well, they are both widely used, just not in scientific computing. Lua has found wide acceptance in the gaming community due its fast/lightweight interpreter. Similarly, D is broadly seen as a potential replacement for C++. Unfortunately, neither language has had an impact in scientific computing, where the ability to reuse existing scientific codes trumps almost all other benefits. $\endgroup$ Commented Jul 23, 2014 at 17:19
  • $\begingroup$ I think you are taking liberty with the term "widely used" :-) I think any measure of programming language popularity is uncertain, but here is one: tiobe.com/index.php/content/paperinfo/tpci/index.html . Lua makes position 36 with 0.3% of code written in it. D is position 50 with 0.2% of code. $\endgroup$ Commented Jul 26, 2014 at 1:43
  • $\begingroup$ Agreed that they are not as popular as many languages used in web programming or core systems programming and administration, but that doesn't mean they aren't widely used, just that they are not likely to be the first (or even the second) programming language encountered. Anyway, it's a long digression that's not worth going into. $\endgroup$ Commented Jul 30, 2014 at 14:56
0
$\begingroup$

I would definitely recommend against LUA. Despite what you may have heard from the gaming community, it's not necessarily a fast or well designed language for scientific computing.

If you can manage it, CUDA is possibly the best choice, because it has the advantage of being GPU accelerated, dramatically increasing your compute power for an application as complex as a climate simulation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.