[Omp] OpenMP and pure function in fortran

Herbert Fruechtl Herbert.Fruchtl at uk.fujitsu.com
Thu Nov 18 02:48:06 PST 2004


As I understand it, OpenMP treats all procedures like "pure" functions.
If they are not (because they access global variables or cause other
side effects), you have to take care of that yourself (e.g. through
"critical" directives) inside these procedures.

Cheers,

  Herbert

> -----Original Message-----
> From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] 
> On Behalf Of Marek Wojcik
> Sent: 17 November 2004 16:36
> To: Omp at openmp.org
> Subject: [Omp] OpenMP and pure function in fortran
> 
> 
>  Dear Experts,
> 
>  Is OpenMP standard aware of Fortran 95 Pure (Elemental) 
> Functions?  In other words is it enough to declare function 
> pure in order to  achieve parallelization via OpenMP 
> directives?  Is it required or implementation dependent?
> 
>  Regards,
> Marek Wojcik
> 
> P.S Below I included small example.
> 
> module lib
>  implicit none
> 
> contains
> 
>  pure real function poo(x)
>    real, intent (in) :: x
> 
>    poo = 2*x
>   
>  end function poo
> 
> end module lib
> 
> program test
>  use lib
>  implicit none
>  integer, parameter :: n = 1000000
>  integer :: i, j
>  real    :: a(n), b(n), c(n), t1, t2
> 
>  a = 3.1415
> 
> !$OMP PARALLEL 
> 
> !$OMP DO
>  do i=1, n
>     b(i) = poo(a(i))
>   end do
> !$OMP END DO
> 
> !$OMP END PARALLEL
> end do
> 
>  print *, maxval(b), maxval(c), 'time:> ', t2-t1
> 
> end program test 
> 
> _______________________________________________
> Omp mailing list
> Omp at openmp.org http://openmp.org/mailman/listinfo/omp_openmp.org
> 




More information about the Omp mailing list