Difference between revisions of "Programming/C-Plusplus"
From HPC
m |
m |
||
Line 51: | Line 51: | ||
The following modules are available for C | The following modules are available for C | ||
− | * module | + | * module add gcc/4.9.3 (GNU compiler) |
− | * module | + | * module add intel/compiler/64/2016.2.181 (Intel compiler) |
Line 62: | Line 62: | ||
== Batch example == | == Batch example == | ||
− | <pre style="background-color: # | + | |
+ | <pre style="background-color: #f5f5dc; color: black; font-family: monospace, sans-serif;"> | ||
+ | |||
#!/bin/bash | #!/bin/bash | ||
Line 68: | Line 70: | ||
#SBATCH -N 1 | #SBATCH -N 1 | ||
#SBATCH --ntasks-per-node 28 | #SBATCH --ntasks-per-node 28 | ||
− | |||
#SBATCH -o %N.%j.%a.out | #SBATCH -o %N.%j.%a.out | ||
#SBATCH -e %N.%j.%a.err | #SBATCH -e %N.%j.%a.err | ||
Line 77: | Line 78: | ||
module purge | module purge | ||
− | module | + | module add gcc/4.9.3 |
export I_MPI_DEBUG=5 | export I_MPI_DEBUG=5 |
Revision as of 14:48, 7 February 2017
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 load gcc/4.9.3 [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/4.9.3 (GNU compiler)
- module add intel/compiler/64/2016.2.181 (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/4.9.3 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