Difference between revisions of "Programming/Fortran"
From HPC
m |
m |
||
Line 5: | Line 5: | ||
=== Programming example === | === Programming example === | ||
+ | |||
+ | ==== Non Parallel Example ==== | ||
<pre style="background-color: #C8C8C8; color: black; border: 2px solid green; font-family: monospace, sans-serif;"> | <pre style="background-color: #C8C8C8; color: black; border: 2px solid green; font-family: monospace, sans-serif;"> | ||
Line 36: | Line 38: | ||
end program variableTesting | end program variableTesting | ||
+ | </pre> | ||
+ | |||
+ | ==== Parallel Example (openMP) ==== | ||
+ | |||
+ | <pre style="background-color: #C8C8C8; color: black; border: 2px solid green; font-family: monospace, sans-serif;"> | ||
+ | |||
+ | 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 | ||
</pre> | </pre> |
Revision as of 13:59, 6 February 2017
Contents
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.
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 load gcc/4.9.3 (GNU compiler)
- module load 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 load gcc/4.9.3 [username@login01 ~]$ gfortran -o testFortran testFortran.f03