<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic OpenMP reduction for derived-type variable. in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-reduction-for-derived-type-variable/m-p/760868#M16355</link>
    <description>Good day,&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I have coded a simple test:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;[fxfortran]MODULE foo_module
    IMPLICIT NONE
!
!
    PRIVATE
!
type, public :: foo
  integer :: xx
    CONTAINS
      procedure :: set =&amp;gt; set_sub
      procedure :: bar =&amp;gt; bar_fn
      generic :: operator(+) =&amp;gt; foo_plus_foo
      procedure, private :: foo_plus_foo =&amp;gt; foo_plus_foo_fn
end type foo
!

    CONTAINS
!

ELEMENTAL subroutine set_sub(this, xx)
    implicit none
    class(foo), intent(INOUT) :: this
    integer, intent(IN) :: xx
this%xx = xx
return
end subroutine set_sub
!
!
ELEMENTAL integer function bar_fn(this) RESULT(res)
    implicit none
    class(foo), intent(IN) :: this
res = this%xx * this%xx
return
end function bar_fn
!
!
ELEMENTAL type(foo) function foo_plus_foo_fn(f1, f2) RESULT(res)
    implicit none
    class(foo), intent(IN) :: f1, f2
res%xx = f1%xx + f2%xx
return
end function foo_plus_foo_fn
!
!
END MODULE foo_module


PROGRAM main
    USE foo_module
    IMPLICIT NONE
    type(foo) :: f, f_sum
    integer :: i, y

!$OMP parallel
!$OMP single
  call f_sum%set(0)
!$OMP end single

!$OMP do PRIVATE(i,f,y) ! REDUCTION(+:f_sum)
  do i = 1, 10
    call f%set(i)
    y = f%bar()
    write( *, * ) i, y
    call f%set(y)
    f_sum = f_sum + f
  end do
!$OMP end do

!$OMP single
  write( *, * ) 'f_sum is ', f_sum%xx
!$OMP end single

!$OMP end parallel

y = 0
do i = 1, 10
  y = y + i**2
end do
write( *, * ) 'y', y ! 

END PROGRAM main
[/fxfortran]&lt;/PRE&gt; &lt;/DIV&gt;&lt;DIV&gt;Is it correct example? In this case each threads get private i,f,y variables and work with them copies.&lt;/DIV&gt;&lt;DIV&gt;Should I specify a REDUCTION directive in a OMP-pragma?&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Best regards, Oleg.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 24 Jan 2012 19:02:56 GMT</pubDate>
    <dc:creator>oleglebedev</dc:creator>
    <dc:date>2012-01-24T19:02:56Z</dc:date>
    <item>
      <title>OpenMP reduction for derived-type variable.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-reduction-for-derived-type-variable/m-p/760868#M16355</link>
      <description>Good day,&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I have coded a simple test:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;[fxfortran]MODULE foo_module
    IMPLICIT NONE
!
!
    PRIVATE
!
type, public :: foo
  integer :: xx
    CONTAINS
      procedure :: set =&amp;gt; set_sub
      procedure :: bar =&amp;gt; bar_fn
      generic :: operator(+) =&amp;gt; foo_plus_foo
      procedure, private :: foo_plus_foo =&amp;gt; foo_plus_foo_fn
end type foo
!

    CONTAINS
!

ELEMENTAL subroutine set_sub(this, xx)
    implicit none
    class(foo), intent(INOUT) :: this
    integer, intent(IN) :: xx
this%xx = xx
return
end subroutine set_sub
!
!
ELEMENTAL integer function bar_fn(this) RESULT(res)
    implicit none
    class(foo), intent(IN) :: this
res = this%xx * this%xx
return
end function bar_fn
!
!
ELEMENTAL type(foo) function foo_plus_foo_fn(f1, f2) RESULT(res)
    implicit none
    class(foo), intent(IN) :: f1, f2
res%xx = f1%xx + f2%xx
return
end function foo_plus_foo_fn
!
!
END MODULE foo_module


PROGRAM main
    USE foo_module
    IMPLICIT NONE
    type(foo) :: f, f_sum
    integer :: i, y

!$OMP parallel
!$OMP single
  call f_sum%set(0)
!$OMP end single

!$OMP do PRIVATE(i,f,y) ! REDUCTION(+:f_sum)
  do i = 1, 10
    call f%set(i)
    y = f%bar()
    write( *, * ) i, y
    call f%set(y)
    f_sum = f_sum + f
  end do
!$OMP end do

!$OMP single
  write( *, * ) 'f_sum is ', f_sum%xx
!$OMP end single

!$OMP end parallel

y = 0
do i = 1, 10
  y = y + i**2
end do
write( *, * ) 'y', y ! 

