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

  • Context: C/C++ 
  • Thread starter Thread starter jd1828
  • Start date Start date
  • Tags Tags
    Fortran
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
14 replies · 4K views
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.
 
Physics news on Phys.org
the other program is written in perl. not sure if that matters or not.
 
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.
 
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
 
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.
 
dduardo said:
I did a google search and found this:

CALL SYSTEM('yourprogram')

Great, its works! Thanks
 
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
 
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.