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

  • Fortran
  • Thread starter jd1828
  • Start date
  • Tags
    Fortran
In summary, the problem is that the fortran program needs to pause and wait for the other program to finish running before going through the loop again.
  • #1
jd1828
44
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
  • #2
the other program is written in perl. not sure if that matters or not.
 
  • #3
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)?
 
  • #4
Does anyone even use fortran any more.. or is this for educational purposes?
 
  • #5
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.
 
  • #6
I do use a fortran program developed many years ago by a professor of mine but that's about it.
 
  • #8
:tongue2:

I think this about sums it up:

[January 1995]
 
  • #9
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:
:tongue2:
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.
 

1. What is Fortran and what is it used for?

Fortran is a high-level programming language primarily used for scientific and numerical computing. It is designed to handle large-scale mathematical computations and is commonly used in fields such as physics, engineering, and finance.

2. Is Fortran still relevant in modern programming?

Yes, Fortran is still widely used in scientific computing and is constantly being updated and improved. Many legacy codes are written in Fortran and it is still the language of choice for many scientific applications.

3. How difficult is it to learn Fortran?

Fortran is a relatively easy language to learn, especially for those with a background in mathematics or programming. Its syntax is simple and straightforward, making it easy to read and write.

4. Are there any advantages to using Fortran over other programming languages?

Fortran is specifically designed for scientific computing, so it has built-in features for handling complex mathematical operations. It is also highly optimized for efficiency, making it a popular choice for large-scale simulations and calculations.

5. Can Fortran be used for other types of programming besides scientific computing?

While Fortran is primarily used for scientific computing, it can also be used for general-purpose programming. However, it may not have the same range of libraries and tools available for other languages such as Python or Java.

Similar threads

  • Programming and Computer Science
Replies
22
Views
852
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
463
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
3
Views
4K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top