Skip to content
@Perl-OpenMP

Perl+OpenMP

Perl and OpenMP. What could possibly go right.

Perl+OpenMP

  • discussions, visit: #system-programming on the PA&A Discord
  • email discussion list - sign up @ sourceforge.net [archive]
    (*NOTE: I am working on email deliverability issues for gmail users, maybe other "free" email sites!)

Learning OpenMP (Videos)

OpenMP Modules On CPAN

  • OpenMP - metapackage (includes following 2 modules w/lagniappe)
  • OpenMP::Simple - helper C macros and runtime functions
  • OpenMP::Environment - for managing variables in %ENV important to the OpenMP runtime

Quick Start

Install Modules

cpanm OpenMP # installs all of the above modules

First Program

Create this Perl file and execute on *nix using a perl built using gcc:

#!/usr/bin/env perl
use strict;
use warnings;
   
use OpenMP;
   
use Inline (
    C    => 'DATA',
    with => qw/OpenMP::Simple/,
);
   
my $omp = OpenMP->new;
   
for my $want_num_threads ( 1 .. 8 ) {
    $omp->env->omp_num_threads($want_num_threads);
 
    $omp->env->assert_omp_environment; # (optional) validates %ENV
 
    # call parallelized C function
    my $got_num_threads = _check_num_threads();
 
    printf "%0d threads spawned in ".
            "the OpenMP runtime, expecting %0d\n",
              $got_num_threads, $want_num_threads;
}
 
__DATA__
__C__
 
/* C function parallelized with OpenMP */
int _check_num_threads() {
  int ret = 0;
    
  PerlOMP_GETENV_BASIC
   
  #pragma omp parallel
  {
    #pragma omp single
    ret = omp_get_num_threads();
  }
 
  return ret;
}
__END__

Expected Output:

1 threads spawned in the OpenMP runtime, expecting 1
2 threads spawned in the OpenMP runtime, expecting 2
3 threads spawned in the OpenMP runtime, expecting 3
4 threads spawned in the OpenMP runtime, expecting 4
5 threads spawned in the OpenMP runtime, expecting 5
6 threads spawned in the OpenMP runtime, expecting 6
7 threads spawned in the OpenMP runtime, expecting 7
8 threads spawned in the OpenMP runtime, expecting 8

Next Program

That's up to you. Please share!

Resources

Most Used OpenMP Things (the Common Core):

  • #pragma omp parallel
  • int omp_get_thread_num()
  • int omp_get_num_threads()
  • export OMP_NUM_THREADS=N
  • #pragma omp barrier
  • #pragma omp critical
  • #pragma omp for
  • #pragma omp parallel for
  • reduction(op:list)
  • schedule(dynamic[,chunk])
  • shcedule(static,[,chunk])
  • private(list), firstprivate(list), shared(list)
  • nowait
  • #pragma omp single
  • #pragma omp task
  • #pragma omp taskwait

See more below under "Videos."

Tutorials

Books

Videos

Highlighted slides fropm this video speak of the most popular OpenMP constructs; the red boxes are items in the first edition of Common Core, the items in green are identified by Mattson candiates for an updated version of the book since they have proven emiracally to be popular. The items in the first edition were a good guess:

image

Popular repositories Loading

  1. perl-openmp-examples perl-openmp-examples Public archive

    various examples of OpenMP and Perl/perl...

    Perl 2

  2. p5-OpenMP-Simple p5-OpenMP-Simple Public

    Wrapper around Alien::OpenMP that provides helpful C macros and runtime functions

    Perl 2 1

  3. p5-OpenMP-Environment p5-OpenMP-Environment Public

    Perl interface for manipulating OpenMP's environmental runtime execution variables

    Fortran 1 1

  4. p5-Alien-OpenMP p5-Alien-OpenMP Public

    Portable buildopt interface to OpenMP enabled compiler flags and other things.

    Perl 1 4

  5. p5-OpenMP p5-OpenMP Public

    Metapackage for using OpenMP in Perl

    Perl 1

  6. The-Perl-Conference-2022-OpenMP The-Perl-Conference-2022-OpenMP Public archive

    Slides, code examples, and other artificacts from The Perl & Rakudo Conference 2022; Houston, Texas

    Perl

Repositories

Showing 10 of 15 repositories
  • p5-OpenMP-Simple Public

    Wrapper around Alien::OpenMP that provides helpful C macros and runtime functions

    Perl 2 1 3 0 Updated Mar 11, 2025
  • p5-Alien-OpenMP Public

    Portable buildopt interface to OpenMP enabled compiler flags and other things.

    Perl 1 4 6 (1 issue needs help) 0 Updated Mar 11, 2025
  • .github Public
    0 0 0 0 Updated Mar 7, 2025
  • p5-OpenMP-wxPerl Public

    demo project showing how to control OpenMP threads during runtime in a wxPerl based GUI on Windows (Strawberry Perl)

    Perl 0 0 0 0 Updated Jan 8, 2025
  • p5-OpenMP-Tests-Readonly Public

    Collection of tests and scripts consisting of OpenMP codes using the Perl API to explore the read-only nature of the Perl API

    Perl 0 0 0 0 Updated Dec 7, 2024
  • p5-OpenMP Public

    Metapackage for using OpenMP in Perl

    Perl 1 0 0 0 Updated Jul 20, 2024
  • p5-OpenMP-Environment Public

    Perl interface for manipulating OpenMP's environmental runtime execution variables

    Fortran 1 1 0 0 Updated Jul 17, 2024
  • C 0 0 0 0 Updated Jun 28, 2024
  • openmp-tutorial Public Forked from UoB-HPC/openmp-tutorial

    Exercises and Solutions for "Programming Your GPU with OpenMP: A Hands-On Introduction"

    C 0 43 0 0 Updated Nov 13, 2023
  • The-Perl-Conference-2023-OpenMP Public archive

    Slides, code examples, and other artificacts from The Perl & Rakudo Conference 2023; Toronto, Canada

    Perl 0 0 0 0 Updated Jul 17, 2023

Top languages

Loading…

Most used topics

Loading…