Difference between revisions of "Programming/Fortran"

From HPC
Jump to: navigation , search
(Batch example)
m
Line 11: Line 11:
  
  
<pre style="background-color: #C8C8C8; color: black; border: 2px solid #C8C8C8; font-family: monospace, sans-serif;">
+
<pre style="background-color: #f5f5dc; color: black; font-family: monospace, sans-serif;">
 
program variableTesting
 
program variableTesting
 
implicit none
 
implicit none
Line 46: Line 46:
  
  
<pre style="background-color: #C8C8C8; color: black; border: 2px solid #C8C8C8; font-family: monospace, sans-serif;">
+
<pre style="background-color: #f5f5dc; color: black; font-family: monospace, sans-serif;">
 
program helloworld
 
program helloworld
 
   use omp_lib
 
   use omp_lib
Line 64: Line 64:
 
The following modules are available:
 
The following modules are available:
  
* module load gcc/4.9.3 (GNU compiler)
+
* module add gcc/4.9.3 (GNU compiler)
* module load intel/compiler/64/2016.2.181 (Intel compiler)
+
* module add intel/compiler/64/2016.2.181 (Intel compiler)
  
 
==== Compilation ====
 
==== Compilation ====
Line 72: Line 72:
  
 
<pre style="background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
 
<pre style="background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
[username@login01 ~]$  module load gcc/4.9.3
+
[username@login01 ~]$  module add gcc/4.9.3
 
[username@login01 ~]$  gfortran -o testFortran  testFortran.f03
 
[username@login01 ~]$  gfortran -o testFortran  testFortran.f03
 
</pre>
 
</pre>
Line 80: Line 80:
 
=== Batch example ===
 
=== Batch example ===
  
<pre style="background-color: #f5f5dc; color: black; font-family: monospace, sans-serif;">
+
 
 +
<pre style="background-color: #C8C8C8; color: black; border: 2px solid #C8C8C8; font-family: monospace, sans-serif;">
 +
 
 
#!/bin/bash
 
#!/bin/bash
  
Line 94: Line 96:
  
 
module purge
 
module purge
module load gcc/4.9.3
+
module add gcc/4.9.3
  
 
export I_MPI_DEBUG=5
 
export I_MPI_DEBUG=5

Revision as of 11:50, 8 February 2017

Programming Details

Fortran (formerly FORTRAN, derived from Formula Translation) is a general-purpose, imperative programming language that is especially suited to numeric computation and scientific computing.

There is direct support for openMP and openMPI.


Programming example

Non Parallel Example

program variableTesting
implicit none

   ! declaring variables
   integer :: total,average
   complex :: cx
   logical :: done
   character(len=80) :: message ! a string of 80 characters

   !assigning values
   total = 20000
   average = 1666
   done = .true.
   message = "A big Hello from HPC"

   cx = (3.0, 5.0) ! cx = 3.0 + 5.0i

        if (total .ge. average) then
                print *, total, " greater or equal than average"
        else
                print *, total, " less than average"
        endif

   Print *, average
   Print *, cx
   Print *, done
   Print *, message

end program variableTesting

Parallel Example (openMP)

program helloworld
  use omp_lib
  implicit none

!$OMP PARALLEL
!$OMP CRITICAL
  print *,'Hello from thread number',OMP_GET_THREAD_NUM()
!$OMP END CRITICAL
!$OMP END PARALLEL

end program helloworld

Modules Available

The following modules are available:

  • module add gcc/4.9.3 (GNU compiler)
  • module add intel/compiler/64/2016.2.181 (Intel compiler)

Compilation

The program would be compiled in the following way, optional Intel compiler available too:

[username@login01 ~]$  module add gcc/4.9.3
[username@login01 ~]$  gfortran -o testFortran  testFortran.f03

Usage Examples

Batch example


#!/bin/bash

#SBATCH -J openmpi-single-node
#SBATCH -N 1
#SBATCH --ntasks-per-node 28
#SBATCH -o %N.%j.%a.out
#SBATCH -e %N.%j.%a.err
#SBATCH -p compute
#SBATCH --exclusive

echo $SLURM_JOB_NODELIST

module purge
module add gcc/4.9.3

export I_MPI_DEBUG=5
export I_MPI_FABRICS=shm:tmi
export I_MPI_FALLBACK=no

/home/user/CODE_SAMPLES/OPENMP/demo
[username@login01 ~]$ sbatch demo.job
Submitted batch job 239552

Further Information