wiki:cypress/Programming/CppExamples/OpenMpCpp

OpenMP C++

Hello World

//
//  hellp_omp.cpp: display a message on the screen
//
#include <iostream>
#include <omp.h>
 
int main () {
  int id;
  std::cout << "C++ Start" << std::endl;
#pragma omp parallel private(id)
  {
    id = omp_get_thread_num();
    std::cout <<  "hello from " << id << std::endl;
#pragma omp barrier
    if ( id == 0 ) {
      int nthreads = omp_get_num_threads();
      std::cout <<  nthreads << " threads said hello!" << std::endl;
    }
  }
  std::cout << "End" << std::endl;
}

Compile with GNU C++

g++ hello_omp.c -fopemp

Compile with PGI C++

pgcpp hello_omp.c -mp

Compile with Intel C++

icpc hello_omp.c -openmp

Example of Jobscript

See Example

Last modified 4 years ago Last modified on May 15, 2015 9:51:12 AM