wiki:cypress/Programming/Cexamples/OpenMp

Version 1 (modified by cmaggio, 10 years ago) ( diff )

OpenMP C

Hello World

/*
  hellp_omp.c: display a message on the screen
*/
#include <stdio.h>
#include <omp.h>
 
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 -fopemp

Compile with Intel C

icc hello_omp.c -openmp

Example of Jobscript

#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
cat $SLURM_JOB_NODELIST
 
./a.out
 
echo End job
Note: See TracWiki for help on using the wiki.