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 10 years ago Last modified on 05/15/15 09:51:12
Note: See TracWiki for help on using the wiki.