Download cpp source code

/*
 * Copyright 2021 Jeisson Hidalgo-Cespedes - Universidad de Costa Rica
 * Creates a secondary thread that greets in the standard output
 */

#include <omp.h>

#include <cstdlib>
#include <iostream>

int main(int argc, char* argv[]) {
  int thread_count = omp_get_max_threads();
  if (argc >= 2) {
    thread_count = atoi(argv[1]);
  }

  // ...
  #pragma omp parallel num_threads(thread_count) default(none) shared(std::cout)
  {
    // ...
    #pragma omp critical(cout)
    std::cout << "Hello from " << omp_get_thread_num() << " thread of "
      << omp_get_num_threads() << std::endl;
    // ...
  }
  // ...
  return 0;
}