- 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!)
- The OpenMP Common Core: A hands on exploration (3.5 hrs - Tim Mattson, Intel, 2019)
- Using OpenMP in Perl (2hrs - Houston PM, May 2021)
- Introduction to OpenMP for Perl Programmers (50m - TPRC 2022)
- State of the Art: Perl and Multithreading via OpenMP (50m - TPRC 2022)
- Intermediate OpenMP for Perl Programmers (50m - TPRC 2024)
- 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
cpanm OpenMP # installs all of the above modules
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
That's up to you. Please share!
#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
- PDF The OpenMP Common Core: A journey back to the roots of OpenMP (Mattson, 2019) code
- PDF A Guide To OpenMP (Estrade, 2011)
- Amazon: The OpenMP Common Core: Making OpenMP Simple Again (Scientific and Engineering Computation) (ISBN: 0262538865)
- How Popular is OpenMP? (2023)