传递大量的数据从FORTRAN到C ++ [英] Passing large amount of data from FORTRAN to C++

查看:212
本文介绍了传递大量的数据从FORTRAN到C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是从一个FORTRAN程序到C ++程序传递大量数据(双号)的最佳和最有效的方法?现在我使用的二进制文件,但它的速度不够快!

我试过管道。我跟着 http://msdn.microsoft.com/en-美国/库/ ms682499(VS.85)的.aspx ,在C ++的一部分。但对于FORTRAN部分(这是孩子处理器),我不知道如何正确地写入数据。我一定要像控制台WRITE(*,*)AllTheNumbers 上写的?因为写在控制台上花费了大量的时间!

我的FORTRAN code写数据:

  DO 281 I = 1,NDOF
        DO 280 J = 1,UBW
        中频(S(I,J).NE.0)THEN
          WRITE(*,2770)I,(J + I-1)
          WRITE(*,2760)(S(I,J))
        万一
 280 CONTINUE
 281 CONTINUE


解决方案

最快的方式将能使之混合语言编程。产生一个(例如,Fortran的)的数字,并从该语言调用其他(例如,C ++)。随着ISO C绑定的Fortran,称C是Fortran语言标准的一部分。许多Fortran编译器支持这一点。使用外部C在C ++的一面。双打传递一个数组应该很容易。

编辑:如果您继续使用传送信息的方法IO,你应该传递的信息为二进制数据。你采样的Fortran code为使用格式化IO ...变换的数字的内部二进制重新presentation为人类可读字符是缓慢的。在你的Fortran公开声明使用:访问='流',表='格式化'。不要在写使用的格式。

What is the best and most efficient method to pass large amount of data (double numbers) from a FORTRAN program to a C++ program? right now I am using binary file but it is not fast enough!

I tried pipe. I followed http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx for the C++ part. But for the FORTRAN part (which is the child processor) I do not know how to properly write data. Do I have to write on the console like WRITE(*,*) AllTheNumbers? because writing on the console takes a lot of time!

My FORTRAN code to write data:

        DO 281 I=1,NDOF 
        DO 280 J=1,UBW              
        IF (S(I,J).NE.0) THEN      
          WRITE (*, 2770) I,(J+I-1)
          WRITE (*,2760) (S(I,J))          
        ENDIF        
 280    CONTINUE         
 281    CONTINUE

解决方案

The fastest way would be to make it one mixed-language program. Generate the numbers in one (e.g., Fortran) and call the other (e.g., C++) from that language. With the ISO C Binding of Fortran, calling C is part of the Fortran language standard. Numerous Fortran compilers support this. Use "extern C" on the C++ side. Passing an array of doubles should be easy.

EDIT: if you continue using an IO method of transferring the information, you probably should transfer the information as binary data. You sample Fortran code is using formatted IO ... converting the internal binary representation of the numbers into human-readable characters is slow. In your Fortran open statement use: access='stream', form='unformatted'. Don't use a format on the write.

这篇关于传递大量的数据从FORTRAN到C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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