Skip to content

Commit

Permalink
Merge pull request #28 from lukemartinlogan/main
Browse files Browse the repository at this point in the history
Change html to md
  • Loading branch information
lukemartinlogan authored Dec 13, 2024
2 parents 21c8248 + 4398e44 commit 193f7b3
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ this file there are two options.
g++ src/database_lib.cc -I${PWD}/include -fpic -c -o build/database_lib.o
```

-I${PWD}/include will ensure the compiler searches the include directory
``-I${PWD}/include`` will ensure the compiler searches the include directory
for headers

### Fix 2: Environment Variables
Expand Down Expand Up @@ -234,7 +234,7 @@ g++ src/grocery_db.cc -I${PWD}/include -L${PWD}/build -ldatabase_lib -o build/gr
g++ src/movies_db.cc -I${PWD}/include -L${PWD}/build -ldatabase_lib -o build/movies_db
```

-L${PWD}/build tells the compiler to search this directory for shared objects.
``-L${PWD}/build`` tells the compiler to search this directory for shared objects.

### Fix 2: Environment Variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY

CMAKE_BINARY_DIR is automatically provided by CMake. This is the absolute
path to the directory which contains the root CMake. In our case, this would
be "cd ${GRC_TUTORIAL}/cpp/03-cpp-build-with-cmake".
be ``cd ${GRC_TUTORIAL}/cpp/03-cpp-build-with-cmake``.

