= OpenMP C = == Hello World == {{{#!C /* hellp_omp.c: display a message on the screen */ #include #include int main () { int id, nthreads; printf("C Start\n"); #pragma omp parallel private(id) { id = omp_get_thread_num(); printf("hello from %d\n", id); #pragma omp barrier if ( id == 0 ) { nthreads = omp_get_num_threads(); printf("%d threads said hello!\n",nthreads); } } printf("End\n"); } }}} === Compile with GNU C === {{{gcc hello_omp.c -fopenmp}}} === Compile with Intel C === {{{ module load intel-psxe icc hello_omp.c -openmp }}} === Example of Jobscript === {{{#!sh #!/bin/bash #SBATCH --job-name=HelloC_OMP #SBATCH --qos=normal #SBATCH --time=00:10:00 #SBATCH --nodes=1 #SBATCH --ntasks-per-node=1 #SBATCH --cpus-per-task=4 ########## THE JOB ITSELF ########### export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK echo Start Job pwd echo $SLURM_JOB_NODELIST ./a.out echo End job }}}