Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
5eb0bd3
Update README links
juanfrh Mar 24, 2023
aadf074
Create AUTHORS
juanfrh Mar 24, 2023
f0b8566
Add license
juanfrh Mar 24, 2023
bfa24ea
Update eigen lecture & exercises
josephleekl Apr 7, 2023
e797f6c
update eigen slides
josephleekl Apr 10, 2023
4b82bd6
update footnote
josephleekl Apr 13, 2023
3d6f0fa
Updated 'intro' and 'classes' lecture slides
mcjamieson Apr 14, 2023
45b257e
Minor update to code snippet
mcjamieson Apr 14, 2023
e75e024
Merge pull request #2 from mcjamieson/main
JPRichings Apr 16, 2023
78519ce
Merge pull request #1 from josephleekl/main
JPRichings Apr 16, 2023
e682401
remove kokkos part of the course
JPRichings Feb 19, 2024
9c79e54
Edits to remove portable frameworks section.
JPRichings Feb 19, 2024
a1bc521
Updated C++23 draft version, ARCHER2 default GCC version
mcjamieson Feb 25, 2024
2e18206
Minor updates to formatting
mcjamieson Feb 25, 2024
86b0745
Merge pull request #4 from mcjamieson/main
JPRichings Apr 7, 2024
e867419
test
JPRichings Apr 8, 2024
7424eef
edits to formatting a examples
JPRichings Apr 8, 2024
0cc3466
Merge pull request #1 from EPCCed/main
JPRichings Apr 8, 2024
8fb3bf4
Merge pull request #5 from JPRichings/main
JPRichings Apr 9, 2024
f27dfbb
update exercise path
JPRichings Apr 9, 2024
1430792
Merge remote-tracking branch 'refs/remotes/origin/main'
JPRichings Apr 9, 2024
8b8d06f
Merge pull request #6 from JPRichings/main
JPRichings Apr 9, 2024
468ff02
Update intro chapter to use new module structure
NMannall Oct 11, 2024
285a27b
Allow default footer text to be overridden
NMannall Oct 15, 2024
cd26aee
Update remaining chapters for the new remark theme
NMannall Oct 15, 2024
3930af9
Merge pull request #8 from NMannall/update-remark-theme
JPRichings Oct 15, 2024
39dcd36
Update cpp intro slides
NMannall Oct 18, 2024
10aa7f7
Update classes chapter
NMannall Oct 18, 2024
b7cbd6c
Update containers and loops slides
NMannall Oct 18, 2024
de31cdd
Update resources slides and RAII examples
NMannall Oct 24, 2024
94b76b6
Update templates slides
NMannall Oct 24, 2024
cba8222
Update algorithms, lambdas and traits slides
NMannall Oct 25, 2024
5123ae5
Update exercise slides at the end of each slide deck
NMannall Oct 25, 2024
da11177
Merge pull request #9 from NMannall/refresh-material-oct-24
NMannall Oct 28, 2024
86a419f
Split containers exercise into part1 and part2 directories
NMannall Oct 28, 2024
319e59b
Merge pull request #10 from NMannall/refresh-material-oct-24
NMannall Oct 28, 2024
c383a65
Update Makefile for Archer2
rupertnash Oct 29, 2024
79e9dcb
Correct test of copying complex numbers
NMannall Mar 10, 2025
ac76a34
Check non equality of complex number imaginary part
NMannall Mar 10, 2025
d530264
Add new class types exercise
NMannall Mar 10, 2025
9350db3
Reorder classes slides and add new exercise slide
NMannall Mar 10, 2025
5f68a91
Move complex exercise to 2.2-complex folder
NMannall Mar 10, 2025
6f7a9d6
Add section numbers to section 2 exercises
NMannall Mar 10, 2025
e9b4e48
Update instructions for containers exercise
NMannall Mar 10, 2025
03ac9e3
Add new templates exercise
NMannall Mar 10, 2025
f4519d8
Add type templating to tests
NMannall Mar 10, 2025
f2098ad
Merge pull request #11 from NMannall/new-exercises-mar-25
JPRichings Mar 10, 2025
a8f0239
updates to course structure
JPRichings Mar 10, 2025
68e0a04
Merge remote-tracking branch 'refs/remotes/origin/main'
JPRichings Mar 10, 2025
1023279
update timeable
JPRichings Mar 10, 2025
d69ba22
conditionals
JPRichings Mar 10, 2025
26fbfb0
formatting
JPRichings Mar 10, 2025
1e459e2
update formatting of exercise
JPRichings Mar 10, 2025
763f893
update operator introduction
JPRichings Mar 10, 2025
e63ba1c
formatting
JPRichings Mar 10, 2025
ed8420a
formatting
JPRichings Mar 10, 2025
f4e1bf6
title update
JPRichings Mar 10, 2025
6efdfc8
formatting
JPRichings Mar 10, 2025
6af5115
pointer games
JPRichings Mar 10, 2025
d56c1bc
formatting
JPRichings Mar 11, 2025
562291c
formatting
JPRichings Mar 11, 2025
406c8a5
Exercise README updates
NMannall Mar 11, 2025
48ee51c
Merge branch 'EPCCed:main' into main
NMannall Mar 11, 2025
d2381c3
Merge pull request #13 from NMannall/main
NMannall Mar 11, 2025
8acd5b0
Correct template exercise README
NMannall Mar 11, 2025
f68bef0
my_array example added
JPRichings Mar 12, 2025
538a720
pointers exercise added
JPRichings Mar 12, 2025
3a0e1cb
special pointers exercise added
JPRichings Mar 12, 2025
6a77d50
update RAII lectures
JPRichings Mar 12, 2025
2cc9bd2
udate course timetable
JPRichings Mar 12, 2025
c428728
Merge remote-tracking branch 'refs/remotes/origin/main'
JPRichings Mar 12, 2025
fb38239
update course timetable
JPRichings Mar 12, 2025
c08c05e
Merge branch 'EPCCed:main' into main
NMannall Mar 12, 2025
08d00b7
Add some hints to complex exercise
NMannall Mar 12, 2025
79e22b9
Update exercises README
NMannall Mar 12, 2025
b3a0b99
Merge pull request #14 from NMannall/main
NMannall Mar 12, 2025
d8d97f9
correct makefile
JPRichings Mar 12, 2025
b9ae42c
update course timetable final day
JPRichings Mar 13, 2025
bd49cc7
combining classes lectures
JPRichings Mar 13, 2025
01ab353
combining classes images
JPRichings Mar 13, 2025
d067102
update combining classes exercises
JPRichings Mar 13, 2025
02c00d5
Merge remote-tracking branch 'refs/remotes/origin/main'
JPRichings Mar 13, 2025
0d7dba9
update content
JPRichings Mar 13, 2025
f5a3019
Add section numbers to lecture and exercise folders
NMannall Apr 17, 2025
7e3a799
Update eigen exercise to run on ARCHER2
NMannall Apr 17, 2025
bec368b
Update makefiles to C++17
NMannall Apr 17, 2025
030bbfa
Update Catch version
NMannall Apr 17, 2025
875349e
Add outputs from exercises to .gitignore
NMannall Apr 17, 2025
9e90c66
Add type trait extension to templates exercise
NMannall Apr 17, 2025
b723831
Update course intro slides
NMannall Apr 17, 2025
028c1a2
Update 2 day course outline
NMannall Apr 18, 2025
9414f34
Update presenters on title slides
NMannall Apr 18, 2025
c0bc4ef
Move traits to templates section
NMannall Apr 18, 2025
3df48d7
Remove duplicated pointers section
NMannall Apr 18, 2025
d04581e
Correct section numbering for pointers and my-array exercises
NMannall Apr 18, 2025
59c3d4a
Add missing executables to .gitignore
NMannall Apr 18, 2025
238a467
Merge pull request #25 from NMannall/refresh-material-apr-25
JPRichings Apr 18, 2025
1ce0a88
Correct terminal output in exercise 2.2 README
NMannall Apr 22, 2025
d548b85
Add complex number reminder slide
NMannall Apr 22, 2025
1dceb19
Update C++ intro slides
NMannall Apr 22, 2025
4035bb0
Add intro examples to .gitignore
NMannall Apr 22, 2025
b67589b
Shorten slide so text doesn't overflow
NMannall Apr 22, 2025
4328427
Merge pull request #30 from NMannall/refresh-material-apr-25
NMannall Apr 23, 2025
6ef5d3f
Update README.md
JPRichings Jul 2, 2025
8b62683
Update README.md
JPRichings Jul 2, 2025
71a20bb
Update README.md
JPRichings Jul 2, 2025
a7029e1
Fix the link to the Section 4 exercises. (#32)
rwanwork Oct 22, 2025
1a34763
Create solutions directory
NMannall Oct 22, 2025
58e23a1
Merge branch 'main' into update-solutions
NMannall Oct 22, 2025
d6afbdd
Remove duplicate lecture directories
NMannall Oct 22, 2025
06cbcaf
Update solutions folder README
NMannall Oct 22, 2025
2f6626a
Add .gitignore for solutions folder
NMannall Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ exercises/2.1-class-types/test
exercises/2.2-complex/test
exercises/3-containers/part1/test
exercises/3-containers/part2/test
exercises/4-pointers/pointers
exercises/5-templates/part1/sum
exercises/5-templates/part2/test
exercises/6.1-my-array/part*/my_array
exercises/6.2-special-pointers/part1/unique
exercises/6.2-special-pointers/part2/shared
exercises/8-algorithm/ex
exercises/9-eigen/explicit
exercises/9-eigen/implicit
exercises/9-eigen/sparse
exercises/9-eigen/*.txt
exercises/9-eigen/*.gif
exercises/10-threads/area
exercises/10-threads/area

lectures/1-cpp-intro/auto/auto
lectures/1-cpp-intro/hello/hello
lectures/1-cpp-intro/sum/sum
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Rupert Nash
Joseph Lee
395 changes: 395 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Modern C++ for Computational Scientists

Repository view: <https://github.com/EPCCed/archer2-CPP-2021-07-20>
[Repository view](https://github.com/EPCCed/archer2-cpp/)

Pages view: <https://EPCCed.github.io/archer2-CPP-2021-07-20/>
[Pages view](https://epcced.github.io/archer2-cpp/)

Since the 2011 revision to the C++ language and standard library, the
ways it is now being used are quite different. Used well, these
Expand Down
67 changes: 12 additions & 55 deletions exercises/10-threads/area.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#include <cstdio>
#include <complex>
#include <chrono>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>

using complex = std::complex<double>;

Expand All @@ -20,66 +16,27 @@ bool in_mandelbrot(const complex& c) {
return true;
}

void area(
int start,
int stop,
int npoints,
double scale_real,
double scale_imag,
int& num_inside,
std::mutex& mutex
) {
const auto eps = 1.0e-7;
const auto shift = complex{-2.0 + eps, 0.0 + eps};

for (int i = start; i < stop; ++i) {
for (int j = 0; j < npoints; ++j) {
const auto c = shift + complex{
(scale_real * i) / npoints,
(scale_imag * j) / npoints
};
if (in_mandelbrot(c)) {
mutex.lock();
num_inside++;
mutex.unlock();
}
}
}
}

int main() {
const auto NPOINTS = 2000;

const auto scale_real = 2.5;
const auto scale_imag = 1.125;

const auto eps = 1.0e-7;
const auto shift = complex{-2.0 + eps, 0.0 + eps};
using clock = std::chrono::high_resolution_clock;
auto start = clock::now();

std::mutex mutex;
// Outer loops run over npoints, initialise z=c
// Inner loop has the iteration z=z*z+c, and threshold test
int num_inside = 0;

int n_threads = 16;
std::vector<std::thread> threads;

int points_per_thread = NPOINTS / n_threads;
int i = 0;
int j = 0;

for (int id = 0; id < n_threads; ++id) {
i = id * points_per_thread;
j = i + points_per_thread;
threads.push_back(
std::thread(
area, i, j, NPOINTS, scale_real, scale_imag, std::ref(num_inside), std::ref(mutex)
)
);
}

// Wait for all threads to finish
for (auto&& thread : threads) {
thread.join();
for (int i = 0; i < NPOINTS; ++i) {
for (int j = 0; j < NPOINTS; ++j) {
const auto c = shift + complex{(scale_real * i) / NPOINTS,
(scale_imag * j) / NPOINTS};
if (in_mandelbrot(c))
num_inside++;
}
}

auto finish = clock::now();

// Calculate area and error and output the results
Expand Down
6 changes: 2 additions & 4 deletions exercises/10-threads/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Source for this can be obtained from Github. Get a new copy with:

```
git clone https://github.com/EPCCed/archer2-CPP-2021-07-20
git clone https://github.com/EPCCed/archer2-cpp
```

or update your existing one with
Expand All @@ -17,11 +17,9 @@ git pull
then you can

```
cd archer2-CPP-2021-07-20/exercises/threads
cd archer2-cpp/exercises/threads
```



`area.cpp` contains a C++ version of the Mandelbrot example which you used in Threaded Programming.

Parallelise the outer loop of the main computation using C++
Expand Down
22 changes: 9 additions & 13 deletions exercises/2.1-class-types/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@ Complex::Complex(double real, double imag) : re(real), im(imag) {
}

double Complex::real() {
return re;
// Return real component
}

double Complex::imag() {
return im;
}
/* Add definition of a member function to access the imaginary component */

Complex Complex::conj() {
return Complex{re, -im};
// Return complex conjugate
}

double Complex::norm() {
return std::sqrt(re*re + im*im);
}
/* Add definition of 'norm' member function. Hint: Look up std::sqrt from the
cmath header to help calculate the magnitude of a complex number */

Complex Complex::add(Complex other_complex) {
return Complex{re + other_complex.re, im + other_complex.im};
}
/* Add definition of 'add' member function */

bool Complex::equals(Complex other_complex) {
return re == other_complex.re && im == other_complex.im;
}
// Return true if the real and imaginary parts of the complex numbers are
// equal. False otherwise.
}
32 changes: 17 additions & 15 deletions exercises/2.1-class-types/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@
// Simple complex number class
class Complex {
public:
// Default value is zero
Complex() = default;
// Construct purely real complex
Complex(double real);
// Construct from real and imaginary parts
Complex(double real, double imag);
/* Add declarations to create:
- A default constructor
- A constructor using just a real component
- A constructor using real and imaginary components
*/

// Access components
double real();
double imag();
/* Add declaration to access the imaginary component */

// Compute the complex conjugate
Complex conj();

// Compute the magnitude
double norm();
/* Add declaration for member function 'norm' that takes no arguments and
returns the magnitude of the complex number.
*/

// Add two complex numbers
Complex add(Complex other_complex);
/* Add declaration for an 'add' member function as so: z = i.add(j)
I.e. For complex numbers i and j, z is the result of i + j.
*/

// Check if two complex numbers are equal
bool equals(Complex other_complex);

private:
double re = 0.0;
double im = 0.0;
/* Add private member variables to store the real and imaginary components of
the complex number. These should have type 'double' and a suitable default
value.
*/
};

