4 ms·
Very naive question, but are the semantics of Fortran so different that it can't be translated to C first and then compiled using a C compiler? Perhaps maintain
by mattbillenstein 3y ago
Very naive question, but are the semantics of Fortran so different that it can't be translated to C first and then compiled using a C compiler? Perhaps maintained in C going forward?
I can't imagine there are a lot of Fortran folks around maintaining these old libraries - they must need maintenance no?
- googl-free 3y agoyeah, fortran has native arrays
- lldb 3y agoWe have this already - “f2c” has been around for decades.
- ogrisel 3y agoIt's currently used to provide a hackish WASM compatible port of scipy for Pyodide and the Pyodide maintainers are eager to be able to drop the f2c hacks in favor of lfortran or any WASM-capable fotran compiler because f2c can cause very hard to debug low level crashes when running scipy or other downstream libraries tests (e.g. scikit-learn).
- mkoubaa 3y agoFortran is a higher level language than C. There are plenty of fortran developers. It's awful for application development, but that isn't it's niche
- not2b 3y agoIf you want the code to run slower, yes, you could do that. Because there are no pointers in Fortran, only arrays, and because arguments to functions aren't allowed to alias (let's ignore the horror of COMMON blocks for now), aggressive optimization and vectorization is easier. The standard Fortran math libraries just work, and they are fast. I should clarify that you can write C/C++ code that would have equivalent speed, especially with the C restrict keyword, but putting in an f2c step to translate the existing code will making things significantly worse in many cases.
- Sohcahtoa82 3y ago> Because there are no pointers in Fortran, only arrays, and because arguments to functions aren't allowed to alias [...], aggressive optimization and vectorization is easier. Can you explain this like I'm 12? What's an example of an aggressive optimization you can make based on arguments not being aliased and there being no pointers?
- Falell 3y agoNot a direct compiler optimization, but consider memcpy() vs memmove() as an example. If you know two regions of memory do not overlap you can call memcpy() for a direct optimized copy, but if they overlap you must call memmove() and introduce an intermediate copy.
- Sohcahtoa82 3y agoIt makes sense, but when would you ever memcpy with overlap? I would think any situation that lets that happen is from a bug, like you have an incorrect buffer length or an incorrect destination address.
- murderfs 3y agoInserting an element in an array is something along the lines of memmove(arr + idx + 1, arr + idx, (length - idx) * sizeof(*arr)); arr[idx] = foo;
- johncolanduoni 3y agomemmove does not (in any implementation I’ve ever heard of) introduce an intermediate copy, it just performs the copy loop in the reverse direction to handle the overlap (and can’t always vectorize in the same way memcpy can).
- superlopuh 3y agoHere's a relevant thread: https://users.rust-lang.org/t/possible-rust-specific-optimizations/79895/3 https://users.rust-lang.org/t/possible-rust-specific-optimiz...