Fortran 77 代码到 C++ 的转换

2022-01-14 00:00:00 fortran translation c++

是否有人将 Fortran 77 代码的大型(我们的为 550,000 行)程序转换为 C++?你遇到了什么陷阱?转换成功了吗?您是否使用过类似 for_c ( http://www.钴蓝色.com/fc/fcmain.htm)?生成的 C++ 代码是明显快了还是慢了?

Has anyone converted a large (ours is 550,000 lines) program of Fortran 77 code to C++ ? What pitfalls did you run into ? Was the conversion a success ? Did you use a tool like for_c ( http://www.cobalt-blue.com/fc/fcmain.htm ) ? Was the resulting C++ code significantly faster or slower ?

推荐答案

这增加了 EvilTeach 的建议.请记住,链接 Fortran 77 和 C/C++ 代码相当容易,因此您可以逐步转换应用程序的某些部分并将它们与旧部分链接在一起.如果您这样做,您将不得不考虑所有常见的 fortran/c 差异(行/列主要数组、数组索引等),但它会为您省去一次调试整个自动翻译代码库的痛苦.

This adds to EvilTeach's advice. Keep in mind that it's fairly easy to link Fortran 77 and C/C++ code, so you can convert parts of your application incrementally and link them together with the old parts. You'll have to think about all the usual fortran/c discrepancies (row/column-major arrays, array indexing, etc.) if you do this, but it would save you the pain of debugging your entire auto-translated codebase at once.

国家 (DOE) 实验室有许多类似的大型混合代码,它们对旧的 Fortran 代码进行了大量投资.如果你走这条路,你可能会考虑使用 Babel,它的开发是为了允许在同一应用程序中的 C、C++、Fortran、Fortran90、Python 和 Java 之间共享的组件.在实验室中这样做的动机是将不同团队为非常大的模拟构建的物理模型捆绑在一起,但您可能会发现它对于转换代码也很有用.它在许多项目中得到积极维护和使用,尽管对于您正在尝试做的事情来说它可能有点过于复杂.

There are many large hybrid codes like this at the national (DOE) labs, which have a significant investment in old Fortran code. If you go this route, you might consider using Babel, which was developed to allow components to be shared between C, C++, Fortran, Fortran90, Python and Java all in the same app. The motivation for this at the labs is tying together physics models built by different teams for really large simulations, but you might find it useful for transitioning your code, too. It's actively maintained and used on a lot of projects, though it might be a bit too complex for what you're trying to do.

相关文章