3.1.8.4.7.1. 逐次実行

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

  1. ソースプログラムを用意します。
    サンプルプログラムを/home/system/sample/C/single/clang_sample.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 -Nclang -Ofast -Rpass=.* -ffj-lst=t -o clang_sample clang_sample.c
clang_sample.c:39:10: remark: gettimeofday_sec inlined into main with cost=45 (threshold=375)
      [-Rpass=inline]
    t1 = gettimeofday_sec();
         ^
clang_sample.c:47:10: remark: gettimeofday_sec inlined into main with cost=45 (threshold=375)
      [-Rpass=inline]
    t2 = gettimeofday_sec();
         ^
clang_sample.c:40:5: remark: This loop is changed to the matmul library function call.
      [-Rpass=fast-matmul]
    for (j = 0; j < N; j++) {

(省略)

注釈

  • -Rpass=.*を指定することで、最適化情報を出力します。

  1. ジョブスクリプトを用意します。
    ジョブスクリプトのサンプルは/home/system/sample/C/single/clang_job_single.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
./sample
  1. pjsubコマンドでジョブを投入します。

[_LNlogin]$ pjsub clang_job_single.sh

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

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