Portal:Perl+OpenMP
Introduction
WIth most perl binaries compiled with a version of GCC that supports OpenMP in some form, it make a lot of sense to explore the use of OpenMP with Perl programs - and to make it much easier. This is where the Perl+OpenMP Project comes into play. The following page is really meant to be an overview of what is possible and the resources available to those interested in such efforts.
See Also
See main project site, https://github.com/Perl-OpenMP/ for more information.
Quick Start
#!/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__
Alternate Compiler Support
This section will cover using Perl+OpenMP on compilers other than GCC. The trick is to adapt `Alien::OpenMP` to support other compilers that can be used to compile `perl` and also support OpenMP.
Special Topics
Intel Xeon Phi Co-Processor
section in process ...