/*
 * 01-hello-openmp.c  —  Your FIRST OpenMP program
 * Session 03 · 2311CSC501J Parallel Processing
 *
 * WHAT THIS SHOWS
 *   Normal C code runs on ONE thread. Add a single line — #pragma omp parallel —
 *   and the compiler forks a whole TEAM of threads that each run the block below.
 *   Every thread introduces itself. The order they print in is NOT fixed — that is
 *   your first taste of non-deterministic parallel output.
 *
 * HOW TO COMPILE & RUN
 *   Linux / real gcc:
 *       gcc -fopenmp 01-hello-openmp.c -o hello
 *       ./hello
 *
 *   Choose how many threads (default = your core count):
 *       OMP_NUM_THREADS=4 ./hello
 *
 *   No compiler on your machine? Paste this into OnlineGDB (onlinegdb.com) or
 *   Compiler Explorer (godbolt.org, add the -fopenmp flag) and just press Run.
 *
 *   macOS note: Apple's default "clang" needs libomp:
 *       brew install libomp
 *       clang -Xpreprocessor -fopenmp -lomp 01-hello-openmp.c -o hello
 *   (or just use OnlineGDB — zero setup.)
 */

#include <stdio.h>
#include <omp.h>

int main(void) {
    /* Everything above here runs on a single "master" thread. */

    #pragma omp parallel
    {
        /* Everything INSIDE these braces runs once PER THREAD, all at once. */
        int id    = omp_get_thread_num();    /* which thread am I? (0..total-1) */
        int total = omp_get_num_threads();   /* how many of us are there?       */
        printf("Hello from thread %d of %d\n", id, total);
    }

    /* The threads have joined back into one. We're serial again. */
    return 0;
}
