开发者

A little help regarding openMP and gomp

here is the parallel(verbatim) version of matrix to vector multiplication as implemented in this book

using OpenMP

subroutine matvecmul(mat,vec,res,m,n)
use omp_lib
implicit none
integer::m,n,i,j
real*8,dimension(m,n),intent(in)::mat
real*8,dimension(n),intent(in)::vec
real*8,dimension(m)::res 
res(:)=0.0
 !$omp parallel do default(none)
 !$omp shared(mat,vec,res,m,n) private(i,j)
  do i=1,m
   do j=1,n
    res(i)=res(i)+mat(i,j)*vec(j)
   end do
  end do
 !$omp end parallel do
 return
end subroutine matvecmul

i get this syntax error "unclassified openMP clause shared","unclassified openMP clause private" compiled with gfortran 4.4.5 and gfortran 4.6.0

is the shared clause deleted/depcrecated or not implemented in "gomp" or i made some foolish mistake or errata of book ...开发者_如何学运维 with default(one) i didn't get any syntaxerror how am i supposed to say which vars are private and which to be shared ?

here is how i implemented without errors (and correct)

subroutine matvecmul(mat,vec,res,m,n)
use omp_lib
implicit none
integer::m,n,i,j
real*8,dimension(m,n),intent(in)::mat
real*8,dimension(n),intent(in)::vec
real*8,dimension(m)::res
res(:)=0.0
 !$omp parallel do private(i,j)
  do i=1,m
   do j=1,n
    res(i)=res(i)+mat(i,j)*vec(j)
   end do
  end do
 !$omp end parallel do
return
end subroutine matvecmul

i'm still a newbie to openmp (but i need to learn it fast... part of my job!) some explaination here would be appreciated.. is there any openMP tutorial only using gomp (say gcc/gfortran 4.4.5)?


This doesn't have anything to do with gcc's implementation of OpenMP; intel fortran refuses to compile this, too. This is just about how lines are continued in OpenMP + Fortran.

What you want to do, which is entirely correct, is:

!$omp parallel do default(none) shared(mat,vec,res,m,n) private(i,j)

I heartily endorse the approach of using default none and explicitly specifying shared and private variables as best practice. If you use the line above, your routine will compile

The code brok this up into multiple lines, for clarity; and there's nothing wrong with that except the syntax is that, like with other modern Fortran continuation lines, you need an ampersand at the end of the continued line:

 !$omp parallel do default(none)  &
 !$omp shared(mat,vec,res,m,n) private(i,j)

Presumably this was a typo in the book. Because OpenMP is a standard, there's no special gomp (or iomp) version of OpenMP. A compliant OpenMP program should compile on any compliant compiler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