3.1.7.11.3. OpenMP¶
シングルノードジョブ(OpenMP)のFortranプログラムをコンパイルする例を示します。
- ソースプログラムを用意します。サンプルプログラムを
/home/system/sample/Fortran/openmp/sample_omp.f
として用意しています。
1 parameter(n=5888)
2 real*8 a(n+1,n),b(n+1,n),c(n+1,n)
3 real*8 t0,t1,second
4!
5! print message
6!
7 write(6,500)
8 write(6,510) n,n
9 500 format(" *** matrix multiply *** ")
10 510 format(' (NPROW,NPCOL) : (',I6,',',I6,')')
11
12!
13! initialize matrix
14!
15!$omp parallel do default(private) shared(a,b,c)
16 do j=1,n
17 do i=1,n
18 a(i,j)=0.1d0
19 b(j,i)=0.3d0
20 c(i,j)=0.0d0
21 end do
22 end do
23!$omp end parallel do
24!
25! do matrix multiply
26!
27 t0 = second()
28!$omp parallel do default(private) shared(a,b,c)
29 do j=1,n
30 do i=1,n
31 do k=1,n
32 c(i,j) = c(i,j) + a(i,k) * b(k,j)
33 end do
34 end do
35 end do
36!$omp end parallel do
37 t1 = second()
38!
39! print result
40!
41 write(6,520) c(1,1)
42 write(6,530) t1-t0
43 520 format(" c(1,1)=",g10.4)
44 530 format(" time :",f10.2," sec")
45 end
46!----
47 function second()
48 real*8 second,t
49 call gettod(t)
50 second=t*1.e-6
51 end
サンプルプログラムをコンパイルします。
[_LNlogin]$ frtpx -V -Kfast,openmp,optmsg=2 -Nlst=t -o sample_omp sample_omp.f frtpx: Fujitsu Fortran Compiler 4.1.0 tcsds-1.2.24 jwd_fortpx: Fujitsu Fortran Compiler 4.1.0 (Feb 26 2020 07:41:18) Fortran diagnostic messages: program name(main) jwd6002s-i "sample_omp.f", line 17: SIMD conversion is applied to DO loop. jwd8204o-i "sample_omp.f", line 17: This loop is software pipelined. jwd8205o-i "sample_omp.f", line 17: The software-pipelined loop is chosen at run time when the iteration count is greater than or equal to 48. jwd8220o-i "sample_omp.f", line 29: Optimizations is performed in this program unit with possibility of side effects. See informational messages below to determine which such optimizations have been performed. jwd8331o-i "sample_omp.f", line 29: This DO loop was changed to the library call(matmul). GNU assembler version 2.30 (aarch64-linux-gnu) using BFD version version 2.30-49.el7 GNU ld version 2.30-49.el7 Supported emulations: aarch64linux aarch64elf aarch64elf32 aarch64elf32b aarch64elfb armelf armelfb aarch64linuxb aarch64linux32 aarch64linux32b armelfb_linux_eabi armelf_linux_eabi i386pep i386pe flistpx: Fujitsu Listing Processor 4.1.0 (Jan 9 2020 14:46:36)
- ジョブスクリプトを用意します。ジョブスクリプトのサンプルは
/home/system/sample/Fortran/openmp/job_openmp.sh
として用意しています。
#!/bin/sh #PJM -L "node=1" #PJM -L "rscgrp=small" #PJM -L "elapse=10:00" #PJM -x PJM_LLIO_GFSCACHE=/vol0004 #PJM -g groupname #PJM -s # execute job export OMP_NUM_THREADS=12 ./sample_omp
pjsubコマンドでジョブを投入します。
[_LNlogin]$ pjsub job_openmp.sh [INFO] PJM 0000 pjsub Job 113 submitted.
- 実行結果を確認します。標準出力は
ジョブ名.ジョブID.out
として出力されます。
[_LNlogin]$ cat job_openmp.sh.113.out *** matrix multiply *** (NPROW,NPCOL) : ( 5888, 5888) c(1,1)= 176.6 time : 30.55 sec