GitLab now enforces expiry dates on tokens that originally had no set expiration date. Those tokens were given an expiration date of one year later. Please review your personal access tokens, project access tokens, and group access tokens to ensure you are aware of upcoming expirations. Administrators of GitLab can find more information on how to identify and mitigate interruption in our documentation.
If you did not specify the `-o` option (see below) the compiler will produce an output file named `a.out`.
### Compiler Options
Some compile options that might be useful:
-`-o <filename>` sets the output filename for your executable
-`-Wall` enables all warnings
-`-Wextra` enables even more warnings than all warnings :astonished:
-`-pedantic` disables all compiler vendor specific language extensions so your program must be in conformance with the international standard
-`-O3` enables most optimizations
-`march=native` optimize for the hardware architecture you are compiling on
-`-std=c++14` sets the compiler to behave according to the C++14 international standard
-`-fsanitize=address` enables that address sanitizer which detects memory leaks and other problems at runtime
## Program Structure
### Main Function
You `.cpp` file requires a `main` function which specifies what your program does if you execute it:
```c++
intmain(intargc,char*argv[])
{
}
```
Any returned value will be the return code of your program. If no value is returned it will be zero. The arguments can be omitted if no command line arguments are required.
I recommend transforming the arguments to a `std::vector<std::string>`:
```c++
std::vector<std::string>args(argv,argv+argc);
```
Note that the first argument is always the executable name!
### Source and Header Files
Declarations go to header files (`.h`) , definitions go to source (`.cpp`) files. For function and class templates both, declarations and definitions have to go to header files, since they are only instantiated at the time they are used.
If functions should be able to be _inlined_ for performance reasons, their definition also has to go to the header file and the function has to be declared `inline`.
#### Header Files
Each header file must start with a `#pragma once` preprocessor instruction to avoid double inclusion and redefinition errors.
## CMake
To generate Makefiles use CMake. A project using CMake needs a `CMakeLists.txt` in its root directory. An example can be found in the `CMakeDemo` directory.
### Generating Build Files
It is advised that build files are generated in a separate directory from the source files (called an out-of-source build). To do this create a `build` directory or use the empty provided in this repository. Then run CMake:
```bash
cmake <path_to_src_dir>
```
CMake will create the necessary Makefiles for you in your `build` directory.
### Build your Project
To build the complete project run
```bash
make
```
To build only a single executable run
```bash
make <executable_name>
```
You can get rid of the build object files and executables using
```bash
make clean
```
### CMake Project Options
To edit your CMake project options run (inside your `build` directory:
```bash
ccmake .
```
Most importantly you can set the build type to `Debug` or `Release` where the latter activates compiler optimizations and removes debug symbols from your program.
In the demo project there is also a `SANITIZE_ADDRESS` option which enables the address sanitizer.
You can see more options if you hit `t` while in `ccmake`. Then you can also set additional `CMAKE_CXX_FLAGS`, meaning compiler options.
## Some Things you could do:
### Sanitize Your Matrix Class
Take your matrix classes using dynamic memory allocation with or without the `std::unique_ptr` and add a program which copies, moves and destroys your matrix class. Enable the address sanitizer and see if there are any issues with your code! Try to add your test program(s) as new CMake executable(s).
### Performance Measurements STL
Time some of the STL algorithms and containers we used in exercise. Compare different compiler options. A class timer is already in the CMakeDemo directory. Try to add your benchmark(s) as new CMake executable(s).
### Optimize Matrix Multiplication
There is already a `matmult` application in the CMake directory which measures the runtime of the matrix multiplication. The naive implementation performs rather poorly, try to change that! As a first step you could try to transpose the second matrix, so that you have line-wise access to both matrices during the algorithm. Secondly you could try to implement a blocking strategy (https://en.wikipedia.org/wiki/Loop_nest_optimization) to improve locality and cache reuse.