<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Check this out,</p>
<p><br>
</p>
<pre
style="box-sizing: border-box; font-family: var(--fontStack-monospace, ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace); font-size: 11.9px; margin-top: 0px; margin-bottom: 0px; overflow-wrap: normal; padding: var(--base-size-16); overflow: auto; line-height: 1.45; color: rgb(31, 35, 40); background-color: var(--bgColor-muted, var(--color-canvas-subtle)); border-radius: 6px; word-break: normal; min-height: 52px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><span
class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"><span
class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);">#</span>!/usr/bin/env perl</span>
<span class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">use</span> strict;
<span class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">use</span> warnings;
<span class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">use</span> OpenMP::Simple;
<span class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">use</span> OpenMP::Environment;
<span class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">use</span> Inline (
<span class="pl-c1"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-constant);">C</span> <span
class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">=></span> <span
class="pl-s"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);"><span
class="pl-pds"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);">'</span>DATA<span
class="pl-pds"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);">'</span></span>,
<span class="pl-c1"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-constant);">with</span> <span
class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">=></span> <span
class="pl-s"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);"><span
class="pl-pds"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);">qw/</span>OpenMP::Simple<span
class="pl-pds"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);">/</span></span>,
);
<span class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">my</span> <span
class="pl-smi"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-storage-modifier-import);">$env</span> = OpenMP::Environment<span
class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">-></span>new;
<span class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">for</span> <span
class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">my</span> <span
class="pl-smi"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-storage-modifier-import);">$want_num_threads</span> ( 1 .. 8 ) {
<span class="pl-smi"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-storage-modifier-import);">$env</span><span
class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">-></span>omp_num_threads(<span
class="pl-smi"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-storage-modifier-import);">$want_num_threads</span>);
<span class="pl-smi"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-storage-modifier-import);">$env</span><span
class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">-></span>assert_omp_environment; <span
class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"><span
class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);">#</span> (optional) validates %ENV</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"><span
class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);">#</span> call parallelized C function</span>
<span class="pl-k"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);">my</span> <span
class="pl-smi"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-storage-modifier-import);">$got_num_threads</span> = _check_num_threads();
<span class="pl-c1"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-constant);">printf</span> <span
class="pl-s"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);"><span
class="pl-pds"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);">"</span>%0d threads spawned in <span
class="pl-pds"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);">"</span></span>.
<span class="pl-s"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);"><span
class="pl-pds"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);">"</span>the OpenMP runtime, expecting %0d<span
class="pl-cce" style="box-sizing: border-box;">\n</span><span
class="pl-pds"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-string);">"</span></span>,
<span class="pl-smi"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-storage-modifier-import);">$got_num_threads</span>, <span
class="pl-smi"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-storage-modifier-import);">$want_num_threads</span>;
}
<span class="pl-c1"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-constant);">__DATA__</span><span
class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"></span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);">__C__</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> </span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);">/* C function parallelized with OpenMP */</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);">int _check_num_threads() {</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> int ret = 0;</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> </span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> PerlOMP_UPDATE_WITH_ENV__NUM_THREADS /* <~ MACRO x OpenMP::Simple */</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> </span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> #pragma omp parallel</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> {</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> #pragma omp single</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> ret = omp_get_num_threads();</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> }</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> </span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"> return ret;</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);">}</span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);"></span>
<span class="pl-c"
style="box-sizing: border-box; color: var(--color-prettylights-syntax-comment);">__END__</span></pre>
<p></p>
<pre class="moz-signature" cols="72">--
Brett Estrade
Principal/Owner
Coastal Computing Services, LLC
DBA Acutis Computing and Data Consultancy
<a class="moz-txt-link-freetext" href="https://coastalcomputingservices.net">https://coastalcomputingservices.net</a>
<a class="moz-txt-link-freetext" href="https://acutisdata.com">https://acutisdata.com</a></pre>
</body>
</html>