C/C++ Can Fortran 90 match the speed of C++ in running external programs and loops?

  • Thread starter Thread starter jd1828
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
Fortran 90 can be used to run external programs, but it requires the use of the CALL SYSTEM subroutine to execute commands within a loop. Users noted that while Fortran compilers optimize numerical calculations effectively, they may not be the best choice for tasks involving text manipulation, which Perl handles more efficiently. The discussion highlighted the need for Fortran to pause and wait for the external program to finish before continuing the loop, which is a common requirement in such scenarios. Comparisons were made between Fortran and C++, emphasizing that Fortran is still relevant in scientific computing despite perceptions of its declining use. Ultimately, the choice of programming language depends on the specific task and the programmer's familiarity with the language.
jd1828
Messages
43
Reaction score
0
Im writing a program in fortran 90. what I am trying to get it to do is to open an input file for another program, change a few variables. then run that program. Then when the program is done running it will change the variables in the input file again and run the program. This will be a Do loop.
I know how to do all of this except how to run the other program from inside the fortran program.
 
Technology news on Phys.org
the other program is written in perl. not sure if that matters or not.
 
1) You could try the code found on this page:

http://www.jcameron.com/vms/fortran.htm

The programs are:

MAILBOX_A.FOR
MAILBOX_B.FOR

2) Does Fortran not have IPC (interprocess communication)?
 
Does anyone even use fortran any more.. or is this for educational purposes?
 
Anttech said:
Does anyone even use fortran any more.. or is this for educational purposes?


In computer science no. In scientific work, yes. Fortran compilers produce faster code for straight numerical calculations than any other language. Plus its easier to learn than C or C++. All the work I do with Los Alamos is Fortran for simulations. I also use perl when I need to process text outputs from other people's codes into more useful formats.

I've never needed top run a separate program by calling it from a fortran program though, and I have no idea how one would do this. That said, I don't see the advantage to using Fortran to do what you are asking at all. It would probably be much easier to do in Perl (which is designed for manipulating text). Unless the input files are binary, not text? If so, I would suggest writing a program in Fortran to convert them to text, call that from a Perl script, open the text version with the perl script, perform the necessary changes. Then if necessary, call a second Fortran program to take the new text version and convert it back to binary to be opened by the final program. I would suggest (as is my own practice) to use Perl for calling other programs, rather than using fortran to do it.
 
I do use a fortran program developed many years ago by a professor of mine but that's about it.
 
:-p

I think this about sums it up:

[January 1995]
 
The problem is that I have this program that I need to run around 50+ times. Each time I have to change a variable in an input file. In this case its a volume measurment that I need to increase a little each time. The program will take about 5 hours to run one calculation. I wanted to make a fortran program that would change the variable and run the program. That way I could just run it and check back in a week to see if it finished. I am using fortran because its all I can really program with. So the program would look like this
Loop
1. (this part is easy, no problems here)
- open file (text file)
- read variable
- change a variable based on iteration of loop
-close file
2. Run program (I have no idea)
end loop
 
  • #10
I did a google search and found this:

CALL SYSTEM('yourprogram')
 
  • #11
dduardo said:
:-p
I think this about sums it up:
[January 1995]
And? The discussion is about C and C++ vs F90. Unless I missed something, that should still apply.
 
  • #12
dduardo said:
I did a google search and found this:

CALL SYSTEM('yourprogram')

Great, its works! Thanks
 
  • #13
franznietzsche said:
See this http://www.lahey.com/PRENTICE.HTM . Sums things up fairly well.
Nice read - thanks, in many of our appls this applies :
However, unlike C and C++, Fortran 90 is designed to generate executable codes that are highly optimized and thus run extremely fast.
 
  • #14
Im just about done with this program but I am having one major problem. I have the CALL SYSTEM subroutine inside a loop. I need the loop to pause and wait for the other program to finish running before going through the loop again. If that's hard to understand it would look something like this:

DO i=1,100

Call System('program')

pause and wait for program to finish

end do
 
  • #15
franznietzsche said:
And? The discussion is about C and C++ vs F90. Unless I missed something, that should still apply.

C++ compilers have come a long way since 1995. Also C++ coding techniques. For example, most compilers allow one to specify strict aliasing. Can you post a simple example of Fortran that cannot be translated into C++ that will run just as fast?

BTW, I'm not saying that C++ isn't ugly. But processors don't run C++ or Fortran; therefore there is no intrinsic reason for one or the other to be faster.
 

Similar threads

Replies
2
Views
827
Replies
8
Views
4K
Replies
4
Views
2K
Replies
5
Views
5K
Replies
8
Views
2K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
3
Views
4K
Back
Top