END PROGRAM main
[/fxfortran]&lt;/PRE&gt; &lt;/DIV&gt;&lt;DIV&gt;Is it correct example? In this case each threads get private i,f,y variables and work with them copies.&lt;/DIV&gt;&lt;DIV&gt;Should I specify a REDUCTION directive in a OMP-pragma?&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Best regards, Oleg.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 24 Jan 2012 19:02:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-reduction-for-derived-type-variable/m-p/760868#M16355</guid>
      <dc:creator>oleglebedev</dc:creator>
      <dc:date>2012-01-24T19:02:56Z</dc:date>
    </item>
    <item>
      <title>OpenMP reduction for derived-type variable.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-reduction-for-derived-type-variable/m-p/760869#M16356</link>
      <description>I think a bit about it.&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;This is a model code that reproduces a piece of my prject code. This realization is closer to my project than first one.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;[fortran]MODULE foo_module
    IMPLICIT NONE
!
!
    PRIVATE
!
type, public :: foo
  double precision :: xx
    CONTAINS
      procedure :: init =&amp;gt; init_sub
      generic :: operator(+) =&amp;gt; foo_plus_foo_fn
      procedure, private :: foo_plus_foo_fn
end type foo

!
    CONTAINS
!
subroutine init_sub(this, xx)
    implicit none
    class(foo), intent(INOUT) :: this
    double precision, intent(IN) :: xx
this%xx = xx
return
end subroutine init_sub
!
!
ELEMENTAL type(foo) function foo_plus_foo_fn(f1, f2) RESULT(res)
    implicit none
    class(foo), intent(IN) :: f1, f2
res%xx = f1%xx + f2%xx
return
end function foo_plus_foo_fn
!
!
END MODULE foo_module


PROGRAM main
    USE foo_module
    IMPLICIT NONE
    type(foo) :: f, f_sum
    double precision :: y = 0.
    integer :: i

!$OMP parallel

!$OMP do PRIVATE(i,f) REDUCTION(+:y)
  do i = 1, 5
    call f%init(dble(i))
    y = y + f%xx
    f_sum = f_sum + f ! I would like to implement this behaviour.
  end do
!$OMP end do

!$OMP single
  write( *, '( :, 1X, 3(1X, A, f17.10) )' ) 'f_sum is ', f_sum%xx, 'y_sum is ', y, 'abs', abs(y-f_sum%xx)
!$OMP end single

!$OMP end parallel

END PROGRAM main[/fortran]&lt;/PRE&gt; &lt;/DIV&gt;&lt;DIV&gt;Does anybody have any idea how to sum a derived-type variable?&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Best, Oleg.&lt;/DIV&gt;</description>
      <pubDate>Wed, 25 Jan 2012 17:10:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-reduction-for-derived-type-variable/m-p/760869#M16356</guid>
      <dc:creator>oleglebedev</dc:creator>
      <dc:date>2012-01-25T17:10:09Z</dc:date>
    </item>
    <item>
      <title>OpenMP reduction for derived-type variable.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-reduction-for-derived-type-variable/m-p/760870#M16357</link>
      <description>type(foo) :: f, f_sum, f_sumLocal&lt;BR /&gt;...&lt;BR /&gt;call f_sum%init(0.0D0)&lt;BR /&gt;!$omp parallel private(i, f, f_sumLocal)&lt;BR /&gt;call f_sumLocal%init(0.0D0)&lt;BR /&gt;$omp do...&lt;BR /&gt;...&lt;BR /&gt;f_sumLocal = f_sumLocal + f&lt;BR /&gt;end do&lt;BR /&gt;!$omp end do&lt;BR /&gt;!$omp critical(critical_for_f_sum)&lt;BR /&gt;f_sum = f_sum + f_sumLocal&lt;BR /&gt;!$omp end critical(critical_for_f_sum)&lt;BR /&gt;!$omp end parallel&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey</description>
      <pubDate>Thu, 26 Jan 2012 04:12:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-reduction-for-derived-type-variable/m-p/760870#M16357</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2012-01-26T04:12:59Z</dc:date>
    </item>
    <item>
      <title>OpenMP reduction for derived-type variable.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-reduction-for-derived-type-variable/m-p/760871#M16358</link>
      <description>Or you could add a type member function called... reduce that contains the critical section with the +.&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;!$omp end do&lt;BR /&gt;f_sum%reduce(f_sumLocal)&lt;BR /&gt;!$omp end parallel&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey</description>
      <pubDate>Thu, 26 Jan 2012 04:17:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-reduction-for-derived-type-variable/m-p/760871#M16358</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2012-01-26T04:17:41Z</dc:date>
    </item>
  </channel>
</rss>

