Lesson 13

Date: 4/19/2017
High Performance Computing (part I: OpenMP)
Linux System Administration


OpenMP


  • Shared memory is used by parallel threads.
  • The master process forks threads in the parallel region of the code.



  • Parallel regions are specified by the compiler directives in the code:

    C / C++ - General Code Structure
    #include <omp.h>
    
    main()  {
    int var1, var2, var3;
    
    /* Serial code */ 
          .
          .
    /* Beginning of parallel section. Fork a team of threads. Specify variable scoping */
    
    #pragma omp parallel private(var1, var2) shared(var3)
      {
      Parallel section executed by all threads 
            .
      All threads join master thread and disband 
      }  
    /* Resume serial code */ 
    }
    

  • GNU 4.2 and newer gcc and gfortran compilers include OpenMP support.
    gcc -fopenmp testcode.c
    export OMP_NUM_THREADS=4
    ./a.out
    
  • Usually, OMP_NUM_THREADS shouldn't exceed the total number of available cores in a system.
  • If OMP_NUM_THREADS is undefined, the run will utilize all available cores on the system.


  • Take me to the Course Website