Skip to content

Commit 9a96b65

Browse files
committed
Update chapter 7
1 parent 4796a08 commit 9a96b65

File tree

10 files changed

+71
-63
lines changed

10 files changed

+71
-63
lines changed

README.md

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,11 @@ Course 'CS205 C/C++ Program Design' in 2021 Fall at Southern University of Scien
4444
* [Lab notes](week07/Lab07.pptx)
4545
* [Examples](week07/examples)
4646

47-
## Chapter 8: Speedup Your Program
48-
49-
### Compiler options (-O3 for GCC, -Wall, etc…)
50-
51-
### SIMD (SSE, AVX, NEON, RISC-V, Universal Intrinsics of OpenCV)
52-
53-
### OpenMP
54-
55-
### Memory Hierarchies and Speed
56-
57-
### Crop ROI from a 2D Matrix
58-
59-
### Intel, ARM and RISC-V Architechture
60-
61-
### Lab:
62-
63-
Create two 1Mx1K float matrices matA and matB, compute matA + matB.
64-
65-
* compute the result row by row and col by col, compare the performance difference
66-
* use -O3 to improve the speed
67-
* improve the speed using SIMD, will the speed be improved? Why?
47+
## [Chapter 8: Speedup Your Program](week08/README.md)
6848

49+
* [Lecture notes](week08/Lecture08.pptx)
50+
* [Lab notes](week08/Lab08.pptx)
51+
* [Examples](week08/examples)
6952

7053
## Chapter 9: Basics of Classes
7154

week07/Lecture07.pptx

1.47 KB
Binary file not shown.

week07/examples/function-pointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ float (*norm_ptr)(float x, float y); //norm_ptr is a function pointer
88

99
int main()
1010
{
11-
norm_ptr = &norm_l1; //Pointer norm_ptr is pointing to norm_l1
11+
norm_ptr = norm_l1; //Pointer norm_ptr is pointing to norm_l1
1212
cout << "L1 norm of (-3, 4) = " << norm_ptr(-3.0f, 4.0f) << endl;
1313

1414
norm_ptr = &norm_l2; //Pointer norm_ptr is pointing to norm_l2

week07/examples/function-reference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ float (&norm_ref)(float x, float y) = norm_l1; //norm_ref is a function referenc
88

99
int main()
1010
{
11-
cout << "L1 norm of (-3, 4) = " << norm_ref(-3.0f, 4.0f) << endl;
11+
cout << "L1 norm of (-3, 4) = " << norm_ref(-3, 4) << endl;
1212
return 0;
1313
}
1414

week07/examples/overload.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ int main()
3232
cout << "sum = " << sum(1.1f, 2.2f) << endl;
3333
cout << "sum = " << sum(1.1, 2.2) << endl;
3434

35-
// //which function will be called?
36-
// cout << "sum = " << sum(1, 2.2) << endl;
35+
//which function will be called?
36+
cout << "sum = " << sum(1, 2.2) << endl;
3737

3838
return 0;
3939
}

week07/examples/recursion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void div2(double val)
1313
{
1414

1515
cout << "Entering val = " << val << endl;
16-
if (val > 0.1)
16+
if (val > 1.0)
1717
div2( val / 2); // function calls itself
1818
else
1919
cout << "--------------------------" << endl;

week07/examples/template1.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
#include <typeinfo>
3+
using namespace std;
4+
5+
template<typename T>
6+
T sum(T x, T y)
7+
{
8+
cout << "The input type is " << typeid(T).name() << endl;
9+
return x +
10+
y;
11+
}
12+
// Explicitly instantiate
13+
template double sum<double>(double, double);
14+
15+
int main()
16+
{
17+
auto val = sum(4.1, 5.2);
18+
cout << val << endl;
19+
return 0;
20+
}

week07/examples/template2.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
#include <typeinfo>
3+
using namespace std;
4+
5+
template<typename T>
6+
T sum(T x, T y)
7+
{
8+
cout << "The input type is " << typeid(T).name() << endl;
9+
return x + y;
10+
}
11+
12+
int main()
13+
{
14+
// Implicitly instantiates product<int>(int, int)
15+
cout << "sum = " << sum<int>(2.2f, 3.0f) << endl;
16+
// Implicitly instantiates product<float>(float, float)
17+
cout << "sum = " << sum(2.2f, 3.0f) << endl;
18+
19+
return 0;
20+
}

week07/function-template.cpp

Lines changed: 0 additions & 37 deletions
This file was deleted.

week08/REAME.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
# Chapter 8: Speedup Your Program
3+
4+
## Compiler options (-O3 for GCC, -Wall, etc…)
5+
6+
## SIMD (SSE, AVX, NEON, RISC-V, Universal Intrinsics of OpenCV)
7+
8+
## OpenMP
9+
10+
## Memory Hierarchies and Speed
11+
12+
## Crop ROI from a 2D Matrix
13+
14+
## Intel, ARM and RISC-V Architechture
15+
16+
## Lab:
17+
18+
Create two 1Mx1K float matrices matA and matB, compute matA + matB.
19+
20+
* compute the result row by row and col by col, compare the performance difference
21+
* use -O3 to improve the speed
22+
* improve the speed using SIMD, will the speed be improved? Why?

0 commit comments

Comments
 (0)