Difference between revisions of "Programming/C-Plusplus"
From HPC
m |
m |
||
Line 40: | Line 40: | ||
<pre style="background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;"> | <pre style="background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;"> | ||
− | [username@login01 ~]$ module add gcc/ | + | [username@login01 ~]$ module add gcc/8.2.0 |
[username@login01 ~]$ g++ -o test2 -fopenmp test2.c (openMP support) | [username@login01 ~]$ g++ -o test2 -fopenmp test2.c (openMP support) | ||
[username@login01 ~]$ ./test2 | [username@login01 ~]$ ./test2 | ||
Line 53: | Line 53: | ||
The following modules are available for C | The following modules are available for C | ||
− | * module add gcc/ | + | * module add gcc/8.2.0 (GNU compiler) |
− | * module add intel/ | + | * module add intel/2018 (Intel compiler) |
Line 78: | Line 78: | ||
module purge | module purge | ||
− | module add gcc/ | + | module add gcc/8.2.0 |
export I_MPI_DEBUG=5 | export I_MPI_DEBUG=5 |
Revision as of 10:22, 10 June 2019
Contents
Programming Details
C++ is a general-purpose, imperative computer programming language. It is derived from the the C language and shares many constructs with it, it also expands into object orientated pragramming paradigms.
There is direct support for openMP and openMPI. |
Programming example
#include <omp.h> #include <iostream> int main () { int thread_number; #pragma omp parallel private(thread_number) { #pragma omp for schedule(static) nowait for (int i = 0; i < 100; i++) { thread_number = omp_get_thread_num(); cout << "Thread " << thread_number << " says " << i << endl; } } return 0; }
Compilation
The program would be compiled in the following way, optional Intel compiler available too:
[username@login01 ~]$ module add gcc/8.2.0 [username@login01 ~]$ g++ -o test2 -fopenmp test2.c (openMP support) [username@login01 ~]$ ./test2 Thread 22 says 32 Thread 11 says 39 .....
Modules Available
The following modules are available for C
- module add gcc/8.2.0 (GNU compiler)
- module add intel/2018 (Intel compiler)
Note: OpenMP is a library directive within the compiler and does not require any additional module to be loaded.
Usage Examples
Batch example
#!/bin/bash #SBATCH -J openmpi-single-node #SBATCH -N 1 #SBATCH --ntasks-per-node 28 #SBATCH -o %N.%j.%a.out #SBATCH -e %N.%j.%a.err #SBATCH -p compute #SBATCH --exclusive echo $SLURM_JOB_NODELIST module purge module add gcc/8.2.0 export I_MPI_DEBUG=5 export I_MPI_FABRICS=shm:tmi export I_MPI_FALLBACK=no /home/user/CODE_SAMPLES/OPENMP/demo
[username@login01 ~]$ sbatch demo.job Submitted batch job 234552
Further Information
- https://en.wikipedia.org/wiki/C%2B%2B
- https://en.wikipedia.org/wiki/OpenMP
- http://www.openmp.org/
- https://computing.llnl.gov/tutorials/openMP/