-
Notifications
You must be signed in to change notification settings - Fork 1
/
matmul1.html
95 lines (95 loc) · 4.95 KB
/
matmul1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<h1>Sample job: Matrix multiplication</h1>
<p>The first example of computational task is to multiply two matrices.
The same task is implemented in several popular languages:
C++, Python, and R.</p>
<p>Generally, a batch job consists of
(1) the <em>program</em> to be launched on the compute node(s), as well as
(2) a <em>job script</em>.</p>
<p>A batch job takes no interaction from user while executing: All input
must be provided in the command-line argument of the program, or via
the input file.
Input files have become a common means to pass on the input to a batch job.
The output of a batch job is either printed to the job's output file
(usually recognized by an extension like <code>.o12345</code>, where <code>12345</code>
refers to the job number assigned by the job scheduler.</p>
<p>The <em>program</em> may consist of one or more executable script files
(such as python <code>*.py</code> scripts or R <code>*.R</code> scipts), or
executable binary files (often bearing the <code>*.x</code> or <code>*.exe</code>
filename pattern).
In the case of compiled language such as C, C++, or Fortran, there
will be source files (e.g. <code>*.c</code>, <code>*.cpp</code>, or <code>*.f90</code>) to be compiled
into the binary executable program.</p>
<p>A <em>job script</em> is essentially a shell script containing
special instructions to be passed to the job scheduler (SGE).
These are the lines prefixed by the <code>#$</code> character
located near the top of the script, before any commands.
This job script is what actually launches the <em>program</em>.</p>
<h2>C++</h2>
<p>C++ codes need to be compiled before it can be executed.
A sample makefile has been provided, which provides the instructions
on how to build the executable programs.</p>
<p>Please go to <code>c++</code> directory and type <code>make</code> on the shell prompt.
Your session may look like (the shell prompt may look different):</p>
<pre><code>[user@turing ~/ODU-HPC-samples]$ cd c++
[user@turing ~/ODU-HPC-samples/c++]$ make
g++ -c mattest1.cpp -o mattest1.o -g -O -Iinclude
g++ mattest1.o -o mattest1.exe
g++ -c matread1.cpp -o matread1.o -g -O -Iinclude
g++ matread1.o -o matread1.exe
g++ -c matmul1.cpp -o matmul1.o -g -O -Iinclude
g++ matmul1.o -o matmul1.exe
</code></pre>
<p>If there is no error, you successfully built all the sample executable
programs.</p>
<p>Now switch to <code>turing/c++</code> directory.
There is job script called <code>job-matmul1-c++-1x2.sge</code>.
Please take a look by using <code>cat</code> command:
p
[user@turing ~/ODU-HPC-samples/c++]$ cd ../turing/c++
[user@turing ~/ODU-HPC-samples/turing/c++]$ cat job-matmul1-c++-1x2.sge</p>
<p>Now submit this job to SGE:</p>
<pre><code>[user@turing ~/ODU-HPC-samples/c++]$ qsub job-matmul1-c++-1x2.sge
</code></pre>
<p>qsub will respond with an output like this (where the job number will
be different):</p>
<pre><code>Your job 251245 ("Matmul-1x2") has been submitted
</code></pre>
<p>You can check the job progress by invoking:</p>
<pre><code>[user@turing ~/ODU-HPC-samples/c++]$ qstat -u $USER
</code></pre>
<p>Here, <code>$USER</code> is a shell variable containing your user name on Turing.
When this job is executed, there wil be an output file in this
subdirectory named <code>Matmul-1x2.o251245</code>.
This file name is formatted as <code><JOBNAME>.o<JOBNUMBER></code>.
Inspect the content of that file, which should be like this:</p>
<pre><code>[user@turing ~/ODU-HPC/samples/c++]$ cat Matmul-1x2.o251245
## matmul1 ## infile1=../../samples/matrices/matrix01.in infile2=../../samples/matrices/matrix02.in
A dimensions = 4 5
B dimensions = 5 3
-6393.28 5491.5 -3923.1
-2279.63 2019.51 -2163.88
-366.494 -137.821 -1151.42
904.896 -2839.5 1344.5
</code></pre>
<h2>Python</h2>
<p>Python is an interpreted language, therefore it does not need to be compiled.
To launch a python script <code>foo.py</code>, you can simply invoke:</p>
<pre><code>[use@turing ~/some-dir]$ python foo.py [ARGUMENTS]
</code></pre>
<p>The example job script for python is provided in <code>turing/python</code> subdirectory.
In that directory, examine the content of <code>job-matmul1-python-1x2.sge</code>.
The script itself is provided in <code>python</code> subdirectory, just below the
root directory of the package.</p>
<p><em>Exercise:</em> Submit that python job script using the usual <code>qsub</code> command:</p>
<pre><code>[user@turing ~/ODU-HPC-samples/turing/python]$ cat job-matmul1-python-1x2.sge
</code></pre>
<p>This script performas the same matrix multiplication of two input
matrices as the C++ example; therefore the resulting matrix should be
identical to the previous (C++) calculation.</p>
<p><em>Exercise:</em> Examine the output after the job is completed.</p>
<p>Make sure that there is no glaring python and C++
output. If there is a difference, what looks different? Why?</p>
<h2>R</h2>
<p>There is also the same example, implemented in R scripting language.
Please inspect <code>R</code> and <code>turing/R</code> subdirectories for the R program
and its job script.</p>