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

Tutorials

Books

Videos

Popular repositories Loading

  1. p5-OpenMP-Simple p5-OpenMP-Simple Public

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

    Perl 2

  2. p5-OpenMP-Environment p5-OpenMP-Environment Public

    Perl interface for manipulating OpenMP's environmental runtime execution variables

    Fortran 1 1

  3. p5-Alien-OpenMP p5-Alien-OpenMP Public

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

    Perl 1 4

  4. perl-openmp-examples perl-openmp-examples Public archive

    various examples of OpenMP and Perl/perl...

    Perl 1

  5. 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

  6. p5-Tie-OpenMP-Experimental p5-Tie-OpenMP-Experimental Public

    As the namespace suggests, experiments with Tie::*, OpenMP, and Perl data structures. NONE of this is meant for CPAN directly.

    Perl

Repositories

Showing 10 of 13 repositories
  • .github Public
    Perl-OpenMP/.github’s past year of commit activity
    0 0 0 0 Updated Nov 1, 2024
  • p5-OpenMP-Simple Public

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

    Perl-OpenMP/p5-OpenMP-Simple’s past year of commit activity
    Perl 2 0 0 0 Updated Sep 5, 2024
  • p5-OpenMP Public

    Metapackage for using OpenMP in Perl

    Perl-OpenMP/p5-OpenMP’s past year of commit activity
    Perl 0 0 0 0 Updated Jul 20, 2024
  • p5-OpenMP-Environment Public

    Perl interface for manipulating OpenMP's environmental runtime execution variables

    Perl-OpenMP/p5-OpenMP-Environment’s past year of commit activity
    Fortran 1 1 0 0 Updated Jul 17, 2024
  • Perl-OpenMP/The-Perl-Conference-2024-OpenMP’s past year of commit activity
    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"

    Perl-OpenMP/openmp-tutorial’s past year of commit activity
    C 0 40 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-OpenMP/The-Perl-Conference-2023-OpenMP’s past year of commit activity
    Perl 0 0 0 0 Updated Jul 17, 2023
  • awesome-openmp Public Forked from dautovri/awesome-openmp

    Feel free to contribute!

    Perl-OpenMP/awesome-openmp’s past year of commit activity
    0 CC0-1.0 2 0 0 Updated Dec 13, 2022
  • perl-openmp-proofs-and-concepts Public

    optional target repository challenges

    Perl-OpenMP/perl-openmp-proofs-and-concepts’s past year of commit activity
    Perl 0 0 0 0 Updated Jul 4, 2022
  • p5-Tie-OpenMP-Experimental Public

    As the namespace suggests, experiments with Tie::*, OpenMP, and Perl data structures. NONE of this is meant for CPAN directly.

    Perl-OpenMP/p5-Tie-OpenMP-Experimental’s past year of commit activity
    Perl 0 0 0 0 Updated Jun 27, 2022

Top languages

Loading…

Most used topics

Loading…