Skip to content

Commit

Permalink
Use free form Fortran
Browse files Browse the repository at this point in the history
  • Loading branch information
trossi committed Mar 18, 2024
1 parent 940ecdb commit d4c9b64
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Have you profiled your code?

- Profiled the code: 99.9% of the execution time was being spent on these lines:

```fortran
```fortranfree
do i=1,n ! Removing these unnecessary loop iterations reduced the
do j=1,m ! wall-time of one simulation run from 17 hours to 3 seconds…
do k=1,fact(x)
Expand Down
2 changes: 1 addition & 1 deletion gpu-hip/docs/02-streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ process_in_host();
</div>

<div class=column>
```fortran
```fortranfree
!$omp target nowait
call process_in_device();
!$omp end target
Expand Down
10 changes: 5 additions & 5 deletions gpu-openmp/docs/02-OpenMP-offload-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ cc -o my_exe test.c -fopenmp
</div>

<div class=column>
```fortran
```fortranfree
!$omp target
! code executed in device
!$omp end target
Expand Down Expand Up @@ -270,7 +270,7 @@ cc -o my_exe test.c -fopenmp
</div>

<div class=column>
```fortran
```fortranfree
!$omp target
!$omp teams
!$omp parallel
Expand Down Expand Up @@ -312,7 +312,7 @@ for (int i = 0; i < N; i++)
</div>
<div class=column>
```fortran
```fortranfree
!$omp target
!$omp teams
!$omp distribute
Expand Down Expand Up @@ -368,7 +368,7 @@ for (int i = 0; i < N; i++) {
</div>

<div class=column>
```fortran
```fortranfree
!$omp target teams
!$omp distribute parallel do
do i = 1, N
Expand Down Expand Up @@ -398,7 +398,7 @@ for (int i = 0; i < N; i++) {
</div>

<div class=column>
```fortran
```fortranfree
!$omp target
!$omp loop
do i = 1, N
Expand Down
2 changes: 1 addition & 1 deletion gpu-openmp/docs/05-OpenMP-device-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ for (int i=0; i<n; ++i) {
<div class="column">
**Fortran**
```fortran
```fortranfree
subroutine foo(v, i, n)
!$omp declare target
real :: v(:,:)
Expand Down
12 changes: 6 additions & 6 deletions hybrid/docs/02-openmp-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ lang: en
<div class=column>
- In Fortran, an `end` directive specifies the end of the construct

```fortran
```fortranfree
!$omp parallel
! calculate in parallel
write(*,*) "Hello world!"
Expand Down Expand Up @@ -107,7 +107,7 @@ lang: en
structured block
```
- Fortran:
```fortran
```fortranfree
!$omp parallel [clauses]
structured block
!$omp end parallel
Expand All @@ -129,7 +129,7 @@ lang: en

<small>
<div class="column">
```fortran
```fortranfree
program omp_hello
write(*,*) "Hello world! -main"
Expand Down Expand Up @@ -200,7 +200,7 @@ Over and out! -main
#pragma omp for [clauses]
...
```
```fortran
```fortranfree
!$omp do [clauses]
...
!$omp end do
Expand All @@ -214,7 +214,7 @@ Over and out! -main

# for/do construct

```fortran
```fortranfree
!$omp parallel
!$omp do
do i = 1, n
Expand All @@ -241,7 +241,7 @@ Over and out! -main
- The `workshare` directive divides the execution of the enclosed structured
block into separate units of work, each of which is executed only once

```fortran
```fortranfree
real :: a(n,n), b(n,n), c(n,n) d(n,n)
...
!$omp parallel
Expand Down
2 changes: 1 addition & 1 deletion hybrid/docs/03-openmp-datasharing.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ lang: en
-->

<div class=column>
```fortran
```fortranfree
program hello
use omp_lib
integer :: omp_rank
Expand Down
4 changes: 2 additions & 2 deletions hybrid/docs/04-openmp-reduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lang: en
- Race conditions take place when multiple threads read and write a variable
simultaneously, for example:

```fortran
```fortranfree
asum = 0.0d0
!$omp parallel do shared(x,y,n,asum) private(i)
do i = 1, n
Expand Down Expand Up @@ -106,7 +106,7 @@ asum = 0.0d0

# Race condition avoided with reduction clause

```fortran
```fortranfree
!$omp parallel do shared(x,y,n) private(i) reduction(+:asum)
do i = 1, n
asum = asum + x(i)*y(i)
Expand Down
2 changes: 1 addition & 1 deletion hybrid/docs/05-mpi-threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ lang: en
- In point-to-point communication the thread ID can be used to
generate a tag that guides the messages to the correct thread
```fortran
```fortranfree
!$omp parallel private(tid, tidtag, ierr)
tid = omp_get_thread_num()
tidtag = 2**10 + tid
Expand Down
2 changes: 1 addition & 1 deletion hybrid/docs/06-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ lang: en

- Syntax (Fortran)

```fortran
```fortranfree
!$omp task[clause[[,] clause],...]
...
!$omp end task
Expand Down
2 changes: 1 addition & 1 deletion mpi/docs/01-intro-to-mpi.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ else if (rank == 1) {
#include <mpi.h>
```
- Fortran: use MPI module
```fortran
```fortranfree
use mpi_f08
```
&emsp;(older Fortran codes might have `use mpi` or `include 'mpif.h'`)
Expand Down
6 changes: 3 additions & 3 deletions mpi/docs/03-special-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lang: en
# Example

<div class=column>
```fortran
```fortranfree
if (rank == 0) then
call mpi_send(message, msgsize, &
MPI_INTEGER, 1, &
Expand All @@ -40,7 +40,7 @@ else if (rank == 1) then
</div>

<div class=column>
```fortran
```fortranfree
! Modulo operation can be used for
! wrapping around
dst = mod(rank + 1, ntasks)
Expand Down Expand Up @@ -83,7 +83,7 @@ if (0 == rank) {

# Example

```fortran
```fortranfree
dst = rank + 1
src = rank - 1
Expand Down
14 changes: 7 additions & 7 deletions mpi/docs/04-collectives.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lang: en
- Code becomes more compact and easier to read:

<div class=column>
```fortran
```fortranfree
if (rank == 0) then
do i = 1, ntasks-1
call mpi_send(a, 1048576, &
Expand All @@ -37,7 +37,7 @@ end if
```
</div>
<div class=column>
```fortran
```fortranfree
call mpi_bcast(a, 1048576, &
MPI_REAL, 0, &
MPI_COMM_WORLD, rc)
Expand Down Expand Up @@ -127,7 +127,7 @@ MPI_Scatter(`sendbuf`{.input}, `sendcount`{.input}, `sendtype`{.input}, `recvbuf
Assume 4 MPI tasks. What would the (full) program print?

<div class=column>
```fortran
```fortranfree
if (rank==0) then
do i = 1, 16
a(i) = i
Expand All @@ -145,7 +145,7 @@ if (rank==3) print *, a(:)

</div>
<div class=column>
```fortran
```fortranfree
if (rank==0) then
do i = 1, 16
a(i) = i
Expand Down Expand Up @@ -196,7 +196,7 @@ MPI_Scatterv(`sendbuf`{.input}, `sendcounts`{.input}, `displs`{.input}, `sendtyp
# Scatterv example

<div class=column>
```fortran
```fortranfree
if (rank==0) then
do i = 1, 10
a(i) = i
Expand Down Expand Up @@ -382,7 +382,7 @@ MPI_Alltoall(`sendbuf`{.input}, `sendcount`{.input}, `sendtype`{.input}, `recvbu
# All-to-all example

<div class=column>
```fortran
```fortranfree
if (rank==0) then
do i = 1, 16
a(i) = i
Expand Down Expand Up @@ -494,7 +494,7 @@ MPI_Allreduce(`sendbuf`{.input}, `recvbuf`{.output}, `count`{.input}, `datatype`
# Allreduce example: parallel dot product

<div class=column>
```fortran
```fortranfree
real :: a(1024), aloc(128)
...
if (rank==0) then
Expand Down
4 changes: 2 additions & 2 deletions mpi/docs/08-communicator-topologies-cartesian.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ MPI_Dims_create(`ntasks`{.input}, `ndims`{.input}, `di`{.input}`ms`{.output})

# Creating a Cartesian communication topology

```fortran
```fortranfree
dims = 0
period=(/ .true., .false. /)
Expand Down Expand Up @@ -175,7 +175,7 @@ call mpi_cart_coords(comm2d, rank, 2, coords, rc)
# Halo exchange

<small>
```fortran
```fortranfree
call mpi_cart_shift(comm2d, 0, 1, nbr_up, nbr_down, rc)
call mpi_cart_shift(comm2d, 1, 1, nbr_left, nbr_right, rc)
...
Expand Down
6 changes: 3 additions & 3 deletions mpi/docs/09-user-defined-datatypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ MPI_Type_vector(`count`{.input}, `blocklen`{.input}, `stride`{.input}, `oldtype`

# Example: sending rows of matrix in Fortran

```fortran
```fortranfree
integer, parameter :: n=2, m=3
real, dimension(n,m) :: a
type(mpi_datatype) :: rowtype
Expand Down Expand Up @@ -403,13 +403,13 @@ MPI_Type_contiguous(`count`{.input}, `oldtype`{.input}, `newtype`{.output})
<small>
<div class=column>
```fortran
```fortranfree
! Using derived type
call mpi_send(buf, 1, conttype, ...)
```
</div>
<div class=column>
```fortran
```fortranfree
! Equivalent call with count and basic type
call mpi_send(buf, count, MPI_REAL, ...)
```
Expand Down
Loading

0 comments on commit d4c9b64

Please sign in to comment.