Difference between revisions of "Programming/C-Plusplus"

From HPC
Jump to: navigation , search
(Created page with "== 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 als...")
 
m (Pysdlb moved page C++ to Programming/C-Plusplus without leaving a redirect)
(No difference)

Revision as of 14:37, 6 February 2017

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 load gcc/4.9.3 (GNU compiler)
  • module load 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 -D /home/user/CODE_SAMPLES/OPENMP
#SBATCH -o %N.%j.%a.out
#SBATCH -e %N.%j.%a.err
#SBATCH -p compute
#SBATCH --exclusive

echo $SLURM_JOB_NODELIST

module purge
module load 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

Further Information