Search code examples
fortrandistributed-computinghpchpf

High Performance Fortran (HPF) without directives?


In High Performance Fortran (HPF), I could specify the distribution of arrays involved in a parallel calculation using the DISTRIBUTE directive. For example, the following minimal subroutine will sum two arrays in parallel:

subroutine mysum(x,y,z)
  integer, intent(in)  :: y(10000), z(10000)
  integer, intent(out) :: x(10000), 
  !HPF$ DISTRIBUTE x(BLOCK), y(BLOCK), z(BLOCK)
  x = y + z
end subroutine mysum

My question is, is the DISTRIBUTE directive necessary? I know in practise this is of little interest, but I'm curious as to whether an unadorned, directive-free, Fortran program could also be a valid HPF program?


Solution

  • I do not believe DISTRIBUTE statement is necessary, and I never used it.

    You can achieve this implicitly by using FORALL statements instead of DO loops where applicable. Originally, DO loops would give explicit order of operation on array elements, whereas FORALL would allow the processor to determine an optimal order at runtime. I do not think this makes much difference nowadays, because modern compilers are able to optimize/vectorize/parallelize DO loops where possible. I cannot tell for sure for other compilers, but I remember using Intel Fortran Compiler to compile and run a program on 2 and 4 processors in parallel without using DISTRIBUTE.

    However, depending on the processor architecture and compiler, it is best to try out what you have and see what gives you optimal results or efficiency.