#endif
#endif
2 changes: 1 addition & 1 deletion exercises/2.1-class-types/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ TEST_CASE("Complex number can be added") {
CheckZminusZeq0(-1);
CheckZminusZeq0(Complex{1, 2});
CheckZminusZeq0(Complex{-42, 1e-3});
}
}
7 changes: 6 additions & 1 deletion exercises/2.2-complex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ The files `complex.hpp` and `complex.cpp` contain a partially working comple
You can compile and run with:

```
$ make && ./testc++ --std=c++14 -I../include -c -o complex.o complex.cppc++ --std=c++14 -I../include -c -o test.o test.cppc++ complex.o test.o -o test===============================================================================All tests passed (34 assertions in 6 test cases)
$ make && ./test
g++ --std=c++14 -I../include -c -o complex.o complex.cpp
g++ --std=c++14 -I../include -c -o test.o test.cpp
g++ complex.o test.o -o test
===============================================================================
All tests passed (34 assertions in 6 test cases)
```

But to get to this point you need to complete the code and fix a few bugs!
15 changes: 2 additions & 13 deletions exercises/2.2-complex/complex.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#include "complex.hpp"
#include <cmath>

Complex::Complex(double real) : re(real) {
}

Complex::Complex(double real, double imag) : re(real), im(imag) {
}

