3 ms·
I used to write scientific code in C++ too, but since a few years I've switched to Python+Fortran using f2py to automatically create bindings. Although there ar
by ziotom78 10y ago
I used to write scientific code in C++ too, but since a few years I've switched to Python+Fortran using f2py to automatically create bindings. Although there are a few drawbacks (different conventions in indexing arrays is the most annoying), I have not regretted this decision, python's ecosystem is incredibly large, and Fortran plugging Fortran modules allow me to optimize both speed and memory consumption efficiently. (But I eagerly await for the day Julia will be mature enough to allow me to switch!)
I only use Fortran just for low-level number crunching, and I must say I have yet to miss C++ templates here for this kind of stuff. I'm curious, what is your typical use of templates in your simulation code?
- neutronicus 10y ago> what is your typical use of templates in your simulation code? Apart from templating over floating-point precision, we use templates and policy classes to do a lot of the code reuse / flow control you'd use run-time polymorphism for, but without the overhead of virtual function calls. This is pretty useful for us, because our simulation algorithm has a lot of sub-parts that can be done in different ways. Rather than having a bunch of switch statements (or virtual function calls) in inner loops, we can have that switch statement once, in a factory object, and return instances of objects templated over the correct policy class so that we don't have to branch in inner loops. One of our main competitors is on the Fortran / Python plan. Our application has, instead, a few proprietary input formats (one XML-ish, and the other binary to be used with a GUI). This has its drawbacks (i.e. rolling and using our own Python-based macro language for use with the XML-ish input files). The CEO tells me, though, that this is actually kind of a godsend from a support perspective, because there is a point where all of the customer's simulation logic is frozen into a text file, which we can then debug (this is in contrast to the Python / Fortran approach, where the customer's simulation logic may be very tightly coupled with our own code).