A05 - Hello World with OpenMP
Due Date: Tuesday 02/13/2024 @ 02:00 PM
Late Policy
- You have until the assigned due date, after that you will receive 0 points.
C++ OpenMP Hello World Assignment
Objective
Learn the basics of parallel programming in C++ using the OpenMP library. Write a program that utilizes multiple threads to print “Hello, World!” from each thread. You can use the systems{1-4}.cs.uic.edu or extreme.acer.uic.edu systems. If you use the CS machines, there is no waiting in the queue. If you use ACER resource, you need a PBS script to submit; don’t run on the login node - that is frowned upon. You will also need to make sure you have the correct modules loaded.
Starter Code
Below is the starter code for your assignment. Your task is to complete the missing part of the code.
#include <omp.h>
#include <iostream>
int main() {
// Set the number of threads
omp_set_num_threads(4);
// Parallel region begins here
#pragma omp parallel
{
int thread_id = omp_get_thread_num();
// TODO: Each thread should print "Hello, World!" followed by its thread number
}
return 0;
}
Instructions
- Ensure you have a C++ compiler and OpenMP installed on your system.
- Complete the code inside the parallel block. Each thread should print “Hello, World!” followed by its thread number.
- Compile the code using a command like
g++ -fopenmp openmp00.cc -o openmp00
(or build a Makefile). - Run the compiled program and observe the output. The order of the output might change with each execution due to the nature of parallel execution.
Expected Learning Outcome
Gaining an understanding of fundamental parallel programming concepts and developing proficiency in employing OpenMP directives to establish parallel regions.