[Omp] Newbie in deep end >> Matrix multiplier > Need to add
OpenMPdirectives
Meadows, Lawrence F
lawrence.f.meadows at intel.com
Thu Apr 7 12:47:50 PDT 2005
Non-trivial.
Here's matrix multiply in Fortran: B(n,l) * C(l,m) = A(n,m)
(actually, this adds the product of B and C to A, but
this is the important bit):
do i = 1,n
do j = 1,m
do k = 1,l
a(i,j) = a(i,j) + b(i,k) * c(k,j)
enddo
enddo
enddo
You can parallelize any loop that doesn't carry a dependence.
So that would be either outer loop (extra credit: what OpenMP
directive would you use to parallelize the innermost loop?)
The outermost loop is the best because of granularity, considering
only parallelism. So you would do:
!$omp parallel do
do i = 1,n
do j = 1,m
do k = 1,l
a(i,j) = a(i,j) + b(i,k) * c(k,j)
enddo
enddo
enddo
!$omp end parallel do
The last directive is not required.
In C, you would say:
#pragma omp parallel for
and translate the fortran to C, and probably put curlys around
the whole mess for clarity.
So the homework question is why is this a really bad way to
do matrix multiply, even ignoring the OpenMP directives? Once
you've figured that out, which I presume that you have, and
presumably discovered tiling, then you have to decide which
loop or loops in the tiled loop nest to parallelize. I suspect
that the answer is the outermost block loop, but I have now
exhausted the limits of my knowledge of matrix multiply for
this semester.
Regards,
Larry Meadows
>-----Original Message-----
>From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org]
>On Behalf Of Bono Mitch
>Sent: Thursday, April 07, 2005 12:30 PM
>To: Omp at openmp.org
>Subject: [Omp] Newbie in deep end >> Matrix multiplier > Need
>to add OpenMPdirectives
>
>Hi,
>
>I'm working on a matrix-matrix multiplier in C for my
>dissertation. It is
>based on the DGEMM fortran routine. The multiplier works great
>but I need to
>add open mp directives and I'm totally new to it so don't
>really have a clue
>where. I've looked at the FAQ's and the specifcation examples
>but still
>don't know where to add them.
>
>Can any of you point me to some examples where OpenMP has been
>used in this
>manner?
>
>Thanks for your help,
>
>Colly Mitch.
>
>_________________________________________________________________
>G-string or bloomers? Find out what to wear at MSN Weather!
>http://www.msn.ie/weather
>
>
>_______________________________________________
>Omp mailing list
>Omp at openmp.org
>http://openmp.org/mailman/listinfo/omp_openmp.org
>
More information about the Omp
mailing list