double Complex::real() const {
double const& Complex::real() {
return re;
}

Expand All @@ -28,7 +24,7 @@ double Complex::norm2() const {
}

bool operator==(Complex const& a, Complex const& b) {
return (a.re == b.re) && (a.im == b.im);
return (a.re == b.re) && (a.im == b.re);
}
bool operator!=(Complex const& a, Complex const& b) {
return !(a == b);
Expand All @@ -38,16 +34,9 @@ Complex operator+(Complex const& a, Complex const& b) {
return Complex{a.re + b.re, a.im + b.im};
}

Complex operator-(Complex const& a, Complex const& b) {
return Complex{a.re - b.re, a.im - b.im};
}

Complex operator*(Complex const& a, Complex const& b) {
// (a + ib)*(c + id) == (a*c - b*d) + i(b*c + a*d)
return Complex{
a.re*b.re - a.im*b.im,
a.re*b.im + a.im*b.re
};
}

Complex operator-(Complex const& a) {
Expand Down
6 changes: 1 addition & 5 deletions exercises/2.2-complex/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ class Complex {
// Default value is zero
Complex() = default;
// Construct purely real complex
Complex(double real);
// Construct from real and imaginary parts
Complex(double real, double imag);

// Access components
double real() const;
double imag() const;

// Compute the complex conjugate
Complex conj() const;
Complex conj();

// Compute the magnitude and squared magnitude
double norm() const;
Expand All @@ -32,8 +30,6 @@ class Complex {
friend Complex operator*(Complex const& a, Complex const& b);
friend Complex operator/(Complex const& a, Complex const& b);
// Question: how would you declare multiplication and division by a real number?
friend Complex operator*(Complex const& a, double const& b);
friend Complex operator*(double const& a, Complex const& b);

// Unary negation
friend Complex operator-(Complex const& a);
Expand Down
18 changes: 0 additions & 18 deletions exercises/3-containers/part1/vector_ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,5 @@
// https://en.cppreference.com/w/cpp/container/vector

std::vector<int> GetEven(std::vector<int> const& source) {
auto ans = std::vector<int>{};
for (auto&& elem: source) {
if (elem % 2 == 0)
ans.push_back(elem);
}
return ans;
}

void PrintVectorOfInt(std::ostream& output, std::vector<int> const& data) {
output << "[ ";
bool first = true;
for (auto const& x: data) {
if (!first) {
output << ", ";
}
first = false;
output << x;
}
output << "]";
}
18 changes: 0 additions & 18 deletions exercises/3-containers/part2/vector_ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,5 @@
// https://en.cppreference.com/w/cpp/container/vector

std::vector<int> GetEven(std::vector<int> const& source) {
auto ans = std::vector<int>{};
for (auto&& elem: source) {
if (elem % 2 == 0)
ans.push_back(elem);
}
return ans;
}

void PrintVectorOfInt(std::ostream& output, std::vector<int> const& data) {
output << "[ ";
bool first = true;
for (auto const& x: data) {
if (!first) {
output << ", ";
}
first = false;
output << x;
}
output << "]";
}
10 changes: 10 additions & 0 deletions exercises/4-pointers/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CXXFLAGS = --std=c++17

pointers : pointers.o
$(CXX) $^ -o $@

run : pointers
./pointers

clean :
rm -rf *.o pointers
Loading