JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  1998

COMP-FORTRAN-90 1998

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: HPF vs. arrays of pointers

From:

Thorsten Ohl <[log in to unmask]>

Reply-To:

[log in to unmask][log in to unmask]>

Date:

Thu, 30 Apr 1998 16:34:04 +0200

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (192 lines)

> Maybe we should take this offline to save bandwidth on the
> mailing list?

At least one person asked for an encore :-).

> >  It's nice if the compiler can catch some obviosu dependencies.
>
> I don't know what you meant by your last sentence.

The compiler will alert me if any modification of global variables
have slipped in from serial test versions, etc.  Squeezing the
algorithm into the harness of pure procedures goes a long way toward
parallelizability (theoretically, at least :-).

> Since you made the field PRIVATE, it must be allocated in a routine
> in the module that defines the type.  As long as you have declared
> the mapping of the array of these objects, they will be allocated
> correctly (i.e., on the correct processors) by the ALLOCATE
> statement.

We're getting somewhere: my concern was whether it suffices to declare
the mapping of the objects (which contain pointers) as a whole or
whether I have to specify mappings _inside_ the module defining the
type as well.

In other words: if t is already mapped to processor p, will

   allocate(t%x(100))

allocate t%x on p as well or do I have to add more HPF directives to
insure that?

If it doesn't waste too much bandwidth, here's a more complete
example.  May question is essentially, whether the footnote

  Caveat emptor: the scalability of this version has not been tested
  yet, because we don't have access to a reliable HPF compiler.  In
  particular, one might have to insert further HPF directives that
  distribute the array [[gs]] properly. Furthermore [[vamp_fork_grid]]
  is not local and one might want to tune it to the processor
  topology. The gain will be very small, however.

is correct.

NB: `call vamp_create_grid (gs)' just executes nullify for the
    components of gs(:), but `call vamp_fork_grid (g, gs, gx, d)' does
    a lot of allocating.

@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Practice}
In this section we show three implementations of~$S_n$: serial,
HPF~\cite{Koelbel/etal:1994:HPF} and MPI~\cite{MPI}.  From these
examples it should be obvious how to adapt VAMP to other parallel
computing paradigms.
@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Serial}
Here is a bare bones version of~$S_n$, the real implementation in
[[vamp_sample_grid]] includes some error handling, diagnostics and the
projection~$P$ (cf.~(\ref{eq:P})):
<<Serial implementation of $S_n=S_0(rS_0)^n$>>=
type(tao_random_state), intent(inout) :: rng
type(vamp_grid), intent(inout) :: g
integer, intent(in) :: iterations
<<Interface declaration for [[func]]>>
integer :: iteration
iterate: do iteration = 1, iterations
   call vamp_sample_grid0 (rng, g, func)
   call vamp_refine_grid (g)
end do iterate
@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{HPF}
Here is the HPF version of~$S_n$.  Instead of one random number
generator state~[[rng]] it takes an array consisting of one state per
processor.  These [[rng(:)]] are assumed to be initialized that the
resulting sequences are statistically independent.  For this purpose,
Knuth's random number generator~\cite{Knuth:1997:TAOCP2} is most
convenient and is included with VAMP.  Before each~$S_0$, the procedure
[[vamp_distribute_work]] determines a good decomposition of the
grid~[[d]] into [[size(rng)]] pieces.  This decomposition is encoded
in the array [[d]] where [[d(1,:)]] holds the dimensions along which
to split the grid and [[d(2,:)]] holds the corrsponding number of
divisions.  Using this information, the grid is decomposed by
[[vamp_fork_grid]].  A good HPF compiler will then distribute the
[[!HPF$ INDEPENDENT]] loop among the processors. Finally,
[[vamp_join_grid]] gathers the results.
<<Parallel implementation of $S_n=S_0(rS_0)^n$ (HPF)>>=
type(tao_random_state), dimension(:), intent(inout) :: rng
type(vamp_grid), intent(inout) :: g
integer, intent(in) :: iterations
<<Interface declaration for [[func]]>>
type(vamp_grid), dimension(:), allocatable :: gs, gx
integer, dimension(:,:), pointer :: d
integer :: iteration, num_workers
iterate: do iteration = 1, iterations
   call vamp_distribute_work (size (rng), vamp_rigid_divisions (g), d)
   num_workers = max (1, product (d(2,:)))
   if (num_workers > 1) then
      allocate (gs(num_workers), gx(vamp_fork_grid_joints (d)))
      call vamp_create_grid (gs)
      call vamp_fork_grid (g, gs, gx, d)
      !HPF$ INDEPENDENT
      do i = 1, num_workers
         call vamp_sample_grid0 (rng(i), gs(i), func)
      end do
      call vamp_join_grid (g, gs, gx, d)
      call vamp_delete_grid (gs)
      deallocate (gs, gx)
   else
      call vamp_sample_grid0 (rng(1), g, func)
   end if
   call vamp_refine_grid (g)
end do iterate
@ Since [[vamp_sample_grid0]] performes the bulk of the
computaion, an almost linear speedup\footnote{Caveat emptor: the
scalability of this version has not been tested yet, because we don't
have access to a reliable HPF compiler.  In particular, one might have
to insert further HPF directives that distribute the array [[gs]]
properly. Furthermore [[vamp_fork_grid]] is not local and one might
want to tune it to the processor topology. The gain will be very
small, however.} with the number of processors can be achieved, if
[[vamp_distribute_work]] finds a good decomposition of the grid.  The
version distributed with VAMP does a good job in most cases, but will
fail if the number of processors is a prime number larger than the
number of divisions in the stratification grid.  Therefore it can be
beneficial to tune [[vamp_distribute_work]] to specific hardware.
Furthermore, using a finer stratification grid can improve performance.
@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{MPI}
The MPI version is more low level, because we have to keep track of
message passing ourselves.  Note that we have made this
synchronization points explicit with three
[[if ... then ... else ... end if]] blocks: forking, sampling,
joining.  These blocks could be merged for almost no performance gain
at the expense of readability.  We assume that [[rng]] has been
initialized in each process such that the sequences are again
statistically independent.
<<Parallel implementation of $S_n=S_0(rS_0)^n$ (MPI)>>=
type(tao_random_state), dimension(:), intent(inout) :: rng
type(vamp_grid), intent(inout) :: g
integer, intent(in) :: iterations
<<Interface declaration for [[func]]>>
type(vamp_grid), dimension(:), allocatable :: gs, gx
integer, dimension(:,:), pointer :: d
integer :: num_proc, proc_id, iteration, num_workers
call mpi90_size (num_proc)
call mpi90_rank (proc_id)
iterate: do iteration = 1, iterations
   if (proc_id == 0) then
      call vamp_distribute_work (num_proc, vamp_rigid_divisions (g), d)
      num_workers = max (1, product (d(2,:)))
   end if
   call mpi90_broadcast (num_workers, 0)
   if (proc_id == 0) then
      allocate (gs(num_workers), gx(vamp_fork_grid_joints (d)))
      call vamp_create_grid (gs)
      call vamp_fork_grid (g, gs, gx, d)
      do i = 2, num_workers
         call vampi_send_grid (gs(i), i-1, 0)
      end do
   else if (proc_id < num_workers) then
      call vampi_receive_grid (g, 0, 0)
   end if
   if (proc_id == 0) then
      if (num_workers > 1) then
         call vamp_sample_grid0 (rng, gs(1), func)
      else
         call vamp_sample_grid0 (rng, g, func)
      end if
   else if (proc_id < num_workers) then
      call vamp_sample_grid0 (rng, g, func)
   end if
   if (proc_id == 0) then
      do i = 2, num_workers
         call vampi_receive_grid (gs(i), i-1, 0)
      end do
      call vamp_join_grid (g, gs, gx, d)
      call vamp_delete_grid (gs)
      deallocate (gs, gx)
      call vamp_refine_grid (g)
   else if (proc_id < num_workers) then
      call vampi_send_grid (g, 0, 0)
   end if
end do iterate
@

-- 
Thorsten Ohl, Physics Department, TU Darmstadt -- [log in to unmask]
http://crunch.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

December 2023
February 2023
November 2022
September 2022
February 2022
January 2022
June 2021
November 2020
September 2020
June 2020
May 2020
April 2020
December 2019
October 2019
September 2019
March 2019
February 2019
January 2019
November 2018
October 2018
September 2018
August 2018
July 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
December 2015
November 2015
October 2015
September 2015
August 2015
June 2015
April 2015
March 2015
January 2015
December 2014
November 2014
October 2014
August 2014
July 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager