Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lecture materials
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
generic software skills
lecture materials
Commits
bba13690
Commit
bba13690
authored
10 months ago
by
Dominik Zobel
Browse files
Options
Downloads
Patches
Plain Diff
Add Fortran loop hands-on
parent
e58cffc8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!74
Memory hierarchies lecture
Pipeline
#71944
passed
10 months ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lectures/memory-hierarchies/slides.qmd
+44
-0
44 additions, 0 deletions
lectures/memory-hierarchies/slides.qmd
lectures/memory-hierarchies/static/loops.f90
+13
-0
13 additions, 0 deletions
lectures/memory-hierarchies/static/loops.f90
with
57 additions
and
0 deletions
lectures/memory-hierarchies/slides.qmd
+
44
−
0
View file @
bba13690
...
@@ -192,6 +192,50 @@ $^*$: Lower than one due to caching effects
...
@@ -192,6 +192,50 @@ $^*$: Lower than one due to caching effects
## Memory access patterns
Execution speed depends on data layout in memory
```{.fortranfree}
program loop_exchange
implicit none
integer, parameter :: nel = 20000
! Note: Stay below 46000 to prevent overflows below
integer, dimension(nel, nel) :: mat
integer :: i, j
do i = 1, nel
do j = 1, nel
mat(j, i) = (i-1)*nel + j-1
end do
end do
end program loop_exchange
```
Loop order with optimal access of elements (contiguous memory).
## Hands-On {.handson}
1. Compile the Fortran code from the previous slide (also [here](static/loops.f90))
on Levante or your PC. On Levante load the `gcc` module first (`module load gcc`).
Then measure the time needed to run the program, i.e.
```{.Bash}
gfortran loops.f90 -o loops
time ./loops
```
2. Exchange the loop variables `i` and `j` in line 8 and 9 and compile again.
How does it impact the run time?
3. Try different values for `nel` (for the original loop order and the exchanged one).
How does the matrix size relate to the effect of exchanged loops?
# Memory Models
# Memory Models
- Study effect of latencies, cache sizes, block sizes, ...
- Study effect of latencies, cache sizes, block sizes, ...
...
...
This diff is collapsed.
Click to expand it.
lectures/memory-hierarchies/static/loops.f90
0 → 100644
+
13
−
0
View file @
bba13690
program
loop_exchange
implicit
none
integer
,
parameter
::
nel
=
20000
! Note: Stay below 46000 to prevent overflows below
integer
,
dimension
(
nel
,
nel
)
::
mat
integer
::
i
,
j
do
i
=
1
,
nel
do
j
=
1
,
nel
mat
(
j
,
i
)
=
(
i
-1
)
*
nel
+
j
-1
end
do
end
do
end
program
loop_exchange
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment