Skip to content

Commit 381b90b

Browse files
committed
add talk slides and source code for day2
1 parent 1ea9d12 commit 381b90b

25 files changed

+2791
-0
lines changed

Diff for: day2/compile-link-make.pdf

351 KB
Binary file not shown.

Diff for: day2/floating-point-code/mathopt/Makefile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FC = gfortran
2+
#FC = ifort
3+
#FC = pgf77
4+
5+
CFLAGS = $(ABI) $(ARCH)
6+
7+
TARGETS = prog1 prog2a prog2b prog2c prog2d prog3
8+
9+
default: all
10+
11+
prog1: prog1.f
12+
$(FC) -o $@ $(ABI) $(ARCH) \
13+
-O3 prog1.f
14+
15+
prog2a: prog2.f
16+
$(FC) -o $@ $(ABI) $(ARCH) \
17+
-O3 prog2.f
18+
19+
prog2b: prog2.f
20+
$(FC) -o $@ $(ABI) $(ARCH) \
21+
-O0 prog2.f
22+
23+
prog2c: prog2.f
24+
$(FC) -o $@ $(ABI) $(ARCH) \
25+
-O3 -ffast-math prog2.f
26+
27+
prog2d: prog2.f
28+
$(FC) -o $@ $(ABI) $(ARCH) \
29+
-O3 -ffast-math -funsafe-math-optimizations prog2.f
30+
31+
prog3: prog3.f
32+
$(FC) -o $@ $(ABI) $(ARCH) \
33+
-O3 prog3.f
34+
all: $(TARGETS)
35+
36+
clean:
37+
/bin/rm -f $(TARGETS)
38+
/bin/rm -f *.s *.w2f.f

Diff for: day2/floating-point-code/mathopt/README

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
IEEE Floating Point Arithmetic Optimizations
2+
3+
files:
4+
prog1.f
5+
prog2.f
6+
prog3.f
7+
Makefile
8+
9+
Objectives:
10+
11+
* understand the impact of IEEE-compliant compilation on performance
12+
13+
Instructions:
14+
15+
1. Look at the first program prog1.f: we calculate a two-point average, requiring a division by 2.
16+
2. Make prog1 and measure the runtime. ( /bin/time ./prog1 )
17+
18+
3. Now we take the second program prog2.f, calculating a three-point average, requiring a division by 3.
19+
4. Make prog2a and measure the runtime.
20+
5. How do the runtimes compare to prog1?
21+
Does the extra addition justify the increase in CPU time?
22+
23+
6. Look at the prog3.f: where is the difference between prog2.f and prog3.f?
24+
7, Make it and measure runtime
25+
26+
8. Now make prog2b, prog2c, and prog2d and take note of the extra compiler options used.
27+
9. Measure the runtime of prog2b, prog2c, and prog2d. Compare with prog3 and prog1
28+
what are your conclusions?
29+
30+

Diff for: day2/floating-point-code/mathopt/prog1

19.2 KB
Binary file not shown.

Diff for: day2/floating-point-code/mathopt/prog1.f

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
program main1
2+
c
3+
c
4+
implicit none
5+
integer mx
6+
parameter( mx = 100000 )
7+
real*4 a(mx)
8+
9+
integer i
10+
11+
! Initialize the array
12+
13+
do i = 1, mx
14+
a(i) = float(i)
15+
end do
16+
17+
! Average the array
18+
do i = 1, 10000
19+
call xaver( a, mx )
20+
end do
21+
write(*,'(E22.14,2X,E22.14,2X,E22.14)')
22+
& a(10000), 15000.0e0,
23+
& (a(10000)-15000.0e0)
24+
end
25+
26+
27+
subroutine xaver( a, mx )
28+
c
29+
c Average the data in i direction.
30+
c
31+
implicit none
32+
integer mx
33+
real*4 a(mx)
34+
integer i
35+
36+
do i = 1, mx-1
37+
a(i) = ( a(i) + a(i+1) ) / 2.0e0
38+
end do
39+
40+
end
41+

