Skip to content

Commit 73afba8

Browse files
committed
deploy: fad2b57
1 parent 0a66067 commit 73afba8

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed

_sources/oar.rst.txt

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,60 @@ Here, tips to efficiently launch multiple jobs are provided.
7474
7575
id=`echo "$OAR_JOB_ID - $OAR_ARRAY_ID + 2" | bc -l` # <---- This id runs from 0 to 50, each job gets one, with which you can e.g. index a bash array
7676
temperatures=(0.25 0.5 1 .... )
77-
T=${temperatures[${id}]}
77+
T=${temperatures[${id}]}
78+
79+
Measure the CPU Usage per User
80+
------------------------------
81+
82+
This script calculates the total CPU core usage per user based on job information
83+
from the `oarstat` command. The output will list each user along with the total
84+
number of CPU cores they are using.
85+
86+
Create a Bash Script (for instance named `cpu_usage.sh`), and copy the
87+
following lines into the file:
88+
89+
.. code:: bash
90+
91+
#!/bin/bash
92+
93+
# Run oarstat and process its output to count the total cores per user
94+
oarstat | awk '
95+
# Only process lines that start with a job number (indicating a valid job line)
96+
/^[0-9]+/ {
97+
# $3 is the user, and we look for "R=" to get the core count from any field
98+
for (i=1; i<=NF; i++) {
99+
if ($i ~ /^R=[0-9]+/) {
100+
# Extract the core count from the "R=" field
101+
split($i, core_count, "=")
102+
user_cores[$3] += core_count[2] # Accumulate the core count for the user
103+
}
104+
}
105+
}
106+
# After processing all lines, print the total cores for each user
107+
END {
108+
for (user in user_cores) {
109+
print user, user_cores[user] # Output user and their total core count
110+
}
111+
}
112+
' | sort # Sort the output alphabetically by username
113+
114+
Run the following command to give execution permissions to the script:
115+
116+
.. code:: bash
117+
118+
chmod +x cpu_usage.sh
119+
./cpu_usage.sh
120+
121+
It will return something like:
122+
123+
.. code:: bash
124+
125+
calvof 83
126+
farutial 2
127+
gravells 160
128+
joyeuxm 280
129+
jungg 145
130+
mhirizn- 3
131+
nagasawt 1
132+
ozawam 53
133+
quilliec 2

oar.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,55 @@ <h2>Launch Multiple Jobs<a class="headerlink" href="#launch-multiple-jobs" title
176176
</pre></div>
177177
</div>
178178
</section>
179+
<section id="measure-the-cpu-usage-per-user">
180+
<h2>Measure the CPU Usage per User<a class="headerlink" href="#measure-the-cpu-usage-per-user" title="Link to this heading"></a></h2>
181+
<p>This script calculates the total CPU core usage per user based on job information
182+
from the <cite>oarstat</cite> command. The output will list each user along with the total
183+
number of CPU cores they are using.</p>
184+
<p>Create a Bash Script (for instance named <cite>cpu_usage.sh</cite>), and copy the
185+
following lines into the file:</p>
186+
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/bin/bash</span>
187+
188+
<span class="c1"># Run oarstat and process its output to count the total cores per user</span>
189+
oarstat<span class="w"> </span><span class="p">|</span><span class="w"> </span>awk<span class="w"> </span><span class="s1">&#39;</span>
190+
<span class="s1"> # Only process lines that start with a job number (indicating a valid job line)</span>
191+
<span class="s1"> /^[0-9]+/ {</span>
192+
<span class="s1"> # $3 is the user, and we look for &quot;R=&quot; to get the core count from any field</span>
193+
<span class="s1"> for (i=1; i&lt;=NF; i++) {</span>
194+
<span class="s1"> if ($i ~ /^R=[0-9]+/) {</span>
195+
<span class="s1"> # Extract the core count from the &quot;R=&quot; field</span>
196+
<span class="s1"> split($i, core_count, &quot;=&quot;)</span>
197+
<span class="s1"> user_cores[$3] += core_count[2] # Accumulate the core count for the user</span>
198+
<span class="s1"> }</span>
199+
<span class="s1"> }</span>
200+
<span class="s1"> }</span>
201+
<span class="s1"> # After processing all lines, print the total cores for each user</span>
202+
<span class="s1"> END {</span>
203+
<span class="s1"> for (user in user_cores) {</span>
204+
<span class="s1"> print user, user_cores[user] # Output user and their total core count</span>
205+
<span class="s1"> }</span>
206+
<span class="s1"> }</span>
207+
<span class="s1">&#39;</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>sort<span class="w"> </span><span class="c1"># Sort the output alphabetically by username</span>
208+
</pre></div>
209+
</div>
210+
<p>Run the following command to give execution permissions to the script:</p>
211+
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>chmod<span class="w"> </span>+x<span class="w"> </span>cpu_usage.sh
212+
./cpu_usage.sh
213+
</pre></div>
214+
</div>
215+
<p>It will return something like:</p>
216+
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>calvof<span class="w"> </span><span class="m">83</span>
217+
farutial<span class="w"> </span><span class="m">2</span>
218+
gravells<span class="w"> </span><span class="m">160</span>
219+
joyeuxm<span class="w"> </span><span class="m">280</span>
220+
jungg<span class="w"> </span><span class="m">145</span>
221+
mhirizn-<span class="w"> </span><span class="m">3</span>
222+
nagasawt<span class="w"> </span><span class="m">1</span>
223+
ozawam<span class="w"> </span><span class="m">53</span>
224+
quilliec<span class="w"> </span><span class="m">2</span>
225+
</pre></div>
226+
</div>
227+
</section>
179228
</section>
180229

181230
</main>
@@ -198,6 +247,7 @@ <h2>Launch Multiple Jobs<a class="headerlink" href="#launch-multiple-jobs" title
198247
<li><a class="reference internal" href="#cancel-all-your-jobs-at-once">Cancel All Your Jobs at Once</a></li>
199248
<li><a class="reference internal" href="#record-the-last-job-id-and-state">Record the last Job ID and state</a></li>
200249
<li><a class="reference internal" href="#launch-multiple-jobs">Launch Multiple Jobs</a></li>
250+
<li><a class="reference internal" href="#measure-the-cpu-usage-per-user">Measure the CPU Usage per User</a></li>
201251
</ul>
202252
</li>
203253
</ul>

0 commit comments

Comments
 (0)