Fortran 中的 STL 类似物 [英] STL analogue in Fortran

查看:30
本文介绍了Fortran 中的 STL 类似物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基础:我有非常大的并行 Fortran90/MPI 程序,代表复杂的物理模型.我想为其添加新功能:例如,我需要组织消息队列,在某处引入合并排序并使用哈希表.

Basis: i have very big parallel Fortran90/MPI program which represent complex physical model. I want to add new functionality to it: for example, i need to organize queue of messages, introduce mergesort somewhere and use hash tables.

问题:我自己知道如何编写哈希表、创建队列和代码归并排序,但我认为发明自行车不是一个好主意.

Problem: i know how write hash table, create queue and code mergesort by my self, but i don't think it is a good idea to invent a bicycle.

问题:在这种情况下,Fortran 大师应该怎么做?我应该从 Fortran 构建与 C++ 类的绑定并使用 STL 在那里实现逻辑,还是您可以建议一些类似 Fortran STL 的库?谢谢.

Question: what Fortran guru should do in such situation? Should i build binds to C++ classes from Fortran and realize logic there using STL or you can suggest some Fortran STL-like libraries? Thank you.

推荐答案

Fortran 中没有模板,因此没有 STL.对于一些通用库,您可以尝试 FLIBS.它一般使用transfer()技巧来实现泛型编程.

There are no templates in Fortran and hence no STL. You can try FLIBS for some generic libraries. It generally uses transfer() tricks to achieve generic programming.

有一个预处理器,它为 Fortran 添加了一些模板并附带了一些小的 STL,你也可以尝试一下,命名为 PyF95++.如果您可以通过某个图书馆访问学术论文,您可以在这里阅读.

There is a preprocessor which adds some templates to Fortran and comes with some small STL, you can try that too named PyF95++. If you have access to academic papers through some library, you can read about it here.

在这种特定情况下,我会避免将它与 C++ 混合,尽管可以这样做.您必须分别实例化每个案例并使用包装器(bind(C)iso_c_binding)将其连接到 Fortran.只有当您想要使用算法的类型非常有限时,它才值得.

I would avoid mixing it with C++ in this specific case although it can be done. You must instantiate each case separately and interface it to Fortran using a wrapper (bind(C) and iso_c_binding). Only if you have a very limited number of types you want to use the algorithms for it could be worth it.

您还可以尝试使用 Fortran 中的 C 预处理器来实现一些穷人的模板,对于较小的库它可以工作,但对于复杂的事情可能变得太难维护或丑陋.作为一个例子,你可以看到我的链表实现 https://github.com/LadaF/fortran-list .

You can also try to implement some poor-man's templates using the C-preprocessors in Fortran, For smaller libraries it works, but can become too difficult to maintain or ugly for complex things. As an example you can see my implementation of a linked list https://github.com/LadaF/fortran-list .

通常,没有明确正确的方法或答案,您总是需要从更多的可能性中进行选择.

Generally, there is no clearly right approach or answer, you always have to choose from more possibilities.

这篇关于Fortran 中的 STL 类似物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