CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Fortran 90 to c++ converter (https://www.cfd-online.com/Forums/main/2419-fortran-90-c-converter.html)

Guoping Xia July 27, 2000 23:00

Fortran 90 to c++ converter
 
Is there a converter from Fortran 90 to c++? Could anybody tell me please?

Thanks!

andy July 28, 2000 03:32

Re: Fortran 90 to c++ converter
 
There is the old f2c (Fortran 77 to C). This might give you a start depending on what it does with the Fortran 90 constructs.

Can I ask why you want to convert the code?

Guoping Xia July 28, 2000 11:55

Re: Fortran 90 to c++ converter
 
The fortran 90 code I wrote is for mesh adaptation. I use the dynamic data structures of the new generation of Fortran. However, I find it is not so fast as I expected,so I want to try c++. That is the reason.

andy July 28, 2000 12:34

Re: Fortran 90 to c++ converter
 
I have little direct experience of Fortran 90 but I do know you have to be careful passing your dynamic arrays around. It may be worth having a quick chat with someone (or some reference) which will give you some guidance. Many years ago someone from NAG was explaining the pitfalls of Fortran 90 to me but none of it has stuck unfortunately. It may be a place to start.

C++ is slow. Even the most optimistic will only claim it might approach the speed of Fortran (e.g. Blitz) and this is only after extraodinary efforts to emulate in C/C++ code the optimisation operations performed by a normal Fortran compiler (carefully avoiding reference to the very useful but... g77). You will not believe how long even simple code takes to compile and the bloat of the resulting binary.

Even Bjarne Stroustrup (C++ ARM) cheerfully admits that the C array is irrepairable (I may be misquoting a bit here because I cannot find the reference - anyone?).

If you want speed then stick to Fortran 77 and a decent compiler. Writing one or two extra routines to compact your fixed size arrays when they have hit their maximum size is not much of a chore. Certainly when compared to the efforts of getting to grips with templating in C++ (assuming your C++ compiler has implemented enough template features to use them effectively!).


Jongtae Kim July 28, 2000 20:32

Re: Fortran 90 to c++ converter
 
Hi Gouping, How are you?

It is said that Fortran77 is the fastest language. C and Fortran90 are faster than C++. OOP is slower than structured programming. Dynamic memory allocation makes your code slow-down. But if you use more arrays to save mesh connectivities for the adaptation, you can get the speed-up. So I recommand you to save all the informations for mesh connectivities.

Sincerely yours,

Jongtae Kim


John C. Chien July 28, 2000 21:59

Re: Fortran 90 to c++ converter
 
(1). C++ is equal to c plus object-oriented programming using class and object. (2). You don't have to use oop when writing code in C++ language. The conventional c-language, structured procedural programming still works. (3). The reason going into oop is not for speed but for ease of program maintenance and program resue. (4). I would say that program written in oop style in C++ (class and object) tends to simulate the real world objects and activities more closely. This is especially true for the data hiding inside the class and object. It is always protected from unauthorized access. In the non-oop world, data are not associated with any object and are not protected. (5). Since the new data type such as the user-defined class type, needs to be declared first and then defined later, it always take time to create (constructor) and clean-up (destructor) the object. (6). Just like renting an apartment, the apartment needs to be cleaned, painted, range and oven checked out,etc.. before one can move in. On the other hand, the non-oop approach will simply put you in a big shelter as long as there is a bed available. But then you don't have the privacy at all in the big shelter, not to mention about the security of the personal things. So, the extra security will require extra time and resources. (7). So, C++ with oop is not created for speed. Like graphic programming in computer games, you will have to go a step further to use either DirectX or assembly language in order to really get the speed gain.

Oliver Gloth July 31, 2000 04:29

Re: Fortran 90 to c++ converter
 
I don't think that you can put it that simple (i.e. F77 is faster than C and F90, which are faster than C++ and so on). The big problem about dynamic arrays is aliasing. That means the compiler can not know if two arrays overlap in the memory. This can just not happen in F77, right? Another point is making use of object-oriented features, without thinking about performance. There are, however, many nice approaches to be efficient and object-oriented. If you are interested in OOP+numerics you should check out <a href=http://oonumerics.org/oon/>The Object-Oriented Numerics Page</a>, which is maintained by T.Veldhuizen (the author of Blitz++). I personally recommend his text about 'Techniques for scientific C++' which can be found on that page as well. To my opinion the benefits from OOP (reusability, mainatinability) are worth the effort, although it can still be a bit painful right now.

andy August 9, 2000 05:57

Re: Fortran 90 to c++ converter
 
While looking for something else I came across this link to a F90 to C++ converter.

http://www.cross.ru/kcc/

Could you post back to let us know if it works? Or is partially useful?



All times are GMT -4. The time now is 16:15.