Alien-OpenMP

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

  };
};


__DATA__
/*
   the following should only pass if running in a properly
   supported OpenMP environment; modifications to this should
   ensure it's not just testing for a successful compile and link
*/
// done before thread fork
#include <omp.h>
int main () {
  omp_set_num_threads(3);
  int ans = 42;
// thread section follows
#pragma omp parallel
#pragma omp master
  ans = omp_get_num_threads(); // done in parallel section, but only by master thread (0)
  if (3 == ans)
    return 0;   // good
  return 1;     // bad
} // end of implicit main

t/02-with.t  view on Meta::CPAN

use Alien::OpenMP;
use File::Temp ();
Inline->import(
    C           => do { local $/ = undef; <DATA> },
    filters     => [ sub { (my $filt = $_[0]) =~ s/^__C__$//mg; $filt } ],
    with        => qw/Alien::OpenMP/,
    directory   => ( my $tmp = File::Temp::tempdir() ),
    build_noisy => !!$ENV{HARNESS_IS_VERBOSE}
);

for my $num_threads (qw/1 2 4 8 16 32 64 128 256/) {
    is test($num_threads), $num_threads, qq{Ensuring compiled OpenMP program works as expected. Threads = $num_threads};
}

{
    local %ENV = %ENV;
    $ENV{CC} = q{gcc};
    my $config_ref = Alien::OpenMP->Inline('C');
    like $config_ref->{CCFLAGSEX},  qr/-fopenmp/, q{inspecting value of CCFLAGSEX.};
    like $config_ref->{LDDLFLAGS},  qr/(?:-lomp|-fopenmp)/, q{inspecting value of LDDLFLAGS.};
    is $config_ref->{AUTO_INCLUDE}, q{#include <omp.h>}, q{inspecting value of AUTO_INCLUDE.};
}

done_testing;

__DATA__

__C__
#include <stdio.h>
int test(int num_threads) {
  omp_set_num_threads(num_threads);
  int ans = 0;
  #pragma omp parallel
    #pragma omp master
      ans = omp_get_num_threads(); // done in parallel section, but only by master thread (0)
  return ans;
}



( run in 2.519 seconds using v1.01-cache-2.11-cpan-3cd7ad12f66 )