In this example, we output all executables and shared objects to the bin
directory.
Expand Down Expand Up @@ -259,14 +259,14 @@ include_directories(${CMAKE_SOURCE_DIR}/include)
```

*include_directories* will ensure that header files can be discovered
by the C++ compiler. This is analagous to the "-I" flag in the gcc
by the C++ compiler. This is analagous to the ``-I`` flag in the gcc
compiler. Here we ensure that the compiler will search the directory
${CMAKE_SOURCE_DIR}/include for header files.
``${CMAKE_SOURCE_DIR}/include`` for header files.

CMAKE_SOURCE_DIR is provided automatically by CMake. It represents
the absolute path to the directory containing the root CMakeLists.txt.
In our case, this constant would expand to
"cd ${GRC_TUTORIAL}/cpp/03-cpp-build-with-cmake/".
``cd ${GRC_TUTORIAL}/cpp/03-cpp-build-with-cmake/``.

### Creating a Shared Library
```cmake
Expand All @@ -283,12 +283,12 @@ target_link_libraries(database_lib
input the path to all source files related to the build. The SHARED indicates
this library is shared (as opposed to static). Here, there is only one source
file, datbase_lib.cc. The output of this command will be "libdatabase_lib.so" in
the "build/lib" directory.
the ``build/lib`` directory.

CMAKE_CURRENT_SOURCE_DIR is provided automatically by CMake. It represents
the absolute path to the directory containing the CMakeLists.txt currently
being processed. In our case, this constant would expand to
"cd ${GRC_TUTORIAL}/cpp/03-cpp-build-with-cmake/src".
``cd ${GRC_TUTORIAL}/cpp/03-cpp-build-with-cmake/src``.

*target_link_libraries* will link all necessary libraries necessary to compile the target database_lib.
This is analagous to the "-l" flag in gcc. In our case, we link against the
Expand Down Expand Up @@ -339,14 +339,14 @@ install(

*install* defines what happens when a user calls "make install". In this
case we specify that our targets database_lib, grocery_db, and movies_db
should be installed into one of LIBRARY, ARCHIVE, or RUNTIME depending
should be installed into one of ``LIBRARY``, ``ARCHIVE``, or ``RUNTIME`` depending
on its type. For example, database_lib will be installed to LIBRARY
(since we used add_library), whereas grocery_db and movies_db will be installed
to RUNTIME (since we used add_executable).
to ``RUNTIME`` (since we used add_executable).

CMAKE_INSTALL_PREFIX is a constant provided by CMake which represents
``CMAKE_INSTALL_PREFIX`` is a constant provided by CMake which represents
where files should be installed. This can be configured by users by passing
-DCMAKE_INSTALL_PREFIX to their CMake build. By default, the value of this
``-DCMAKE_INSTALL_PREFIX`` to their CMake build. By default, the value of this
constant is /usr.

### Installing Header Files
Expand All @@ -364,8 +364,8 @@ install(
```

In this case, we use *install* to specify
that the specific file ${CMAKE_SOURCE_DIR}/include/database_lib.h should be
installed to ${CMAKE_INSTALL_PREFIX}/include. Here, we use the keyword
that the specific file ``${CMAKE_SOURCE_DIR}/include/database_lib.h`` should be
installed to ``${CMAKE_INSTALL_PREFIX}/include``. Here, we use the keyword
FILES instead of the keyword TARGET. Targets are defined using a CMake
function such as add_executable or add_library. Files are just the way
they are with no modification.
Expand All @@ -386,18 +386,18 @@ set_property(TEST test_movies_db PROPERTY ENVIRONMENT
```

*add_test* creates a CTest case. Here we create two tests: test_grocery_db
and test_movies_db. The test will execute the command ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/grocery_db.
and test_movies_db. The test will execute the command ``${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/grocery_db``.

CMAKE_RUNTIME_OUTPUT_DIRECTORY is a constant provided by CMake. It
is the location where an executable is installed after performing the
"make" command.

*set_property* sets some sort of property about a target. In this
case the target is the test case test_movies_db. We are setting
an environment variable LD_LIBRARY_PATH. From section 3.2, we
an environment variable ``LD_LIBRARY_PATH``. From section 3.2, we
saw that we needed to be very careful about ensuring the OS
knows where shared libraries are located. In this case, we
ensure the OS will check the path ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}.
ensure the OS will check the path ``${CMAKE_LIBRARY_OUTPUT_DIRECTORY}``.

CMAKE_LIBRARY_OUTPUT_DIRECTORY is a constant provided by CMake. It
is the location where a shared library is installed after performing
Expand Down Expand Up @@ -456,11 +456,12 @@ This will run unit tests verbosely, meaning that terminal outputs
will not be hidden. -VV indicates making the tests verbose

You should see something like:
<pre>UpdateCTestConfiguration from :/home/lukemartinlogan/Documents/Projects/PhD/scs-tutorial/3.3.building_cpp_cmake/build/DartConfiguration.tcl
Parse Config file:/home/lukemartinlogan/Documents/Projects/PhD/scs-tutorial/3.3.building_cpp_cmake/build/DartConfiguration.tcl
UpdateCTestConfiguration from :/home/lukemartinlogan/Documents/Projects/PhD/scs-tutorial/3.3.building_cpp_cmake/build/DartConfiguration.tcl
Parse Config file:/home/lukemartinlogan/Documents/Projects/PhD/scs-tutorial/3.3.building_cpp_cmake/build/DartConfiguration.tcl
Test project /home/lukemartinlogan/Documents/Projects/PhD/scs-tutorial/3.3.building_cpp_cmake/build
```bash
UpdateCTestConfiguration from :/home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/DartConfiguration.tcl
Parse Config file:/home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/DartConfiguration.tcl
UpdateCTestConfiguration from :/home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/DartConfiguration.tcl
Parse Config file:/home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/DartConfiguration.tcl
Test project /home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Expand All @@ -470,9 +471,10 @@ Checking test dependency graph end
test 1
Start 1: test_grocery_db

1: Test command: /home/lukemartinlogan/Documents/Projects/PhD/scs-tutorial/3.3.building_cpp_cmake/build/bin/grocery_db
1: Environment variables:
1: LD_LIBRARY_PATH=/home/lukemartinlogan/Documents/Projects/PhD/scs-tutorial/3.3.building_cpp_cmake/build/bin
1: Test command: /home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/bin/grocery_db
1: Working Directory: /home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/test
1: Environment variables:
1: LD_LIBRARY_PATH=/home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/bin
1: Test timeout computed to be: 1500
1: grocery: in create
1: grocery: in read
Expand All @@ -482,20 +484,21 @@ test 1
test 2
Start 2: test_movies_db

2: Test command: /home/lukemartinlogan/Documents/Projects/PhD/scs-tutorial/3.3.building_cpp_cmake/build/bin/movies_db
2: Environment variables:
2: LD_LIBRARY_PATH=/home/lukemartinlogan/Documents/Projects/PhD/scs-tutorial/3.3.building_cpp_cmake/build/bin
2: Test command: /home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/bin/movies_db
2: Working Directory: /home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/test
2: Environment variables:
2: LD_LIBRARY_PATH=/home/luke/Documents/Projects/grc-tutorial/cpp/03-cpp-build-with-cmake/build/bin
2: Test timeout computed to be: 1500
2: movies: in create
2: movies: in read
2: movies: in update
2: movies: in delete
2/2 Test #2: test_movies_db ................... Passed 0.00 sec

<font color="#4E9A06">100% tests passed</font>, 0 tests failed out of 2
100% tests passed, 0 tests failed out of 2

Total Test time (real) = 0.01 sec
</pre>
```

#### Installing

Expand Down
36 changes: 19 additions & 17 deletions docs/02-hpc-tutorials/04-cpp-introduction/04-cpp-basic-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ in 3.06.

|Name|Description|
|-------|----------|
|A < B|Less than operator. A is less than B.|
|A <= B|Less than or equal operator. A is at most B.|
|A > B|Greater than operator. A is larger than B.|
|A >= B|Greater than or equal operator. A is at least B.|
|A == B|Equality operator. A and B are the same|
|A != B|Inequality operator. A and B are not the same.|
|A && B|AND operator. Both A and B are true.|
|A \|\| B|OR operator. One of A or B is true.|
|!A|NOT operator. Check if A is not true.|
|``A < B``|Less than operator. A is less than B.|
|``A <= B``|Less than or equal operator. A is at most B.|
|``A > B``|Greater than operator. A is larger than B.|
|``A >= B``|Greater than or equal operator. A is at least B.|
|``A == B``|Equality operator. A and B are the same|
|``A !\= B``|Inequality operator. A and B are not the same.|
|``A && B``|AND operator. Both A and B are true.|
|``A \\ B``|OR operator. One of A or B is true.|
|``!A``|NOT operator. Check if A is not true.|

### If-Else

Expand Down Expand Up @@ -514,7 +514,8 @@ which demonstrates the following:

This is technically the way C++ recommends to do File I/O in general.
In HPC, it doesn't get used very often, though. Most HPC programs use
STDIO or POSIX. However, we introduce here anyway.
STDIO or POSIX. However, we introduce here anyway. It is located in
[libstdc.cc](https://github.com/grc-iit/grc-tutorial/blob/main/cpp/04-cpp-basic-syntax/src/libstd.cc).

```cpp
#include <iostream>
Expand Down Expand Up @@ -561,7 +562,7 @@ int main() {

To compile & run the code:
```bash
cd ${GRC_TUTORIAL}/3.5.basics
cd ${GRC_TUTORIAL}/cpp/04-cpp-basic-syntax
mkdir build
cd build
make
Expand All @@ -576,7 +577,7 @@ Hello, World!
### STDIO

The following example demonstrates the basics of the STDIO API.
The code is located in [libstd.cc]().
The code is located in [stdio.cc](https://github.com/grc-iit/grc-tutorial/blob/main/cpp/04-cpp-basic-syntax/src/stdio.cc).

```cpp
#include <stdio.h>
Expand Down Expand Up @@ -641,7 +642,7 @@ int main() {

To compile & run the code:
```bash
cd ${GRC_TUTORIAL}/3.5.basics
cd ${GRC_TUTORIAL}/cpp/04-cpp-basic-syntax
mkdir build
cd build
make
Expand All @@ -656,6 +657,7 @@ Hello, World!
### POSIX

The following example demonstrates the basics of the POSIX API.
It is located in [posix.cc](https://github.com/grc-iit/grc-tutorial/blob/main/cpp/04-cpp-basic-syntax/src/posix.cc).

```cpp
#include <stdio.h>
Expand Down Expand Up @@ -720,7 +722,7 @@ int main() {

To compile & run the code:
```bash
cd ${GRC_TUTORIAL}/3.5.basics
cd ${GRC_TUTORIAL}/cpp/04-cpp-basic-syntax
mkdir build
cd build
make
Expand Down Expand Up @@ -811,7 +813,7 @@ int main() {
To compile & run the code:
```bash
cd ${GRC_TUTORIAL}/3.5.basics
cd ${GRC_TUTORIAL}/cpp/04-cpp-basic-syntax
mkdir build
cd build
make
Expand Down Expand Up @@ -924,7 +926,7 @@ ends when both of these statements are no longer true.
To get the dataset, run the following:
```bash
cd ${GRC_TUTORIAL}/3.5.basics
cd ${GRC_TUTORIAL}/cpp/04-cpp-basic-syntax
mkdir build
cd build
make
Expand Down Expand Up @@ -957,7 +959,7 @@ Average CO: 280
```

Your Objectives:
1. Create a file called my_analyze_kitchen_fire.cc in the ${GRC_TUTORIAL}/3.5.basics directory
1. Create a file called my_analyze_kitchen_fire.cc in the ``${GRC_TUTORIAL}/cpp/04-cpp-basic-syntax`` directory
2. Edit the CMakeLists.txt in that directory to compile your code. Feel free to look at how the other sources in that directory were compiled.
3. How do you read "kitchen_fire.bin" and interpret its contents?
4. How do you analyze its contents to determine the start, end, and average
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ It can be installed as follows:
python3 -m pip install cpplint
```

We have the following code located [here]().
```cpp
// Copyright [year] <Copyright Owner>

Expand Down
4 changes: 2 additions & 2 deletions docs/02-hpc-tutorials/04-cpp-introduction/06-cpp-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public:
In this example, we overload the addition operator to perform complex number addition.

### 3.6.04.3. Relational Operators
Relational operators (==, !=, <, >, <=, >=) can be overloaded to define custom comparison logic for objects of your class.
Relational operators (``==``, ``!=``, ``<``, ``>``, ``<=``, ``>=``) can be overloaded to define custom comparison logic for objects of your class.

Example:

Expand Down Expand Up @@ -190,7 +190,7 @@ public:
In this example, we overload the function call operator to create an object that behaves like a function, adding two integers.
### Bitwise Operators
Bitwise operators (&, |, ^, ~, <<, >>) can be overloaded to define custom bitwise operations for objects of your class.
Bitwise operators (`&`, `|`, `^`, `~`, `<<`, `>>`) can be overloaded to define custom bitwise operations for objects of your class.
Example:
Expand Down
2 changes: 1 addition & 1 deletion docs/02-hpc-tutorials/05-docker/01-docker-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ sudo docker build -t [IMAGE_NAME] [DOCKERFILE_DIR, can be a github link] -f [DOC
2. DOCKERFILE_DIR: the directory containing the Dockerfile.
3. DOCKERFILE_NAME: the name of the dockerfile in that directory. This is optional. Default: Dockerfile.

Let's say that our Dockerfile is located at ${HOME}/MyDockerfiles/Dockerfile.
Let's say that our Dockerfile is located at ``${HOME}/MyDockerfiles/Dockerfile``.
We could build the image two ways:
```
# Option 1: a single command
Expand Down
13 changes: 5 additions & 8 deletions docs/02-hpc-tutorials/05-docker/02-docker-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ is a subdirectory of the current working directory.
```bash
ssh-keygen -t rsa -f ${PWD}/id_rsa -N "" -q
```
**-t rsa** uses RSA for the algorithm.
**-f ${PWD}/id_rsa** defines the output for the private key to be in this directory.
**-N ""** indicates no password should be generated.
**-q** disables interactive prompts.
* ``-t rsa`` uses RSA for the algorithm.
* ``-f ${PWD}/id_rsa`` defines the output for the private key to be in this directory.
* ``-N ""`` indicates no password should be generated.
* ``-q`` disables interactive prompts.

## OpenSSH-Server Dockerfile

Expand Down Expand Up @@ -190,16 +190,13 @@ sudo docker-compose exec -u sshuser node2 hostname
```

These commands should print "node1" and "node2".
![docker-compose exec hostname results](images/5/5.2.7.docker-exec-hostname.png)

Next, we will try performing ssh from one node into the other.
```bash
sudo docker-compose exec -u sshuser node1 ssh node2 hostname
```

The above command will execute "ssh node2 hostname" in node1. Its
result should be:
![docker-compose exec ssh results](images/5/5.2.7.ssh-test.png)
The above command will execute "ssh node2 hostname" in node1.

## Interactive shell with cluster nodes

Expand Down
Loading

0 comments on commit 193f7b3

Please sign in to comment.