3.1.8.4.7.2. OpenMP¶
The following is an example of compiling a single node job (OpenMP) C program.
- Prepare source program.Sample program is prepared as
/home/system/sample/C/openmp/clang_sample_omp.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//
27// initialize matrix
28//
29#pragma omp parallel for shared(a,b,c)
30 for (j = 0; j < N; j++) {
31 for (i = 0; i < N; i++) {
32 a[j][i] = 0.1;
33 b[j][i] = 0.3;
34 c[j][i] = 0.0;
35 }
36 }
37
38//
39// do matrix multiply
40//
41 t1 = gettimeofday_sec();
42#pragma omp parallel for shared(a,b,c)
43 for (j = 0; j < N; j++) {
44 for (i = 0; i < N; i++) {
45 for (k = 0; k < N; k++) {
46 c[i][j] = c[i][j] + a[i][k] * b[k][j];
47 }
48 }
49 }
50 t2 = gettimeofday_sec();
51
52//
53// print result
54//
55 printf("c[1][1] = %f\n", c[1][1]);
56 printf("time : %f sec.\n", t2 - t1);
57 return 0;
58}
Compile sample program
[_LNlogin]$ fccpx -Nclang -Ofast -fopenmp -Rpass=.* -ffj-lst=t -o sample_omp clang_sample_omp.c clang_sample_omp.c:41:10: remark: gettimeofday_sec inlined into main with cost=45 (threshold=375) [-Rpass=inline] t1 = gettimeofday_sec(); ^ clang_sample_omp.c:50:10: remark: gettimeofday_sec inlined into main with cost=45 (threshold=375) [-Rpass=inline] t2 = gettimeofday_sec(); ^ clang_sample_omp.c:32:11: remark: sinking zext [-Rpass=licm] a[j][i] = 0.1; ^ (omitted)
- Prepare job script.Job script sample is prepared as
/home/system/sample/C/openmp/clang_job_openmp.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_omp
Submit a job with pjsub command.
[_LNlogin]$ pjsub clang_job_openmp.sh [INFO] PJM 0000 pjsub Job 117 submitted.
- Check execution result.The standard output is output as
job name.job ID.out
.
[_LNlogin]$ cat clang_job_openmp.sh.117.out 5888, 5888 c[1][1] = 176.640000 time : 10.873365 sec.