From 5c1292a6d7c86f7bddec858cc67b761f10045cac Mon Sep 17 00:00:00 2001 From: oraqlle <41113853+oraqlle@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:13:06 +1000 Subject: [PATCH 1/5] Updated wording for C challenge 8 - concatenate. --- src/chapter2/challenges.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/chapter2/challenges.md b/src/chapter2/challenges.md index 1dcb954..e2e1edf 100644 --- a/src/chapter2/challenges.md +++ b/src/chapter2/challenges.md @@ -51,4 +51,6 @@ This challenge involves implementing the sum and product reductions on an array ## Challenge 8 - Array Concatenation -In this challenge you have to implement a general array concatenation function. This should join two arrays of the same type into a single array similar to `strcat()`. As an extra challenge, implement this concatenation algorithm so that if the destination buffer is not large enough, a new buffer of the required size is created and returns the pointer to the new buffer. +In this challenge you have to implement an array concatenation function. This should join two arrays of the same type into a single array, similar to `strcat()`. You will need to allocate a new block of memory and in order to store the concatenated arrays which will requires the sizes of the two input arrays to be known by the function. This function should return a pointer to the resulting array. + +> Note: The type of the array this function concatenates can be any type except `char`. From 6e707f0543d52d14afb17aec57fa038367248175 Mon Sep 17 00:00:00 2001 From: oraqlle <41113853+oraqlle@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:13:06 +1000 Subject: [PATCH 2/5] Updated wording for C challenge 8 - concatenate (#34). --- src/chapter2/challenges.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/chapter2/challenges.md b/src/chapter2/challenges.md index 1dcb954..e2e1edf 100644 --- a/src/chapter2/challenges.md +++ b/src/chapter2/challenges.md @@ -51,4 +51,6 @@ This challenge involves implementing the sum and product reductions on an array ## Challenge 8 - Array Concatenation -In this challenge you have to implement a general array concatenation function. This should join two arrays of the same type into a single array similar to `strcat()`. As an extra challenge, implement this concatenation algorithm so that if the destination buffer is not large enough, a new buffer of the required size is created and returns the pointer to the new buffer. +In this challenge you have to implement an array concatenation function. This should join two arrays of the same type into a single array, similar to `strcat()`. You will need to allocate a new block of memory and in order to store the concatenated arrays which will requires the sizes of the two input arrays to be known by the function. This function should return a pointer to the resulting array. + +> Note: The type of the array this function concatenates can be any type except `char`. From ad5cb74f2f8fab730ff5bd4647a660455573d41e Mon Sep 17 00:00:00 2001 From: oraqlle <41113853+oraqlle@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:45:39 +1000 Subject: [PATCH 3/5] Added subsection on C's `static` keyword. --- src/chapter2/vars.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/chapter2/vars.md b/src/chapter2/vars.md index da5c1fc..0fc99a6 100644 --- a/src/chapter2/vars.md +++ b/src/chapter2/vars.md @@ -51,6 +51,16 @@ Sometimes you want data to be constant or immutable. This is data that does not const int a = 4; ``` +### Static Data + +In C you can also allows you to create data that will exist for the entire lifetime of the program and is declared with the `static` keyword before the type initialiser. This kind of data is said to have static storage duration which means that it remains 'alive' or valid for the entire duration of the program and will not automatically get cleaned up when the it has left scope. This has some interesting implications but the most useful is its usage in function blocks. Static variables allow data to persist between function calls, meaning that if you invoke a function that owns a static variable; say an `int`, was left with the value `9` once the called had completed, if you were to recall the function and inspect the value the static variable it would still contain the value `9` at the start of the call. This allows you to keep data between function calls. + +```c +static int a = 9; +``` + +There are other more advanced usages of `static` that allow you to control the linkage of different translation units (source and object files) but they are beyond the scope of this book. + ## Operators Operators are the most primitive way to manipulate data and variables in C. There are four major categories for operators these being arithmetic, bitwise, logical and assignment. Each operator is written in either infix (binary), prefix or prefix (unary) form. Most operators return the result of their evaluation meaning it can can be assigned to a new variable however, some modify the data in-place, this includes all assignment operators and the increment and decrement operators (which do both). From 916c3af393907e42737f6849ea292c79aba5fe89 Mon Sep 17 00:00:00 2001 From: oraqlle <41113853+oraqlle@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:47:38 +1000 Subject: [PATCH 4/5] Fixed some typos (#40). --- src/chapter2/vars.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chapter2/vars.md b/src/chapter2/vars.md index 0fc99a6..5750f83 100644 --- a/src/chapter2/vars.md +++ b/src/chapter2/vars.md @@ -99,7 +99,7 @@ Bitwise operators are used to manipulate the individual bits of an integral type | Operator | Name | Description | Example | |:-----------------------:|:------------------:|:-----------------------------------------------------:|:-----------------------:| -| `~` | Compliment | Inverts the bits of a values | `~a` | +| `~` | Complement | Inverts the bits of a values | `~a` | | `&` | And | Ands the bits of two values | `a & b` | | | | Or | Ors the bits of two values | a | b | | `^` | Exclusive Or (Xor) | Xors the bits of two values | `a ^ b` | @@ -110,8 +110,8 @@ Bitwise operators are used to manipulate the individual bits of an integral type > > - Bitwise operators do not exist for floating point types. > - Bits are lost from shift operators. -> - Left shift (`>>`) pads with zeros ie. adds a zero in the new empty position. -> - Right shift (`<<`) pads with the most significant bit ie. the new empty position is filled with the same value as the previous occupant. +> - Left shift (`<<`) pads with zeros ie. adds a zero in the new empty position. +> - Right shift (`>>`) pads with the most significant bit ie. the new empty position is filled with the same value as the previous occupant. > - Left and right shifts are formally described respectively as: \\(a << b ≡ a * 2^{b} mod(2^{N})\\) and \\(a >> b ≡ \frac{a}{2^{b}} mod(2^{N})\\) where \\(N\\) is the numbers bits in the resulting value. ### Logical Operators From 184f434879fd661622544ea1e43675dbd9f5acbc Mon Sep 17 00:00:00 2001 From: oraqlle <41113853+oraqlle@users.noreply.github.com> Date: Tue, 25 Apr 2023 18:42:18 +1000 Subject: [PATCH 5/5] Fixed typos in chapter 1.6 --- src/chapter1/challenges.md | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/chapter1/challenges.md b/src/chapter1/challenges.md index 50cb1be..de7e7f6 100644 --- a/src/chapter1/challenges.md +++ b/src/chapter1/challenges.md @@ -16,12 +16,25 @@ To get setup: - Run: ```sh -git clone # Clone to your machine -cd # Enter clone's directory -git remote add upstream # Create link to template called 'upstream' -git remote set-url --push upstream DISABLE # Disable pushing to template -git fetch upstream # Sync with 'upstream' -git merge upstream/main --allow-unrelated-histories # Merge 'upstream' main branch with your main +# Clone to your machine +git clone + +# Enter clone's directory +cd + +# Create link to template called 'upstream' +git remote add upstream https://github.com/MonashDeepNeuron/HPC-Training-Challenges.git + +# Disable pushing to template +git remote set-url --push upstream DISABLE + +# Sync with 'upstream' +git fetch upstream + +# Merge 'upstream' main branch with your main +git merge upstream/main --allow-unrelated-histories + +# Open repository in VSCode code . ``` @@ -60,7 +73,7 @@ When you want to attempt a challenge it is good practice to create a branch. Thi git branch # Create new branch git checkout # Checkout to the new branch # or -git checkout -b # Checkout to a new branch ``` For your training. I would recommend creating a new branch for every challenge you attempt and merging them with the `main` (default) branch once you are done. This allows you to make modifications to each of your attempts independent of each other as well as make it easier to resync with the template repository should anything change at its base. it also allows you to get some meaningful practice with Git which is one of the most used developer tools in the world.