Diff for: day2/floating-point-code/mathopt/prog2.f

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
program main2
2+
c
3+
c
4+
c
5+
implicit none
6+
integer mx
7+
parameter( mx = 100000 )
8+
real*4 a(mx)
9+
10+
integer i
11+
12+
! Initialize the array
13+
14+
do i = 1, mx
15+
a(i) = float(i)
16+
end do
17+
18+
! Average the array
19+
do i = 1, 10000
20+
call xaver( a, mx )
21+
end do
22+
write(*,'(E22.14,2X,E22.14,2X,E22.14)')
23+
& a(10000), 20000.0e0,
24+
& (a(10000)-20000.0e0)
25+
end
26+
27+
28+
subroutine xaver( a, mx )
29+
c
30+
c Average the data in i direction.
31+
c
32+
implicit none
33+
integer mx
34+
real a(mx)
35+
integer i
36+
37+
do i = 1, mx-2
38+
a(i) = ( a(i) + a(i+1) + a(i+2) ) / 3.0e0
39+
end do
40+
41+
end
42+

Diff for: day2/floating-point-code/mathopt/prog2a

19.2 KB
Binary file not shown.

Diff for: day2/floating-point-code/mathopt/prog2b

19.2 KB
Binary file not shown.

Diff for: day2/floating-point-code/mathopt/prog2c

21 KB
Binary file not shown.

Diff for: day2/floating-point-code/mathopt/prog2d

21 KB
Binary file not shown.

Diff for: day2/floating-point-code/mathopt/prog3

19.2 KB
Binary file not shown.

Diff for: day2/floating-point-code/mathopt/prog3.f

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
program main3
2+
c
3+
c
4+
c
5+
implicit none
6+
integer mx
7+
parameter( mx = 100000 )
8+
real a(mx)
9+
real one_over3
10+
11+
integer i
12+
! define 1/3
13+
one_over3=1.0/3.0
14+
! Initialize the array
15+
16+
do i = 1, mx
17+
a(i) = float(i)
18+
end do
19+
20+
! Average the array
21+
do i = 1, 10000
22+
call xaver( a, mx ,one_over3)
23+
end do
24+
write(*,'(E22.14,2X,E22.14,2X,E22.14)')
25+
& a(10000), 20000.0e0,
26+
& (a(10000)-20000.0e0)
27+
end
28+
29+
30+
subroutine xaver( a, mx,one_over3 )
31+
c
32+
c Average the data in i direction.
33+
c
34+
implicit none
35+
integer mx
36+
real a(mx)
37+
real one_over3
38+
integer i
39+
40+
do i = 1, mx-2
41+
a(i) = ( a(i) + a(i+1) + a(i+2) ) * one_over3
42+
end do
43+
44+
end
45+

Diff for: day2/floating-point-code/paranoia/Makefile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
CC = gcc
2+
3+
CFLAGS = $(ABI) $(ARCH)
4+
5+
TARGETS = prog1 prog2 prog3 prog4 prog5
6+
SRC = paranoia.c args.h
7+
8+
default: all
9+
10+
prog1: $(SRC)
11+
$(CC) -o $@ $(ABI) $(ARCH) \
12+
-O0 -mfpmath=387 paranoia.c -lm
13+
14+
prog2: $(SRC)
15+
$(CC) -o $@ $(ABI) $(ARCH) \
16+
-O0 -mfpmath=sse paranoia.c -lm
17+
18+
prog3: $(SRC)
19+
$(CC) -o $@ $(ABI) $(ARCH) \
20+
-O0 -mpc80 paranoia.c -lm
21+
22+
prog4: $(SRC)
23+
$(CC) -o $@ $(ABI) $(ARCH) \
24+
-O2 -mpc64 -ansi -pedantic paranoia.c -lm
25+
26+
prog5: $(SRC)
27+
$(CC) -o $@ $(ABI) $(ARCH) \
28+
-O3 -ffast-math -funsafe-math-optimizations paranoia.c -lm
29+
30+
all: $(TARGETS)
31+
32+
clean:
33+
/bin/rm -f $(TARGETS)
34+
/bin/rm -f *.s *.w2f.f

Diff for: day2/floating-point-code/paranoia/args.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#if (defined(__cplusplus) || defined(__STDC__) || defined(c_plusplus))
2+
#define ARGS(parenthesized_list) parenthesized_list
3+
#define STDC 1
4+
#define VOID_ARG void
5+
#else
6+
#define ARGS(parenthesized_list) ()
7+
#define STDC 0
8+
#define VOID_ARG
9+
#define const
10+
#endif
11+
12+
#if !defined(EXIT_SUCCESS)
13+
#define EXIT_SUCCESS 0
14+
#define EXIT_FAILURE 1
15+
#endif

0 commit comments

Comments
 (0)