UMBC logo
UMBC High Performance Computing Facility
How to run FORTRAN 77 programs on maya


Running FORTRAN 77 programs on the cluster is similar to running any other serial job. Make sure you've read the tutorial for C programs first, to understand the basics.

Serial Example

Let's try to compile this simple Fortran 77 program
      write(*,*) "Salutations, Earth."

Download: ../code/hello_serial-f77/hello_serial.f
To compile this using GCC and create the executable helloworld-f77-gcc, type
[araim1@maya-usr1 hello_serial-f77]$ gfortran -ffixed-form hello_serial.f -o hello_serial-f77-gcc
[araim1@maya-usr1 hello_serial-f77]$ 
Alternatively, to compile using Intel Fortran and create the executable helloworld-f77-pgi, type
[araim1@maya-usr1 hello_serial-f77]$ ifort hello_serial.f -o hello_serial-f77-intel
[araim1@maya-usr1 hello_serial-f77]$ 
Running this program should produce this message:
[araim1@maya-usr1 hello_serial-f77]$ ./hello_serial-f77-gcc
Salutations, Earth.
[araim1@maya-usr1 hello_serial-f77]$ ./hello_serial-f77-intel
Salutations, Earth.

Parallel Example

We'll assume that you already know the fundamentals of MPI execution from the C tutorial. Now let's create the following program:
      program hello_parallel

C     Include the MPI library definitons:                                                                                
      include 'mpif.h'

      integer numtasks, rank, ierr, rc, len, i
      character*(MPI_MAX_PROCESSOR_NAME) name

C     Initialize the MPI library:                                                                                        
      call MPI_INIT(ierr)
      if (ierr .ne. MPI_SUCCESS) then
         print *,'Error starting MPI program. Terminating.'
         call MPI_ABORT(MPI_COMM_WORLD, rc, ierr)
      end if

C     Get the number of processors this job is using:                                                                    
      call MPI_COMM_SIZE(MPI_COMM_WORLD, numtasks, ierr)

C     Get the rank of the processor this thread is running on.  (Each                                                    
C     processor has a unique rank.)                                                                                      
      call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)

C     Get the name of this processor (usually the hostname)                                                              
      call MPI_GET_PROCESSOR_NAME(name, len, ierr)
      if (ierr .ne. MPI_SUCCESS) then
         print *,'Error getting processor name. Terminating.'
         call MPI_ABORT(MPI_COMM_WORLD, rc, ierr)
      end if

      print 30, "hello_parallel.f: Number of",numtasks,rank,name
 30   format (A,' tasks=',I3,' My rank=',I3,' My name=',A80,'')
C     Tell the MPI library to release all resources it is using:                                                         
      call MPI_FINALIZE(ierr)


Download: ../code/hello_parallel-f77/hello_parallel.f
Compile your program with
mpif77 hello_parallel.f -o hello_parallel
The same compilation command should work even if you've changed the switcher to use a different MPI implementation and compiler. Running the compiled program is now exactly the same as running a C MPI program.