3.1.8.3.7.2. 自動並列

シングルノードジョブ(自動並列)のCプログラムをコンパイルする例を示します。

  1. ソースプログラムを用意します。
    サンプルプログラムは「Cサンプルプログラム(逐次)」の例と同じです。
 1#include <stdio.h>
 2#include <math.h>
 3#include <sys/time.h>
 4
 5#define N 5888
 6
 7double gettimeofday_sec(){
 8    struct timeval tv;
 9    gettimeofday(&tv, NULL);
10    return tv.tv_sec + (double)tv.tv_usec*1e-6;
11}
12
13int main(){
14    double a[N][N+1];
15    double b[N][N+1];
16    double c[N][N+1];
17    int i, j, k;
18    double t1,t2;
19
20//
21//  print message
22//
23    printf ("\n");
24    printf ("%d, %d\n", N, N);
25//
26//  initialize matrix
27//
28    for (j = 0; j < N; j++) {
29       for (i = 0; i < N; i++) {
30          a[j][i] = 0.1;
31          b[j][i] = 0.3;
32          c[j][i] = 0.0;
33       }
34    }
35
36//
37//  do matrix multiply
38//
39    t1 = gettimeofday_sec();
40    for (j = 0; j < N; j++) {
41       for (i = 0; i < N; i++) {
42          for (k = 0; k < N; k++) {
43             c[i][j] = c[i][j] + a[i][k] * b[k][j];
44          }
45       }
46    }
47    t2 = gettimeofday_sec();
48
49//
50//  print result
51//
52    printf("c[1][1] = %f\n", c[1][1]);
53    printf("time : %f sec.\n", t2 - t1);
54    return 0;
55}
  1. サンプルプログラムをコンパイルします。

[_LNlogin]$ fccpx -V -Kfast,parallel,optmsg=2 -o sample_parallel trad_sample.c
fccpx: Fujitsu C/C++ Compiler 4.1.0 tcsds-1.2.24
simulating gcc version 6.1
ccpcompx: Fujitsu C/C++ Compiler 4.1.0 (Feb 26 2020 07:47:51)
Parallelization messages
  jwd5001p-i  "trad_sample.c", line 28: This loop with loop variable 'j' is parallelized.
  jwd6001s-i  "trad_sample.c", line 29: SIMD conversion is applied to this loop with the loop variable 'i'.
  jwd8663o-i  "trad_sample.c", line 29: This loop is not software pipelined because the software pipelining does not improve the performance.
  jwd8202o-i  "trad_sample.c", line 29: Loop unrolling expanding 2 times is applied to this loop.
  jwd8101o-i  "trad_sample.c", line 39: Inline expansion is applied to the user defined function 'gettimeofday_sec'.
  jwd8220o-i  "trad_sample.c", line 40: Optimizations that may cause side effect are applied.
  jwd8331o-i  "trad_sample.c", line 40: This loop is changed to the matmul library function call.
  jwd8101o-i  "trad_sample.c", line 47: Inline expansion is applied to the user defined function 'gettimeofday_sec'.
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

注釈

  • -Koptmsg=2を指定することで、自動並列、SIMD化、ループアンローリングなどの最適化について、メッセージが出力されます。上記例では、jwd5001p-i , jwd6001s-i が該当します。

  • jwd5001p-i は、ループが並列化されたことを意味します。自動並列化されたループと変数が表示されます。

  • jwd6001s-i は、ループがSIMD化されたことを意味します。SIMD化されたループと変数が表示されます。

  1. ジョブスクリプトを用意します。
    ジョブスクリプトのサンプルは/home/system/sample/C/parallel/trad_job_para.shとして用意しています。
#!/bin/sh
#PJM -L "node=1"
#PJM -L "rscgrp=small"
#PJM -L "elapse=10:00"
#PJM -x PJM_LLIO_GFSCACHE=/vol000N
#PJM -g groupname
#PJM -s

# execute job
export OMP_NUM_THREADS=12
./sample_parallel
  1. pjsubコマンドでジョブを投入します。

[_LNlogin]$ pjsub trad_job_para.sh
 [INFO] PJM 0000 pjsub Job 116 submitted.
  1. 実行結果を確認します。
    標準出力はジョブ名.ジョブID.outとして出力されます。
[_LNlogin]$ cat trad_job_para.sh.116.out

5888, 5888
c[1][1] = 176.640000
time : 89.064760 sec.