| 1 | = OpenMP C++ = |
| 2 | == Hello World == |
| 3 | {{{#!cpp |
| 4 | // |
| 5 | // hellp_omp.cpp: display a message on the screen |
| 6 | // |
| 7 | #include <iostream> |
| 8 | #include <omp.h> |
| 9 | |
| 10 | int main () { |
| 11 | int id; |
| 12 | std::cout << "C++ Start" << std::endl; |
| 13 | #pragma omp parallel private(id) |
| 14 | { |
| 15 | id = omp_get_thread_num(); |
| 16 | std::cout << "hello from " << id << std::endl; |
| 17 | #pragma omp barrier |
| 18 | if ( id == 0 ) { |
| 19 | int nthreads = omp_get_num_threads(); |
| 20 | std::cout << nthreads << " threads said hello!" << std::endl; |
| 21 | } |
| 22 | } |
| 23 | std::cout << "End" << std::endl; |
| 24 | } |
| 25 | }}} |
| 26 | == Compile with GNU C++ == |
| 27 | {{{g++ hello_omp.c -fopemp}}} |
| 28 | == Compile with PGI C++ == |
| 29 | {{{pgcpp hello_omp.c -mp}}} |
| 30 | == Compile with Intel C++ == |
| 31 | i{{{cpc hello_omp.c -openmp}}} |
| 32 | == Example of Jobscript == |
| 33 | See |