Difference between revisions of "GPU621/Group 5"
Line 6: | Line 6: | ||
== Introduction == | == Introduction == | ||
− | Since 2020, there has been a lot of updates to the Mac OS ecosystem, and its command line interface. Which has caused for the dependancy documentation for integrating with Mac OS outdated. So this report is our comprehensive findings for interfacing with the OpenMP, TBB, and MPI libraries on Visual Studio Code to leverage Parallel Computing Concepts that are outlined in this course. As many Software Developers working on Mac already now, Visual Studio for Mac only supports some languages, one of which '''isn’t C/C++'''. So we’ll be using the common and popular text editor, Visual Studio Code. Visual Studio Code will allow us to use the command line interface for our compiler to integrate and option the dependancies that we want to use. | + | Since 2020, there has been a lot of updates to the Mac OS ecosystem, and its command line interface. Which has caused for the dependancy documentation for integrating with Mac OS outdated. So this report is our comprehensive findings for interfacing with the OpenMP, TBB, and MPI libraries on Visual Studio Code to leverage Parallel Computing Concepts that are outlined in this course. As many Software Developers working on Mac already now, Visual Studio for Mac only supports some languages, one of which '''isn’t C/C++'''. So we’ll be using the common and popular text editor, Visual Studio Code. Visual Studio Code will allow us to use the command line interface for our compiler to integrate and option the dependancies that we want to use. |
You should already have downloaded and installed: | You should already have downloaded and installed: | ||
Line 16: | Line 16: | ||
Note: Installing Visual Studio Code and the HPC packages are not apart of the scope of this report. The installation is straight forward through the wizard. | Note: Installing Visual Studio Code and the HPC packages are not apart of the scope of this report. The installation is straight forward through the wizard. | ||
− | + | ||
=== Vocabulary === | === Vocabulary === | ||
Going forward, we’ll be using these terms: | Going forward, we’ll be using these terms: | ||
Line 135: | Line 135: | ||
{ | { | ||
// OpenMP - Runtime Routines | // OpenMP - Runtime Routines | ||
− | // omp_hi.cpp | + | // omp_hi.cpp // for OpenMP library functions |
#include <iostream> | #include <iostream> | ||
Line 142: | Line 142: | ||
int main() { | int main() { | ||
− | #pragma omp parallel | + | #pragma omp parallel // Start of parallel region using pragma directive |
{ | { | ||
− | int tid = omp_get_thread_num(); | + | int tid = omp_get_thread_num(); // Get the ID of the current thread |
std::cout << "Hi from thread " | std::cout << "Hi from thread " | ||
− | << tid << '\n'; | + | << tid << '\n'; // Print a message showing the ID of the current thread |
} | } | ||
} | } | ||
Line 155: | Line 155: | ||
// tbb.cpp | // tbb.cpp | ||
#include <iostream> | #include <iostream> | ||
− | #include <tbb/tbb.h> | + | #include <tbb/tbb.h> // for TBB library functions |
int main() { | int main() { | ||
Line 161: | Line 161: | ||
<< TBB_VERSION_MAJOR << "." | << TBB_VERSION_MAJOR << "." | ||
<< TBB_VERSION_MINOR << " (" | << TBB_VERSION_MINOR << " (" | ||
− | << TBB_INTERFACE_VERSION << ")" << std::endl; | + | << TBB_INTERFACE_VERSION << ")" << std::endl; // Print a message showing the version of TBB being used |
} | } | ||
} | } | ||
Line 170: | Line 170: | ||
#include <stdio.h> | #include <stdio.h> | ||
− | #include <mpi.h> | + | #include <mpi.h> // for MPI library functions |
int main(int argc, char** argv) { | int main(int argc, char** argv) { | ||
Line 176: | Line 176: | ||
int rank, np; | int rank, np; | ||
− | MPI_Init(&argc, &argv); | + | MPI_Init(&argc, &argv); // Initialize MPI |
− | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | + | MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get the rank of the current process |
− | MPI_Comm_size(MPI_COMM_WORLD, &np); | + | MPI_Comm_size(MPI_COMM_WORLD, &np); // Get the total number of processes |
printf("Hello from process %d of %d\n", | printf("Hello from process %d of %d\n", | ||
− | rank, np); | + | rank, np); // Print a message showing the rank and total number of processes |
− | MPI_Finalize(); | + | MPI_Finalize(); // Finalize MPI |
return 0; | return 0; | ||
} | } | ||
} | } |
Revision as of 22:25, 2 April 2023
Contents
Investigative Report: Integrating OpenMP, TBB, and MPI into VSCode on MacOS v11.0+
Team
Introduction
Since 2020, there has been a lot of updates to the Mac OS ecosystem, and its command line interface. Which has caused for the dependancy documentation for integrating with Mac OS outdated. So this report is our comprehensive findings for interfacing with the OpenMP, TBB, and MPI libraries on Visual Studio Code to leverage Parallel Computing Concepts that are outlined in this course. As many Software Developers working on Mac already now, Visual Studio for Mac only supports some languages, one of which isn’t C/C++. So we’ll be using the common and popular text editor, Visual Studio Code. Visual Studio Code will allow us to use the command line interface for our compiler to integrate and option the dependancies that we want to use. You should already have downloaded and installed:
- Visual Studio Code,
- If not, you can find the Download and Install for it here: Visual Studio Code - Code Editing. Redefined
- Intel oneAPI Base Toolkit & Intel oneAPI HPC Toolkit
- If not, you can find the Download and Install for it here: Intel oneAPI ToolKits
Note: Installing Visual Studio Code and the HPC packages are not apart of the scope of this report. The installation is straight forward through the wizard.
Vocabulary
Going forward, we’ll be using these terms:
- CLI - Command Line Interface
- VScode - Visual Studio Code
Integrating
Before we go into specifically each library, let’s talk about how VScode handles compilers. Within VSCode, when we create a .CPP file, we can either run the code in our terminal, or we can create a task that compiles our code before launching the executable with our runtime arguments. We’ll use this **task and launch** method to setup our environment for C++.
Start by creating a regular C++ workspace:
- Open up VScode and open a directory where you want to code
- Create a C++ file, for our example we’ll call it: `helloworld.cpp`
- You can add this code into it for now:
#include <iostream> int main(int argc, char const *argv[]) { std::cout << "Hello world"; return 0; }
Tasks
From here, we want to tell VScode what **tasks** to run when we press the Run and Debug button. This will be similar to how we use terminal to build our code.
- Press Command+Shift+P
- At the search bar that comes up, type: Tasks: Configure Task and press Enter
- You’ll may see another option come up, to choose what kind of task, select “C/C++: g++ build active file” (If you don’t have other C/C++ compilers installed, you may not, “C/C++: g++ build active file” will be the default)
- This will create a folder called .vscode with a JSON file called: tasks.json
- Open the tasks.json file, it should look like this:
{ "tasks": [ { "type": "cppbuild", // Type of task "label": "C/C++: g++ build active file", // Label for the task This is important!! for our launch file "command": "/usr/bin/g++", // Which command will be used "args": [ // All the arguments that will be used at buildtime "-fdiagnostics-color=always", // Use Diagnostic colors "-g", // Create debugger data to be used "${file}", // Compile this file "-o", // Output it as "${fileDirname}/${fileBasenameNoExtension}" // The File name without the .cpp extension ], "options": { "cwd": "${fileDirname}" // The working directory that we'll run our compiler in }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }
This task tells VScode, when we use this task, run [this].command with [this].args. VScode will inject this into our terminal to automatically compile our code. This will help our VScode Debugger and help our launch task get ready for running our code.
g++ -fdiagnostics-color=always -g helloworld.cpp -o ./helloworld
Launch
Our launch file will facilitate the execution of our code, in the task.json we compiled and produced an output, here we will run our code with the correct information.
- You can create a **launch.json** file by navigating to the RUN AND DEBUG: RUN section on the left side navigator, (or use Command+Shift+D)
- You’ll see an option there that says “To customize your Run and Debug create a launch.json file”. Choose this option, it will allow us to pass arguments into our code.
- This will create a JSON file called launch.json inside the .vscode folder from before. It will look something like this:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: [1](https://go.microsoft.com/fwlink/?linkid=830387) "version": "0.2.0", "configurations": [] }
- i. You’ll see many options come up, we want to choose “C/C++: (lldb) Launch”.Now our launch.json should look like this:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(lldb) Launch", // Name of our configuration "type": "cppdbg", // Type of Launch (This type is as C++ Debugger) "request": "launch", // We are requesting to launch our code "program": "enter program name, for example ${workspaceFolder}/a.out", // Here is where we will add the name of our file "args": [], // All arguments we want to use "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "lldb" /////////////// // ADD THIS: // "preLaunchTask": "C/C++: g++ build active file" // This will tell VScode which Task to to ////////////// // |-> setup this launch } ] }
prelaunchTask: The prelaunch task is set to a string that matches the label section in our tasks. It identifies which task needs to run in order for the launch to be successful. This is where you can create multiple launch tasks that setup your files differently. We’ll be adding a task and a launch for all the library we’ll be setting up.
OpenMP
OpenMP
TBB
TBB
MPI
MPI
Testing
OpenMP
{ // OpenMP - Runtime Routines // omp_hi.cpp // for OpenMP library functions #include <iostream> #include <omp.h> int main() { #pragma omp parallel // Start of parallel region using pragma directive { int tid = omp_get_thread_num(); // Get the ID of the current thread std::cout << "Hi from thread " << tid << '\n'; // Print a message showing the ID of the current thread } } }
TBB
{ // TBB - Hello World // tbb.cpp #include <iostream> #include <tbb/tbb.h> // for TBB library functions int main() { std::cout << "Hello World from TBB " << TBB_VERSION_MAJOR << "." << TBB_VERSION_MINOR << " (" << TBB_INTERFACE_VERSION << ")" << std::endl; // Print a message showing the version of TBB being used } }
MPI
{ // MPI Program - Hello World // mpi_hello.c #include <stdio.h> #include <mpi.h> // for MPI library functions int main(int argc, char** argv) { int rank, np; MPI_Init(&argc, &argv); // Initialize MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Get the rank of the current process MPI_Comm_size(MPI_COMM_WORLD, &np); // Get the total number of processes printf("Hello from process %d of %d\n", rank, np); // Print a message showing the rank and total number of processes MPI_Finalize(); // Finalize MPI return 0; } }