Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
@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

Loading
Type
Select type
Language
Select language
Sort
Select order
Showing 10 of 15 repositories

Top languages

Loading…

Most used topics

Loading…

Morty Proxy This is a proxified and sanitized view of the page, visit original site.