STL类似于Fortran [英] STL analogue in Fortran

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

问题描述

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

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.

问题: strong>我知道如何写哈希表,创建队列和代码mergeesort由我自己,但我不认为这是一个好主意,发明一辆自行车。

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大师在这种情况下应该做什么?我应该构建绑定到C + +类Fortran和实现逻辑使用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.

有一个预处理器,并带有一些小的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.

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

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