-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenMP.pm
137 lines (90 loc) · 3.07 KB
/
OpenMP.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package OpenMP;
use strict;
use warnings;
use OpenMP::Simple;
use OpenMP::Environment;
my $VERSION = q{1.0.2};
sub new {
my ($pkg) = shift;
return bless {
env => OpenMP::Environment->new,
}, $pkg;
}
sub env {
return shift->{env};
}
777
__END__
=head1 NAME
OpenMP - Metapackage for using OpenMP in Perl
=head1 SYNOPSIS
#!/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;
}
=head1 DESCRIPTION
Currently all this module does is eliminates a little boiler plate, but this
also makes documentation and tutorials much more clear. It also makes it easier
to install everything needed since this module will pull in L<OpenMP::Simple>
and L<OpenMP::Environment>.
Installing this module will also install whichever of the following modules are
not already on your system: L<OpenMP::Environment>, L<OpenMP::Simple>, L<Inline::C>,
and L<Alien::OpenMP>.
OpenMP::Simple - provides C MACROS and convenient runtime functions for use in the
Perl environment; e.g., C<PerlOMP_GETENV_BASIC>.
OpenMP::Environment - provides accessors for environmental variables the OpenMP
run-time considers important; e.g., C<OMP_NUM_THREADS>.
=head1 METHODS
There are just 2 methods,
=over 4
=item B<new>
constructor, only needed if you're going to use the next method, which means
you're updating OpenMP variables in the environment.
=item B<env>
chainable accessor to the L<OpenMP::Environment> reference that is created when
the constructor B<new> used.
=back
=head1 SEE ALSO
This is a module that aims at making it easier to bootstrap Perl+OpenMP
programs. It is designed to work together with L<OpenMP::Environment> and
L<OpenMP::Simple>.
B<Project website:> L<https://github.com/Perl-OpenMP>.
This module heavily favors the C<GOMP> implementation of the OpenMP
specification within gcc. In fact, it has not been tested with any other
implementations because L<Alien::OpenMP> doesn't support anything other
than GCC at the time of this writing due to lack of anyone asking for it.
L<https://gcc.gnu.org/onlinedocs/libgomp/index.html>
Please also see the C<rperl> project for a glimpse into the potential future
of Perl+OpenMP, particularly in regards to thread-safe data structures.
L<https://www.rperl.org>
=head1 AUTHOR
Brett Estrade L<< <[email protected]> >>
=head1 LICENSE & COPYRIGHT
Same as Perl.