HPF and MPI are available to perform internode parallelism on SX-ace
This page introduces how to use HPF/SX.
# For MPI information, please take a look atthis page.

MPI is a bit hard for novice users and we highly recommend to use HPF.

 

About HPF

HPF(High Performane Fortran) is an extension of Fortran for distributed memory architecture.
Just inserting directives to Fortran program alloes you to start distributed and parallel programming and thus HPF is easier to understand than MPI
HPF is available on SX-ACE, not on other large-scale systems at CMC.

 

How to make HPF program

The way to make HPF program is to add HPF directives to your Fortran program.
MPI execution file is generated just by compiling your Fortran program with HPF directives.

 
Making distribute and parallel program is composed of the following three:
 1. data division (data mapping)
 2. loadbalancing and parallelization of computation
 3. inter-processor communication insertion

In HPF, the above 2 and 3 is autimatically performed and so all users need to care is the above 1.

 

Basics to use HPF

This page uses himeno.f, a sample fortran program for your reference.
himeno.f can be obtained from here.

 

1.Understanding of computation costs

Compilation and execution of your serial program to understand the time-consuming fragment of your program.
When you compile, you need to add ftrace option to get the statistical information of the program execution after computation.

 % sxf90 -ftrace himeno.f

Program execution is the same.
You can check the statistical information.
 

 % sxftrace

 EXAMPLE

PROG.UNIT FREQUENCY EXCLUSIVE
TIME[sec](%)
AVER.TIME
[msec]
MOPS MFLOPS V.OP
RATIO
AVER.V.LEN VECTOR
TIME
I-CACHE
MISS
O-CACHE
MISS
BANK
CONF
jacobi 1 72.446(99.9) 72445.97 34217.2 15670.8 99.57 255 68.753 0 0.912 37.633
initmt 1 0.038(0.1) 37.796 27808.3 1.7 99.4 256 0.038 0 0.002 0
main_ 1 0.000(0.0) 0.284 274.5 0.6 47.47 237 0 0 0 0
-------------------------------------------------------------------------------------------------------
total 3 72.484(100.0) 24161.35 34213.7 15662.6 99.57 255 68.79 0 0.914 37.633

In this example, jacobi subroutine occupies most of computation time, and thus we could streamline the program
if parallelization of jacobi routine is possible.

 

2.Consideration of the fragment to parallelize

Looking for loop structure which can be performed in parallel in jacobi subroutine.

 

Basic idea for parallelization

In the case of multiple loop structures, the innermost should be vectorization, the outermost loop should be parallelized with HPF.
In the case of multi-dimensional array, the fist dimension should be the target of vectorization, the last dimension should be with HPF.

In this case, loop with variable k should be parallelized with HPF. This works effectively.
Also、loop structure with variable i should be vectorization.
   

parallelization in jacobi

The inside of jacobi is as follows.
 

  loop with variable loop
   variable k loop
    variable j loop
     variable i loop
      variale so calculation(i,j,k,p are used)
      varialbe ss calculation(i,j,k are used)
     varialbe i loop end
    variable j loop end
   variable k loop end

   varialbe k loop2
    variable j loop2
     variable i loop2
      variable p calculation(k,j,i are used)
     variable i loop2 end
    variable j loop2 end
   variable k loop2 end
  variable loop loop end

In this case, the outermost loop is loop with varible loop. However, as variable loop is not used in the array refered in the outermost loop,
parallelization makes wrong computation result.

Below, parallelization is done focusing on variable k.

 

3.Consideration of mapping

Check array using variable k in the loop structure with variable k.

  p,bnd,wrk1,wrk2
  a,b,c

These arrays uses variable k in the third dimension in either array.
Insert DISTIBUTE指示行, which instructs data mappin,g into these arrays.
The place to insert is between declaration of array and the place where the array is refered.

The following sentence is as follows.

!HPF$ DISTRIBUTE (*,*,BLOCK):: p,bnd,wrk1,wrk2
!HPF$ DISTRIBUTE (*,*,BLOCK,*) :: a,b,c

DISTRIBUTEの後に記述している括弧内の文は、配列の次元毎のマッピング方法を示しています。
例えば、配列p、bnd、wrk1、wrk2は3次元配列となっており、k変数は3次元目を利用していますので、3次元目に「BLOCK」という配列方法を指定しています。BLOCKは一番基本的なマッピング方法で、各プロセッサ単位に配列を均等にマッピングする方法となります。1次元目と2次元目は並列化しませんので、マッピングしないことを表す*(アスタリスク)を指定しています。配列a、b、cは4次元配列となっており、同じくk変数は3次元目を利用していますので、3次元目に「BLOCK」を指定し、それ以外にはアスタリスクを指定しています。
基本的に、HPFではDISTRIBUTE指示行以外を省略することが可能です。つまり、DISTRIBUTE指示行の使い方を覚えるだけで、HPFを使用することが可能です。

 

4.集計計算の並列化

jacobiルーチン内のgosa変数に着目した集計計算の並列化を行います。
下記のINDEPENDENT指示行を挿入することで、gasa変数の集計計算を並列化することが可能です。

   !HPF$ INDEPENDENT,REDUCTION(gosa)

 

5.並列化情報リストの参照

コンパイルしてみましょう。
コンパイルは下記のコマンドになります。

% sxhpf -Mlist2 sorce_file

-Mlist2オプションを付けることで、並列化情報リスト(.lstファイル)を出力することが可能です。

主な並列化情報リストの見方

 < S > 並列化できないループ
 < P > 並列化されたループ
 < N > 並列化可能だが並列化しなかったループ
 < I > 独立なループ
 < R > 独立かつ集計処理を含むループ
 COMM 通信処理。通信を行うとオーバヘッドが増えるので、最低限に抑える
    COMM: 通信パターン [変数名][LINO: 行番号inファイル名]
      通信パターンの種類
       SFT:シフト通信。負荷は低いので無視しても問題ない
       RED:集計計算。並列ループの外側に生成されている場合はやむを得ない。
          並列ループ内側の場合は後述の指示行を使い、並列化可能。
 HOME: 直後のDOループの並列化の基準配列を示します。

    

実行スクリプト

HPFはコンパイルすることでMPIの実行ファイルを出力します。
そのため、基本的にはMPIと同じ実行方法になります。
 
スクリプト例は下記の通りです。
4ノード並列実行、1ノードにつき4並列実行(計16並列実行)、
経過時間 5時間、メモリ 60GB でMPIのバッチリクエストを実行するスクリプトになります。
 

 

おわりに

本項ではDSTRIBUTE指示行とINDEPENDENT指示行を使用しました。
指示行の詳細やより複雑な利用方法については、下記をご参照ください。
HPF/SX V2 利用の手引(要認証)

また、当センターではHPFの講習会を定期的に開催しています。ぜひご参加ください。
講習会一覧 HPFプログラミング入門 講習会資料