<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>High-Performance Computing Clusters on </title>
    <link>https://plantarum.ca/tags/hpc/</link>
    <description>Recent content in High-Performance Computing Clusters on </description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <managingEditor>tyler@plantarum.ca (Tyler Smith)</managingEditor>
    <webMaster>tyler@plantarum.ca (Tyler Smith)</webMaster>
    <lastBuildDate>Tue, 04 Feb 2025 00:00:00 +0000</lastBuildDate>
    
        <atom:link href="https://plantarum.ca/tags/hpc/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>High-Performance Computing Clusters</title>
      <link>https://plantarum.ca/tags/hpc/</link>
      <pubDate>Tue, 04 Feb 2025 00:00:00 +0000</pubDate>
      <author>tyler@plantarum.ca (Tyler Smith)</author>
      <guid>https://plantarum.ca/tags/hpc/</guid>
      <description>&lt;p&gt;Posts and tutorials dealing with high-performance computing clusters, such
as the &lt;a href=&#34;https://docs.alliancecan.ca/wiki/Getting_started&#34;&gt;Digital Research Alliance of Canada&lt;/a&gt;
or the &lt;a href=&#34;https://www.canada.ca/en/shared-services/corporate/hosting-services/high-performance-computing.html&#34;&gt;Canadian Federal Government
supercomputers&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re just getting started, basics for each system are covered in
&amp;ldquo;Notes&amp;rdquo; for each system: &lt;a href=&#34;https://plantarum.ca/2020/09/21/notes-on-compute-canada-accounts/&#34;&gt;Alliance
Canada&lt;/a&gt; (formerly known as
Compute Canada); &lt;a href=&#34;https://plantarum.ca/2023/05/02/notes-on-gpsc-accounts/&#34;&gt;GPSC&lt;/a&gt; (i.e., the
Government of Canada General Purpose Scientific Computing cluster). I also
mention some useful tools and approaches in an older article on making your
own mini-cluster on
&lt;a href=&#34;https://plantarum.ca/2014/08/19/medium-performance-cluster-computing/&#34;&gt;DigitalOcean&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A number of these articles describe how I use
&lt;a href=&#34;https://www.gnu.org/software/emacs/&#34;&gt;Emacs&lt;/a&gt; to manage my interactions with
these systems. Emacs is a very powerful tool for writing and documenting
scripts, and managing the process of submitting them to the cluster.
However, the learning curve can be daunting. If you&amp;rsquo;re just going to be
doing one or two small projects on a cluster, it is probably not worth the
investiment to learn. On the other hand, if you will be doing this
regularly, or you just like tinkering with computer stuff, it can be very
rewarding. You can find my &lt;a href=&#34;https://plantarum.ca/tags/emacs/&#34;&gt;Emacs articles here&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Replacing Loops with Array Jobs</title>
      <link>https://plantarum.ca/2025/01/24/array-jobs/</link>
      <pubDate>Fri, 24 Jan 2025 00:00:00 +0000</pubDate>
      <author>tyler@plantarum.ca (Tyler Smith)</author>
      <guid>https://plantarum.ca/2025/01/24/array-jobs/</guid>
      <description>&lt;h1 id=&#34;loops-in-bioinformatic-pipelines&#34;&gt;Loops in Bioinformatic Pipelines&lt;/h1&gt;
&lt;p&gt;A common requirement of many bioinformatics pipelines is completing the
same analysis on a list of files. This is simple to do with a bit of &lt;a href=&#34;https://tldp.org/LDP/abs/html/&#34;&gt;Bash
scripting:&lt;/a&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --job-name=ustacks&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --output=ustacks.log&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --time=360:00:00&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --ntasks=1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --cpus-per-task=8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --mem-per-cpu=8G&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;source ~/miniconda3/etc/profile.d/conda.sh
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;conda activate stacksM
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;M&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;reads_dir&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;./prort/concat/
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;out_dir&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;ustacks
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;threads&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;while&lt;/span&gt; read SAMPLE; &lt;span style=&#34;color:#66d9ef&#34;&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ustacks -t gzfastq -f &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;reads_dir&lt;span style=&#34;color:#e6db74&#34;&gt;}${&lt;/span&gt;SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;.1.fq.gz &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            -o &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;out_dir&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt; -m &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            --name &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt; -M $M -p &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;threads&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;done&lt;/span&gt; &amp;lt;SAMPLES.txt
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This script reads each line of the file &lt;code&gt;SAMPLES.txt&lt;/code&gt;, passes that value to
the program &lt;code&gt;ustacks&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s fine, but it can require a &lt;em&gt;lot&lt;/em&gt; of cluster time. In this case, I
have 96 files listed in &lt;code&gt;SAMPLES.txt&lt;/code&gt;, and each of them will take three or
four hours to process. That&amp;rsquo;s 15 days. In reality, it may take much longer,
as the cluster may not be able to schedule my job immediately given the
length (at least on the cluster I use!).&lt;/p&gt;
&lt;h1 id=&#34;replacing-loops-with-array-jobs&#34;&gt;Replacing Loops with Array Jobs&lt;/h1&gt;
&lt;p&gt;However, each of these 96 jobs can be processed at the same time. There&amp;rsquo;s
no interaction between them. If instead of asking for a single 15 day job,
I ask for 96 six-hour jobs, it&amp;rsquo;s easier for the cluster to schedule them,
and my total run time drops to something closer to the length of a single
job (maybe 6-12 hours, depending on how quickly they get scheduled).&lt;/p&gt;
&lt;p&gt;This is what array jobs do. I can replace the script above with this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --job-name=ustacks%a&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --output=ustacks_%a.log&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --time=6:00:00&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --ntasks=1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --cpus-per-task=8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --mem-per-cpu=8G&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;source ~/miniconda3/etc/profile.d/conda.sh
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;conda activate stacksM
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;M&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;reads_dir&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;./prort/concat/
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;out_dir&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;ustacks
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;threads&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;SAMPLE&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;sed &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;SLURM_ARRAY_TASK_ID&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;q;d&amp;#34;&lt;/span&gt; SAMPLES.txt&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ustacks -t gzfastq -f &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;reads_dir&lt;span style=&#34;color:#e6db74&#34;&gt;}${&lt;/span&gt;SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;.1.fq.gz &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        -o &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;out_dir&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt; -m &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        --name &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt; -M $M -p &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;threads&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It&amp;rsquo;s nearly the same as the original. The key difference is I&amp;rsquo;ve replaced
the &lt;code&gt;while&lt;/code&gt; loop with a single variable, set using a line of
&lt;a href=&#34;https://www.gnu.org/software/sed/manual/sed.html&#34;&gt;sed&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SAMPLE=$(sed &amp;quot;${SLURM_ARRAY_TASK_ID}q;d&amp;quot; SAMPLES.txt)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Sed is a very powerful tool for processing text. In this case, I&amp;rsquo;ve asked
it to search through the file &lt;code&gt;SAMPLES.txt&lt;/code&gt;, skip forward to the line
&lt;code&gt;${SLURM_ARRAY_TASK_ID}&lt;/code&gt;, print that line, and then quit.&lt;/p&gt;
&lt;p&gt;Where does &lt;code&gt;SLURM_ARRAY_TASK_ID&lt;/code&gt; come from? That&amp;rsquo;s variable is set for us
automatically when we submit our script as an array job. Instead of the
usual invocation of Slurm:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sbatch my_script.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We&amp;rsquo;ll do this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sbatch --array=1-96 my_script.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When we do this, it tells Slurm that we want to submit 96 jobs. Each job
will be run with identical code, except for one thing: Slurm will insert
the variable &lt;code&gt;SLURM_ARRAY_TASK_ID&lt;/code&gt; with a different value into each script.
That value is also inserted into my job name and log file, using the &lt;code&gt;%a&lt;/code&gt;
placeholder:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --job-name=ustacks%a&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --output=ustacks_%a.log&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;With that little change, instead of waiting a month for my 15 day job to
run, I wait a day for 96 six-hour jobs to run.&lt;/p&gt;
&lt;h2 id=&#34;selectively-repeating-failed-jobs&#34;&gt;Selectively Repeating Failed jobs&lt;/h2&gt;
&lt;p&gt;Another benefit of this approach is that it allows you to easily resubmit
only a subset of your jobs. In the example above I&amp;rsquo;ve asked for six hours
for each file. If some of those files happen to require more time than
that, they will fail with a timeout. You&amp;rsquo;lll see this in your job logs.
Here&amp;rsquo;s an example from an array where I requested 36 hours per job:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;date
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sacct --jobs&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;3069231&lt;/span&gt; --format&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;jobid,jobname,state,elapsed | grep -v &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;batch\|extern&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: Fri &lt;span style=&#34;color:#ae81ff&#34;&gt;24&lt;/span&gt; Jan &lt;span style=&#34;color:#ae81ff&#34;&gt;2025&lt;/span&gt; 12:10:04 PM EST
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: JobID           JobName      State    Elapsed 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: ------------ ---------- ---------- ---------- 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: 3069231_1    ustacks23+  COMPLETED   19:14:14 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: 3069231_2    ustacks23+  COMPLETED   17:51:58 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: 3069231_3    ustacks23+  COMPLETED   13:20:56 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: 3069231_4    ustacks23+  COMPLETED   23:43:24 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: 3069231_5    ustacks23+    TIMEOUT 1-12:00:01 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: 3069231_6    ustacks23+  COMPLETED   17:43:17 
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;: 3069231_7    ustacks23+  COMPLETED   17:07:07 
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can see that that wasn&amp;rsquo;t enough time for the fifth job. I can rerun
just that job (after increasing the requested time) with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sbatch --array=5 my_script.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or if there are a group of failed jobs, I can combine them like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sbatch --array=5,7,20-23 my_script.sh
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Much easier than repeating the analysis of all 96 samples just because one
or two of them needed more time.&lt;/p&gt;
&lt;h1 id=&#34;tips-for-using-array-jobs&#34;&gt;Tips for Using Array jobs&lt;/h1&gt;
&lt;h2 id=&#34;automating-making-lists-to-use-in-array-jobs&#34;&gt;Automating Making Lists to use in Array Jobs&lt;/h2&gt;
&lt;p&gt;You can create the lists of samples or files you want to cycle over by
hand. That&amp;rsquo;s probably the fastest way to do it, if you only need to do it
once. But as soon as you start repeating an analysis on different files,
you might benefit from some automation.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://tldp.org/LDP/abs/html/&#34;&gt;Bash scripting&lt;/a&gt; provides a huge variety of
useful tools for creating lists of files or samples you want to cycle
through with &lt;code&gt;SLURM_ARRAY_TASK_ID&lt;/code&gt;. I won&amp;rsquo;t provide a full tutorial, but a
few examples may be useful in showing you why it might be worth investing
some time to learn more about this.&lt;/p&gt;
&lt;h3 id=&#34;filtering-filenames-with-bash-pipes&#34;&gt;Filtering Filenames with Bash Pipes&lt;/h3&gt;
&lt;p&gt;I have a directory containing a list of files like this:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;B12A10.1.fq.gz	    BWA11.rem.2.fq.gz  HHA19.rem.1.fq.gz  RBB8.1.fq.gz
B12A10.2.fq.gz	    BWA1.2.fq.gz       HHA19.rem.2.fq.gz  RBB8.2.fq.gz
B12A10.rem.1.fq.gz  BWA13.1.fq.gz      HHA1.rem.1.fq.gz   RBB8.rem.1.fq.gz
B12A10.rem.2.fq.gz  BWA13.2.fq.gz      HHA1.rem.2.fq.gz   RBB8.rem.2.fq.gz
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each sample has a file of matched forward (&lt;code&gt;.1.fq.gz&lt;/code&gt;) and reverse reads
(&lt;code&gt;.2.fq.gz&lt;/code&gt;), and a file of forward and reverse unmatched reads
(&lt;code&gt;.rem.1.fq.gz&lt;/code&gt; and &lt;code&gt;.rem.2.fq.gz&lt;/code&gt;). In my processing I&amp;rsquo;ll want to loop
over each individual sample, not over all four files for each sample. I do
this with the following line:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ls reads/*.1.fq.gz | grep -v rem | &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    xargs -n &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;  basename -s .1.fq.gz &amp;gt; 2023_list.txt
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The first clause, &lt;code&gt;ls reads/*.1.fq.gz&lt;/code&gt; lists all the forward read files.
This will include both &lt;code&gt;B12A10.1.fq.gz&lt;/code&gt; and &lt;code&gt;B12A10.rem.1.fq.gz&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Next, I use &lt;code&gt;grep -v rem&lt;/code&gt;. That tells &lt;code&gt;grep&lt;/code&gt; to filter the values we give it
for the string &lt;code&gt;rem&lt;/code&gt;. The &lt;code&gt;-v&lt;/code&gt; argument tells &lt;code&gt;grep&lt;/code&gt; to &amp;lsquo;invert&amp;rsquo; the
search. In other words, remove all the values that include &lt;code&gt;rem&lt;/code&gt;. At this
point, we have a single file name per sample, e.g. &lt;code&gt;B12A10.1.fq.gz&lt;/code&gt; and
&lt;code&gt;RBB8.1.fq.gz&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The next step is a combination. First, we pass the values from grep to the
program &lt;code&gt;xargs&lt;/code&gt; with the argument &lt;code&gt;-n 1&lt;/code&gt;. That tells &lt;code&gt;xargs&lt;/code&gt; to pass the
values it recieves one at a time to the following command. That command is
&lt;code&gt;basename&lt;/code&gt;, which will strip off the suffix we identify with the &lt;code&gt;-s&lt;/code&gt;
argument: &lt;code&gt;.1.fg.gz&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Finally, the results are stored in a new file, &lt;code&gt;2023_list.txt&lt;/code&gt;, which will
look like this:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;B12A10
BWA11
HHA19
RBB8
...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you&amp;rsquo;d rather not have another file cluttering up your directory, you can
include the entire pipeline in your Slurm script&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --job-name=ustacks%a&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --output=ustacks_%a.log&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --time=6:00:00&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --ntasks=1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --cpus-per-task=8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#SBATCH --mem-per-cpu=8G&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;source ~/miniconda3/etc/profile.d/conda.sh
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;conda activate stacksM
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;M&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;reads_dir&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;./prort/concat/
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;out_dir&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;ustacks
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;threads&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;SAMPLE&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;ls reads/*.1.fq.gz | grep -v rem | &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    xargs -n &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;  basename -s .1.fq.gz | &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    sed &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;SLURM_ARRAY_TASK_ID&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;q;d&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;$SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ustacks -t gzfastq -f &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;reads_dir&lt;span style=&#34;color:#e6db74&#34;&gt;}${&lt;/span&gt;SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;.1.fq.gz &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        -o &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;out_dir&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt; -m &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        --name &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt; -M $M -p &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;threads&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;parameter-substitutions&#34;&gt;Parameter Substitutions&lt;/h3&gt;
&lt;p&gt;Another set of useful tools are &lt;a href=&#34;https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html&#34;&gt;shell parameter
substitutions&lt;/a&gt;.
They can be a convenient way of trimming prefixes and suffices off of
names, particularly if you use (or received) concistently formatted file
names. For example, if my samples are coded as
&lt;code&gt;population&lt;/code&gt;_&lt;code&gt;individual&lt;/code&gt;.&lt;code&gt;suffix&lt;/code&gt;, I can isolate the various bits like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;FILE&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;NS01_01.1.fq.gz
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;SAMPLE&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;FILE%.1.fq.gz&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;POP&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;FILE%_*&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;IND&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;SAMPLE#&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;POP&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;_&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;echo File: &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;FILE&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;echo   Sample: &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;SAMPLE&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;, Pop: &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;POP&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;, Ind: &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;IND&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;
&lt;p&gt;File: NS01_01.1.fq.gz &lt;br&gt;
Sample: NS01_01, Pop: NS01, Ind: 01&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&#34;tips-for-emacs-users&#34;&gt;Tips for Emacs Users&lt;/h1&gt;
&lt;p&gt;I&amp;rsquo;ve written the above for use by anyone working on a cluster that uses
Slurm for job submission. However, as I explained in my &lt;a href=&#34;https://plantarum.ca/2025/01/10/slurm-yasnippet/&#34;&gt;previous
post&lt;/a&gt;,
&lt;a href=&#34;https://www.gnu.org/software/emacs/&#34;&gt;Emacs&lt;/a&gt; snippets provide an extra
layer of convenience for managing Slurm scripts. Following the approach I
outline there, I write my Slurm scripts as code blocks in
&lt;a href=&#34;https://orgmode.org/&#34;&gt;https://orgmode.org/&lt;/a&gt;. In this context, an array job will look something
like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-org&#34; data-lang=&#34;org&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#+begin_src &lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;bash&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt; :results output
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  date
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  sbatch --array&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;1-96 &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;lt;&amp;lt;SUBMITSCRIPT
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  #!/bin/bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  #SBATCH --job-name=my_job_%a
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  #SBATCH --output=my_job_%a.log
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  #SBATCH --time=1-00:00:00
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  #SBATCH --ntasks=1
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  #SBATCH --cpus-per-task=4
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  #SBATCH --mem-per-cpu=96GB
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  source ~/miniconda3/etc/profile.d/conda.sh
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  conda activate stacksM
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  THREADS=8
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  FILE=\$(ls stacks23_out/*alleles.tsv.gz | grep -v catalog | sed -n &amp;#34;\${SLURM_ARRAY_TASK_ID}p&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  DIR=\$(dirname \$FILE)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  SAMPLE=\$(basename -s .alleles.tsv.gz \$FILE)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  echo &amp;#34;\$DIR : \$SAMPLE&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  cd \${DIR}
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  sstacks -c ../\${DIR} -s ../\${DIR}/\$SAMPLE -p \$THREADS
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;  SUBMITSCRIPT&lt;/span&gt;              
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#+end_src&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Taming Slurm with Emacs&#39; Yasnippet</title>
      <link>https://plantarum.ca/2025/01/10/slurm-yasnippet/</link>
      <pubDate>Fri, 10 Jan 2025 00:00:00 +0000</pubDate>
      <author>tyler@plantarum.ca (Tyler Smith)</author>
      <guid>https://plantarum.ca/2025/01/10/slurm-yasnippet/</guid>
      <description>&lt;p&gt;&lt;img src=&#34;https://plantarum.ca/images/yasnippet.gif&#34; alt=&#34;Animation&#34;&gt;&lt;/p&gt;
&lt;p&gt;In a previous post I explained how to set up &lt;a href=&#34;https://plantarum.ca/2024/03/28/org-cluster/&#34;&gt;Emacs Org-mode for working on
a remote cluster&lt;/a&gt;. If your cluster uses
&lt;a href=&#34;https://slurm.schedmd.com/overview.html&#34;&gt;Slurm&lt;/a&gt; to manage jobs, you will
need to specify a set of options for submission. This isn&amp;rsquo;t difficult, but
it&amp;rsquo;s tedious. We can automate away most of the tedium with Emacs,
specifically the &lt;a href=&#34;http://joaotavora.github.io/yasnippet/&#34;&gt;YASnippet
package&lt;/a&gt;. (YASnippet stands for
&amp;ldquo;yet another snippet package&amp;rdquo;, by the way). The animation above shows what
we&amp;rsquo;re aiming for.&lt;/p&gt;
&lt;h1 id=&#34;install-yasnippet&#34;&gt;Install YASnippet&lt;/h1&gt;
&lt;p&gt;The homepage includes instructions on how to install it. The easiest uses
the &lt;a href=&#34;https://github.com/joaotavora/yasnippet?tab=readme-ov-file#install-with-package-install&#34;&gt;Emacs package
manager&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you want to use it by default, you should add the following to your
config:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;(yas-global-mode 1)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Alternatively, you can set it for each mode you want it applied to. For
example, the following turns it on for &lt;code&gt;org-mode&lt;/code&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;(add-hook &amp;lsquo;org-mode-hook #&amp;lsquo;yas-minor-mode)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;You may also need the following line to ensure all your previously defined
templates are loaded:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;(yas-reload-all)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&#34;writing-snippets&#34;&gt;Writing Snippets&lt;/h1&gt;
&lt;p&gt;A snippet is a bit of text that you can automatically insert into a file.
It can include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;text, inserted &amp;lsquo;as-is&amp;rsquo;;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;tab stop fields, which you can navigate through and enter text (with or
without default values) when the template is inserted;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;more complex variations combining fields, transformations, mirrors and
elisp code&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To get started, call the command &lt;code&gt;M-x yas-new-snippet&lt;/code&gt;. This will open a
new buffer with the following text:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# -*- mode: snippet -*-
# name: 
# key: 
# --
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The cursor will be on the &lt;code&gt;name&lt;/code&gt; row. This value is for our benefit, so
something descriptive is appropriate. I&amp;rsquo;ll use the phrase &amp;lsquo;Slurm header&amp;rsquo;.&lt;/p&gt;
&lt;p&gt;This buffer is actually a snippet itself, so we can use the &lt;code&gt;TAB&lt;/code&gt; key to
jump to the next tab stop, which is on the next line.&lt;/p&gt;
&lt;p&gt;The key is a combination of one or more letters that we&amp;rsquo;ll use to insert
the template. It can&amp;rsquo;t contain a space. It should be memorable, but not
something we&amp;rsquo;ll type in other contexts. In this case, &lt;code&gt;slrm&lt;/code&gt; will do. Hit
&lt;code&gt;TAB&lt;/code&gt; again, and point will move down into the body of the snippet.&lt;/p&gt;
&lt;p&gt;This is where we put the text for our submission script.&lt;/p&gt;
&lt;p&gt;For starters, we can include any text we want to appear &amp;lsquo;as-is&amp;rsquo;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# -*- mode: snippet -*-
# name: Slurm header
# key: slrm
# --
#+BEGIN_SRC bash :results output
  date
  sbatch &amp;lt;&amp;lt;SUBMITSCRIPT
  #!/bin/bash
  #SBATCH --job-name=MYJOB
  #SBATCH --output=MYJOB.log
  #SBATCH --open-mode=truncate
  #SBATCH --partition=standard
  #SBATCH --time=24:00:00
  #SBATCH --ntasks=1
  #SBATCH --cpus-per-task=1

  $0

  SUBMITSCRIPT
#+END_SRC
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I start and end with the &lt;code&gt;org-mode&lt;/code&gt; block header/footer, with the language
set to &lt;code&gt;bash&lt;/code&gt; and the &lt;code&gt;:results output&lt;/code&gt; option. These never change.&lt;/p&gt;
&lt;p&gt;I start the code chunk with the &lt;code&gt;date&lt;/code&gt; command, so it will capture the time and
date I submitted the script, which will be recorded in the &lt;code&gt;org&lt;/code&gt; file.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;lt;&amp;lt;SUBMITSCRIPT
...
SUBMITSCRIPT
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Defines the script that is passed to Slurm, as discussed in my
&lt;a href=&#34;https://plantarum.ca/2024/03/28/org-cluster/&#34;&gt;previous&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After that we find the actual Slurm directives with default values for each
line.&lt;/p&gt;
&lt;p&gt;There is one special field here, &lt;code&gt;$0&lt;/code&gt;. This is where the cursor will be
after the template is inserted.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s fine, but we still need to go back and fill in the actual values for
the directives. We can improve this with by adding tab stops, along with
default values and &lt;code&gt;mirrors&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# -*- mode: snippet -*-
# name: Slurm header
# expand-env: ((yas-indent-line &amp;#39;fixed))
# key: slrm
# --
#+BEGIN_SRC bash :results output
  date
  sbatch &amp;lt;&amp;lt;SUBMITSCRIPT
  #!/bin/bash
  #SBATCH --job-name=${1:NAME}
  #SBATCH --output=$1.log
  #SBATCH --open-mode=truncate
  #SBATCH --partition=standard
  #SBATCH --time=${2:24:00:00}
  #SBATCH --ntasks=1
  #SBATCH --cpus-per-task=${3:1}

  $0

  SUBMITSCRIPT
#+END_SRC
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When we insert this template, the cursor starts at the &lt;code&gt;--job-name&lt;/code&gt;
directive where the &lt;code&gt;${1:NAME}&lt;/code&gt; field is. The &lt;code&gt;1&lt;/code&gt; indicates this is the
first tab stop. The value &lt;code&gt;NAME&lt;/code&gt; is the default for this field. Whatever
value we enter here will be mirrored to the line below with the suffix
&lt;code&gt;log&lt;/code&gt;, i.e., &lt;code&gt;--output=NAME.log&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;After we&amp;rsquo;ve added the name, pressing &lt;code&gt;&amp;lt;tab&amp;gt;&lt;/code&gt; takes us to the second tab
stop, for the &lt;code&gt;time&lt;/code&gt; directive. My default is &lt;code&gt;24:00:00&lt;/code&gt;, but I can change
that to whatever I need. The third tab stop is for &lt;code&gt;cpus-per-task&lt;/code&gt;. After
that we tab to stop zero, where we can enter the body of our script.&lt;/p&gt;
&lt;p&gt;One final tweak: I want yasnippet to leave the indentation of this template
exactly as I&amp;rsquo;ve written it (i.e., &amp;lsquo;fixed&amp;rsquo;). To accomplish this, I&amp;rsquo;ve set
the &lt;code&gt;expand-env&lt;/code&gt; options in the header to use fixed indentation.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# expand-env: ((yas-indent-line &amp;#39;fixed))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can test out your snippet by calling &lt;code&gt;M-x yas-try-snippet&lt;/code&gt;, which is
bound to &lt;code&gt;C-c C-t&lt;/code&gt;. This will open a temporary buffer with the body of your
snippet inserted. You can then enter text and tab through the stops to see
how it works. &lt;code&gt;C-x k&lt;/code&gt; will kill the buffer when you&amp;rsquo;re done.&lt;/p&gt;
&lt;p&gt;When you&amp;rsquo;re done, you can install the snippet with &lt;code&gt;C-c C-c&lt;/code&gt;, (or &lt;code&gt;M-x yas-load-snippet-buffer-and-close)&lt;/code&gt;. Emacs will ask you what mode you want
to use the snippet in. In this case, it&amp;rsquo;s &lt;code&gt;org-mode&lt;/code&gt;.&lt;/p&gt;
&lt;h1 id=&#34;using-snippets&#34;&gt;Using Snippets&lt;/h1&gt;
&lt;p&gt;With that out of the way, you can insert your snippet in an org file with
the key sequence &lt;code&gt;slurm&amp;lt;tab&amp;gt;&lt;/code&gt;. Yasnippet provides a lot of additional
features. If you&amp;rsquo;re interested, see the &lt;a href=&#34;http://joaotavora.github.io/yasnippet/index.html&#34;&gt;online
manual&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&#34;interacting-with-slurm&#34;&gt;Interacting with Slurm&lt;/h1&gt;
&lt;p&gt;Once you&amp;rsquo;ve composed your Slurm script, you&amp;rsquo;ll want to submit it to the
cluster. If you&amp;rsquo;ve set up your org file to point to the cluster, as I
described in &lt;a href=&#34;https://plantarum.ca/2024/03/28/org-cluster/&#34;&gt;my previous post&lt;/a&gt;, all you need to
do is type &lt;code&gt;C-c C-c&lt;/code&gt;, while the cursor (point) is in your Slurm code block.&lt;/p&gt;
&lt;p&gt;It may take a few moments to connect, depending on your network. Once it
does, you should see something like this appear in your org file:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#+RESULTS:
: Tue 27 Aug 2024 12:17:15 PM EDT
: Submitted batch job 2931015
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We could log into the server to check on the status of our job. But with
another snippet, we can have Emacs do that for us.&lt;/p&gt;
&lt;p&gt;I use the following snippet for this purpose:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# name: sacct
# key: sss
# expand-env: ((yas-indent-line &amp;#39;fixed))
# --
#+BEGIN_SRC bash :results output 
date
sacct --jobs=`(save-excursion
                   (re-search-backward &amp;#34;^: Submitted batch job \\([[:digit:]]+\\)&amp;#34;)
                   (buffer-substring-no-properties
                     (match-beginning 1) (match-end 1)))`$0
#+END_SRC
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I&amp;rsquo;ve used a bit of elisp code to do some work here. Yasnippet will process
any text between back ticks (&amp;quot;`&amp;quot;) as elisp code. Let&amp;rsquo;s step through that:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;`(save-excursion 
   (re-search-backward &amp;#34;^: Submitted batch job \\([[:digit:]]+\\)&amp;#34;)
   (buffer-substring-no-properties (match-beginning 1) 
     (match-end 1)))`
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We start with &lt;code&gt;save-excursion&lt;/code&gt;. That tells Emacs that we want to come back
to the spot we started when the code is finished.&lt;/p&gt;
&lt;p&gt;Next we use &lt;code&gt;re-search-backward&lt;/code&gt; to find a line that starts with (&lt;code&gt;^&lt;/code&gt;) the
string &amp;ldquo;: Submitted batch job&amp;rdquo;, followed by a number. The number is wrapped
in &lt;code&gt;\\(&lt;/code&gt; and &lt;code&gt;\\)&lt;/code&gt;: these symbols tell Emacs to record the number as a
&amp;lsquo;match group&amp;rsquo;.&lt;/p&gt;
&lt;p&gt;Finally, we return the number with the &lt;code&gt;buffer-substring-no-properties&lt;/code&gt;
call. This returns the substring (text) in the current buffer, starting
with &lt;code&gt;(match-beginning 1)&lt;/code&gt; (which is the first digit in our number), and
ending with &lt;code&gt;(match-end 2)&lt;/code&gt;, which is the last digit in our number.&lt;/p&gt;
&lt;p&gt;This results in the following text being inserted in the buffer:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#+BEGIN_SRC bash :results output 
date
sacct --jobs=3472303
#+END_SRC
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;As written, this bit of code assumes the job we want to see the status of
is somewhere above the point that we call this snippet. It&amp;rsquo;s not very
robust if this isn&amp;rsquo;t true, but in my limited use-case it works well enough.&lt;/p&gt;
&lt;p&gt;The snippet leaves the cursor inside the code block. If you type &lt;code&gt;C-c C-c&lt;/code&gt;
at that point, it will submit the command to the cluster, and after a
moment or two you should see something like this:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#+RESULTS:
: Fri 10 Jan 2025 05:28:53 PM EST
: JobID           JobName  Partition    Account  AllocCPUS      State ExitCode 
: ------------ ---------- ---------- ---------- ---------- ---------- -------- 
: 3472303          my_job   standard grdi_gena+          1  COMPLETED      0:0 
: 3472303.bat+      batch            grdi_gena+          1  COMPLETED      0:0 
: 3472303.ext+     extern            grdi_gena+          1  COMPLETED      0:0 
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&#34;viewing-job-output&#34;&gt;Viewing Job Output&lt;/h1&gt;
&lt;p&gt;The preceding covers most of my needs for interacting with my cluster. One
last trick that can be handy is linking to log files or program output.&lt;/p&gt;
&lt;p&gt;You can insert a link to a file in org mode with &lt;code&gt;C-c C-l&lt;/code&gt;. You will be
prompted for the file location. This can include remote files with the
syntax: &lt;code&gt;/ssh:user@host:path/to/file&lt;/code&gt;; this can be shortened to
&lt;code&gt;/ssh:host:path/to/file&lt;/code&gt; if you&amp;rsquo;ve set the appropriate options in
&lt;code&gt;.ssh/config&lt;/code&gt; as I describe in a &lt;a href=&#34;https://plantarum.ca/2023/05/02/notes-on-gpsc-accounts/#configure-keys-and-addresses&#34;&gt;previous
post&lt;/a&gt;.
Next you&amp;rsquo;re prompted for the name of the link, which can be anything you
like. Once the link is complete, Emacs will colour it to let you know it
has a special power: you can view the file by pressing enter on the link.&lt;/p&gt;
&lt;p&gt;I don&amp;rsquo;t do this often enough to have made a snippet for it.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Introduction to Emacs&#39; Org Mode for cluster computing</title>
      <link>https://plantarum.ca/2024/03/28/org-cluster/</link>
      <pubDate>Thu, 28 Mar 2024 00:00:00 +0000</pubDate>
      <author>tyler@plantarum.ca (Tyler Smith)</author>
      <guid>https://plantarum.ca/2024/03/28/org-cluster/</guid>
      <description>


&lt;div id=&#34;getting-started&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Getting Started&lt;/h1&gt;
&lt;p&gt;This tutorial builds on my previous post
&lt;a href=&#34;https://www.gnu.org/software/emacs/&#34;&gt;Emacs&lt;/a&gt; posts (ie.,
&lt;a href=&#34;https://plantarum.ca/2020/06/16/emacs-tutorial-01/&#34;&gt;introduction&lt;/a&gt;,
&lt;a href=&#34;https://plantarum.ca/2020/06/17/emacs-tutorial-02/&#34;&gt;Orgmode&lt;/a&gt;, &lt;a href=&#34;https://plantarum.ca/2020/12/30/emacs-03/&#34;&gt;R and
ESS&lt;/a&gt;). If you’re not familiar with Emacs, you might
want to look through those first, particularly
&lt;a href=&#34;https://plantarum.ca/2020/06/17/emacs-tutorial-02/&#34;&gt;Orgmode&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In this post, I will show you how to setup an &lt;code&gt;Org mode&lt;/code&gt; (or &lt;code&gt;Orgmode&lt;/code&gt;,
&lt;code&gt;org-mode&lt;/code&gt;) file on your local machine (laptop or office desktop) to manage
and run a cluster computing project.&lt;/p&gt;
&lt;p&gt;While not absolutely necessary, working this way is &lt;em&gt;much&lt;/em&gt; easier if you’ve
configured your machine to provide keywordless access to the server. I’ve
talked about setting up your &lt;a href=&#34;https://plantarum.ca/2023/05/02/notes-on-gpsc-accounts/#configure-keys-and-addresses&#34;&gt;.ssh/config
file&lt;/a&gt;
to manage usernames and hostnames/addresses previously, as well as setting
up &lt;a href=&#34;https://plantarum.ca/2014/08/19/medium-performance-cluster-computing#security&#34;&gt;RSA
keys&lt;/a&gt;
so you can securely access remote servers without a password.&lt;/p&gt;
&lt;p&gt;In addition, within Emacs you’ll likely want to configure the variable
&lt;code&gt;org-confirm-babel-evaluate&lt;/code&gt; to &lt;code&gt;nil&lt;/code&gt;, so that you don’t get asked for
confirmation each time you try to evalute a code block, and also to
configure which languages you would like to use in code blocks, via the
&lt;code&gt;Org Babel Load Languages&lt;/code&gt; setting. I step through this in my &lt;a href=&#34;https://plantarum.ca/2020/06/17/emacs-tutorial-02#setting-up&#34;&gt;previous
post&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;org-file-headers&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Org file headers&lt;/h1&gt;
&lt;p&gt;First off, we want to tell &lt;code&gt;Org Mode&lt;/code&gt; where we want to run our code. Putting
this information in the file header ensures it will apply to all the code
blocks in the file (unless we explicitly change it for a particular block).&lt;/p&gt;
&lt;p&gt;My file template includes the following two lines as the first two lines of
my &lt;code&gt;.org&lt;/code&gt; file:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;# -*- org-export-babel-evaluate: nil -*-
#+PROPERTY: header-args:bash :results output :dir /ssh:gpsc:./path/to/my/project&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first line tells &lt;code&gt;Orgmode&lt;/code&gt; not to evaluate code blocks if/when we
export our source file (i.e., if we want to create a pdf or html report).
If we don’t do this, then every time we export the document it will
resubmit all of our cluster jobs, which is almost certainly not what we
want.&lt;/p&gt;
&lt;p&gt;The second line sets the default properties for &lt;code&gt;bash&lt;/code&gt; code blocks.
&lt;code&gt;:results output&lt;/code&gt; means we want the text printed out by the code in our
code blocks inserted into the file. &lt;code&gt;:dir /ssh:gpsc:./path/to/my/project&lt;/code&gt;
means we want these code blocks to be run on the remote host &lt;code&gt;gpsc&lt;/code&gt;, which
we access through &lt;code&gt;ssh&lt;/code&gt;, and in the directory &lt;code&gt;./path/to/my/project&lt;/code&gt;
(relative to my home directory).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When this is properly configured, we can edit the &lt;code&gt;org&lt;/code&gt; file on our local
machine, and send all the code to the server to run!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you make a mistake in the header lines, or just want to change the path
or other details, be sure to update the settings by pressing &lt;code&gt;C-c C-c&lt;/code&gt; with
the cursor on the header line, or, in the menus, select ‘Org’ -&amp;gt;
‘Refresh/Reload’ -&amp;gt; ‘Refresh setup current buffer’.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;executing-code-on-the-server&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Executing code on the server&lt;/h1&gt;
&lt;p&gt;Now we’re ready to run some code. To create a block, enter the following
text in the file:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+begin_src bash
  date
  ls
#+end_src&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The lines &lt;code&gt;#+begin_src ...&lt;/code&gt; and &lt;code&gt;#+end_src&lt;/code&gt; denote the code block, with the
argument &lt;code&gt;bash&lt;/code&gt; indicating that this is the language for this block.&lt;/p&gt;
&lt;p&gt;With the cursor (point) anywhere in the block, hit &lt;code&gt;C-c C-c&lt;/code&gt; to evaluate
the code. The results will show up in a few moments:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+RESULTS:
: Thu 28 Mar 2024 09:31:21 PM UTC
: hostname.tld.ca
: bin  data  man	miniconda3  ovbin  rubus  slurm_sample.sh  srcs  wp2&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is the contents of my home directory on &lt;code&gt;hostname.tld.ca&lt;/code&gt; - success!&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;write-submit-job-requests-with-slurm&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Write &amp;amp; submit job requests (with slurm)&lt;/h1&gt;
&lt;p&gt;Now we can run bash scripts on the head node. That’s fine for installing
packages with &lt;code&gt;conda&lt;/code&gt;/&lt;code&gt;mamba&lt;/code&gt; or whatever system you’re using. But for
&lt;em&gt;real&lt;/em&gt; work, we’ll need to submit a job request. In my case we use the
&lt;code&gt;slurm&lt;/code&gt; scheduler. I use two different methods to run these scripts.&lt;/p&gt;
&lt;div id=&#34;heredocs&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Heredocs&lt;/h2&gt;
&lt;p&gt;In most cases, I include the entire script as a
&lt;a href=&#34;https://linuxize.com/post/bash-heredoc/&#34;&gt;heredoc&lt;/a&gt;:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+begin_src bash :results output
  sbatch &amp;lt;&amp;lt;SUBMITSCRIPT
  #!/bin/bash
  #SBATCH --job-name=myjob
  #SBATCH --output=myjob.log
  #SBATCH --time=24:00:00
  #SBATCH --cpus-per-task=1
  #SBATCH --mem-per-cpu=1G

  VARIABLE=&amp;quot;My variable&amp;quot;

  source ~/miniconda3/etc/profile.d/conda.sh
  conda activate bowtie2

  echo \$VARIABLE

  bowtie2 --help

  SUBMITSCRIPT
#+end_src&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(Of course the actual details will depend on how your server is set up,
with slurm, qsub, or whatever is set up).&lt;/p&gt;
&lt;p&gt;Note that when you include bash variables in scripts submitted as
&lt;code&gt;heredocs&lt;/code&gt;, you need to escape the &lt;code&gt;$&lt;/code&gt; when you reference them (e.g.,
&lt;code&gt;\$VARIABLE&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Again, we can submit this script by pressing &lt;code&gt;C-c C-c&lt;/code&gt; when the cursor is
anywhere in the code block. In this case, the output we get is from
&lt;code&gt;sbatch&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+RESULTS:
: Submitted batch job 2075188&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Having a record of the job number allows us to track its progress with
another code block:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+BEGIN_SRC bash
sacct --jobs=2075188 --format=jobid,jobname,state,elapsed,ReqMem,MaxRSS
#+END_SRC&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Running this (&lt;code&gt;C-c C-c&lt;/code&gt; again) returns the status of my job:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+RESULTS:
: JobID           JobName      State    Elapsed     ReqMem     MaxRSS 
: ------------ ---------- ---------- ---------- ---------- ---------- 
: 2075188         ustacks    RUNNING   00:00:07        64G            
: 2075188.bat+      batch    RUNNING   00:00:07                       
: 2075188.ext+     extern    RUNNING   00:00:07                       &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we’re getting somewhere! In this one file we can include our freehand
notes and metadata, along side the scripts we used in the analysis. One
file per project, so we don’t need to keep track of different script
versions for each step in a long workflow.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;standalone-scripts&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Standalone scripts&lt;/h2&gt;
&lt;p&gt;Most job scripts are pretty simple, so the &lt;code&gt;heredoc&lt;/code&gt; approach is fine, and
keeps all the details together in the &lt;code&gt;org&lt;/code&gt; file. However, if you have a
more involved script, you may want to keep it in a file of its own. That
will give you access to the language-specific editing features of Emacs,
and may help keep your main &lt;code&gt;org&lt;/code&gt; file to a manageable length.&lt;/p&gt;
&lt;p&gt;If you choose this approach, you can include a link to the external script
with the format:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[[file:/ssh:servername:path/to/script.sh][script.sh]]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You’ll want this file to be in the same directory you specified in the
&lt;code&gt;org&lt;/code&gt; file header.&lt;/p&gt;
&lt;p&gt;Using this link format, pressing enter with the cursor on the link text
will open that file for you, allowing you to read and edit it with ease.&lt;/p&gt;
&lt;p&gt;To submit the script, we can use a much smaller code block:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;sbatch script.sh&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This would be the way I would submit jobs in other languages as well, if
you use Perl, Python, or R in your analyses.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;streamlining-all-the-text-entry&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Streamlining all the text entry&lt;/h1&gt;
&lt;p&gt;This system works very well, and being based on plain text files it’s
pretty robust and portable. However, there are a lot of bits of text to
enter, and remembering all the syntax can be tedious. &lt;code&gt;orgmode&lt;/code&gt; provides
some conveniences to simplify this.&lt;/p&gt;
&lt;p&gt;To enter a new code block, you can use the shortcut &lt;code&gt;C-c C-,&lt;/code&gt; to open the
block menu, and select source code with &lt;code&gt;s&lt;/code&gt;. Then add the header &lt;code&gt;bash&lt;/code&gt; and
you’re ready to go. You can do the same thing via the menus with ‘Org’ -&amp;gt;
‘Editing’ -&amp;gt; ‘Add block structure’.&lt;/p&gt;
&lt;p&gt;The headers for &lt;code&gt;slurm&lt;/code&gt; scripts can be quite involved as well. I use &lt;a href=&#34;https://joaotavora.github.io/yasnippet/&#34;&gt;the
yasnippet extension&lt;/a&gt; to insert
templates for these. I’ll leave the details for another post.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;what-about-r&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;What about R?&lt;/h1&gt;
&lt;p&gt;You can run &lt;a href=&#34;https://www.r-project.org/&#34;&gt;R&lt;/a&gt; scripts in batch mode on a
server just like any other script. But you might want to run an interactive
process for exploring the results of your scripts. I do this by passing the
output from code blocks run on the server to a local instance of R. I’ll
explain that in a future post as well.&lt;/p&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Notes on GPSC Accounts</title>
      <link>https://plantarum.ca/2023/05/02/notes-on-gpsc-accounts/</link>
      <pubDate>Tue, 02 May 2023 00:00:00 +0000</pubDate>
      <author>tyler@plantarum.ca (Tyler Smith)</author>
      <guid>https://plantarum.ca/2023/05/02/notes-on-gpsc-accounts/</guid>
      <description>


&lt;p&gt;Shared Services Canada maintains the General Purpose Science Cluster (GPSC)
high-performance computing cluster. These are my notes for accessing it
from the AAFC network. For more general notes on using &lt;code&gt;orgmode&lt;/code&gt; to manage
cluster work, see &lt;a href=&#34;https://plantarum.ca/2024/03/28/org-cluster&#34;&gt;this post&lt;/a&gt;.&lt;/p&gt;
&lt;div id=&#34;get-the-hostname-from-the-administrators&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Get the hostname from the administrators&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: GPSC no longer uses multi-hop access (at least from AAFC), so you
just need the GPSC hostname to log in. I’m leaving these notes here in
case we switch back at some point.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Multi-hop access from inside your department network requires logging into
your ‘local’ cluster (&lt;code&gt;&amp;lt;LOCAL HOSTNAME&amp;gt;&lt;/code&gt;), and then logging into GPSC
(&lt;code&gt;&amp;lt;GPSC HOSTNAME&amp;gt;&lt;/code&gt;) from there. You’ll need to get the actual hostnames for
these from the cluster administrator.&lt;/p&gt;
&lt;ol style=&#34;list-style-type: decimal&#34;&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ssh&lt;/code&gt; into your local cluster using your GPSC username (not the same as
your AAFC network user ID) and password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;from your local cluster, &lt;code&gt;ssh&lt;/code&gt; into the GPSC with the same credentials.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div id=&#34;configure-keys-and-addresses&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Configure keys and addresses&lt;/h1&gt;
&lt;p&gt;Use an RSA key for password-free logins, as I described in my &lt;a href=&#34;https://plantarum.ca/2014/08/19/medium-performance-cluster-computing#security&#34;&gt;tutorial on
Digital Ocean
droplets&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I’ll never rember the hostnames, so I’ve added the following to
&lt;code&gt;~/.ssh/config&lt;/code&gt; on my laptop (Linux; should work the same on Mac(?),
Windows users will have to configure their &lt;code&gt;ssh&lt;/code&gt; client as needed):&lt;/p&gt;
&lt;pre class=&#34;bash&#34;&gt;&lt;code&gt;Host gpsc
    Hostname &amp;lt;GPSC HOSTNAME&amp;gt;
    User &amp;lt;USERNAME&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This allows me to sign in to &lt;code&gt;&amp;lt;GPSC HOSTNAME&amp;gt;&lt;/code&gt; via &lt;code&gt;ssh gpsc&lt;/code&gt; without
remembering the actual address, username or password. This also works for
transferring files via &lt;code&gt;rsync&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&#34;bash&#34;&gt;&lt;code&gt;rsync &amp;lt;LOCAL&amp;gt; gpsc:&amp;lt;PATH&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, &lt;code&gt;&amp;lt;LOCAL&amp;gt;&lt;/code&gt; can be a file (e.g., &lt;code&gt;my_script.sh&lt;/code&gt;), or a directory (e.g.,
&lt;code&gt;my-folder&lt;/code&gt;), and &lt;code&gt;&amp;lt;PATH&amp;gt;&lt;/code&gt; is the location to transfer to on gpsc. Leaving
&lt;code&gt;&amp;lt;PATH&lt;/code&gt; blank will transfer your file or directory to your home directory
on &lt;code&gt;gpsc&lt;/code&gt;.&lt;/p&gt;
&lt;!-- I also added first stanza to `~/.ssh/config` on `&lt;LOCAL HOSTNAME&gt;`. --&gt;
&lt;!-- ~~Together with the RSA key, this allows me to sign in to `&lt;LOCAL --&gt;
&lt;!-- HOSTNAME&gt;` via `ssh aafc-gpsc`, and from there into the GPSC via `ssh gpsc`, --&gt;
&lt;!-- without remembering the actual hostnames or password.~~ --&gt;
&lt;!-- ~~To further streamline this, I&#39;ve added the following alias on my laptop (in --&gt;
&lt;!-- `~/.bash_aliases`): --&gt;
&lt;!-- ```{bash, eval = FALSE} --&gt;
&lt;!-- alias gpsc=&#39;ssh -t aafc-gpsc ssh gpsc&#39; --&gt;
&lt;!-- ``` --&gt;
&lt;!-- With this set, from a terminal I can login to GPSC directly via `gpsc`. --&gt;
&lt;!-- We have similar issues with `rsync`: to transfer files to and from `gpsc`, we --&gt;
&lt;!-- need to pass them through `aafc-gpsc`. We can accomplish this in a single --&gt;
&lt;!-- step via: --&gt;
&lt;!-- ```{bash, eval = FALSE} --&gt;
&lt;!-- rsync -av -e &#34;ssh -A -t USERNAME@aafc-gpsc ssh -A -t USERNAME@gpsc&#34; SOURCE :DEST --&gt;
&lt;!-- ``` --&gt;
&lt;!-- This will sync `SOURCE` from the local file to `DEST` on `gpsc`, passing --&gt;
&lt;!-- through `aafc-gpsc` (and with the *a*rchival and *v*erbose flags). Note --&gt;
&lt;!-- that we need to use the `:` to indicate which file is on the remote --&gt;
&lt;!-- machine. --&gt;
&lt;!-- Another alias will make this easier: --&gt;
&lt;!-- ```{bash, eval = FALSE} --&gt;
&lt;!-- alias rs2gpsc=&#39;rsync -av -e &#34;ssh -A -t USERNAME@aafc-gpsc ssh -A -t USERNAME@gpsc&#34;&#39; --&gt;
&lt;!-- ``` --&gt;
&lt;!-- With this installed, we can send to `gpsc` with: --&gt;
&lt;!-- ```{bash, eval = FALSE} --&gt;
&lt;!-- rs2gpsc LOCALFILE :REMOTE-PATH --&gt;
&lt;!-- ``` --&gt;
&lt;!-- and retrieve files with: --&gt;
&lt;!-- ```{bash, eval = FALSE} --&gt;
&lt;!-- rs2gpsc :REMOTE-FILE LOCAL-PATH --&gt;
&lt;!-- ``` --&gt;
&lt;!-- Note the `:` in the second example indicating we&#39;re transfering *from* --&gt;
&lt;!-- `gpsc` to our local machine. --&gt;
&lt;/div&gt;
&lt;div id=&#34;prepare-slurm-submission-scripts&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Prepare slurm submission scripts&lt;/h1&gt;
&lt;p&gt;The template for submitting jobs is:&lt;/p&gt;
&lt;pre class=&#34;bash&#34;&gt;&lt;code&gt;#!/bin/bash -l
#SBATCH --job-name=JOB_NAME
#SBATCH --open-mode=append
#SBATCH --partition=standard
#SBATCH --time=1:00:00
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
####SBATCH --mem-per-cpu=1G
#SBATCH --comment=&amp;quot;&amp;lt;SUBMIT_COMMENT&amp;gt;&amp;quot;
#SBATCH --account=&amp;lt;ACCOUNT_NAME&amp;gt;

echo hello
sleep 45
echo goodbye&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that you’ll need to include your actual &lt;SUBMIT_COMMENT&gt; and &lt;ACCOUNT_NAME&gt;
as provided by the administrators.&lt;/p&gt;
&lt;p&gt;With the above template saved to a file named &lt;code&gt;slurm_script.sh&lt;/code&gt;, you can
run it from the cluster via &lt;code&gt;sbatch slurm_script.sh&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Be sure to update the &lt;code&gt;job-name&lt;/code&gt; option to something informative, and of
course increase the &lt;code&gt;time&lt;/code&gt;, &lt;code&gt;ntasks&lt;/code&gt;, and &lt;code&gt;cpus-per-task&lt;/code&gt; to something
appropriate for your job.&lt;/p&gt;
&lt;p&gt;Note that on GPSC, &lt;code&gt;mem-per-cpu&lt;/code&gt; isn’t required. That’s why I’ve commented
it out in the script above (notice the extra &lt;code&gt;###&lt;/code&gt;). The system will
automatically divide RAM among CPUs, which usually works fine. If your job
runs out of memory, you can uncomment this line and ask for a specific
(higher) amount.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;configure-emacs&#34; class=&#34;section level1&#34;&gt;
&lt;h1&gt;Configure Emacs&lt;/h1&gt;
&lt;!-- ## Multihops on Tramp --&gt;
&lt;!-- For Emacs users, we can streamline our workflow by configuring --&gt;
&lt;!-- [TRAMP](https://www.gnu.org/software/tramp/) to use multi-hops. Add the --&gt;
&lt;!-- following to your config (usually `.emacs`, or `.emacs.d/init.el`; TRAMP is --&gt;
&lt;!-- installed with Emacs, no additional packages required): --&gt;
&lt;!-- ```{lisp, eval = FALSE} --&gt;
&lt;!-- (add-to-list &#39;tramp-default-proxies-alist  --&gt;
&lt;!--              &#39;(&#34;gpsc&#34;  --&gt;
&lt;!--                nil  --&gt;
&lt;!--                &#34;/ssh:USERNAME@&lt;LOCAL HOSTNAME&gt;:&#34;)) --&gt;
&lt;!-- ``` --&gt;
&lt;p&gt;You can open files on GPSC in Emacs on your local machine via: &lt;code&gt;C-x C-f /ssh:gpsc:FILENAME&lt;/code&gt;.&lt;/p&gt;
&lt;div id=&#34;execute-code-blocks-with-org-and-babel&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Execute code blocks with Org and Babel&lt;/h2&gt;
&lt;p&gt;You can use &lt;a href=&#34;https://orgmode.org/&#34;&gt;orgmode&lt;/a&gt; to run code blocks from a file
on your local machine on &lt;code&gt;GPSC&lt;/code&gt;. To do this, use a header like this in your
local &lt;code&gt;.org&lt;/code&gt; file (which assumes you’ve set up your &lt;code&gt;.ssh/config&lt;/code&gt; files as
described above):&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+PROPERTY: header-args:bash :results output :dir /ssh:gpsc:./path/to/working/directory&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I ran into transient permission issues executing code blocks. I’ve fixed
this by configuring &lt;code&gt;org-babel&lt;/code&gt; to use my home directory for temp files. It
seems to have problems writing to &lt;code&gt;/tmp&lt;/code&gt; on GPSC, although I should have
permission to do so? Here’s the code from my emacs &lt;code&gt;init.el&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&#34;elisp&#34;&gt;&lt;code&gt;(setq org-babel-remote-temporary-directory &amp;quot;~/&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So far the temp files &lt;code&gt;babel&lt;/code&gt; generates are cleaned up automatically, so
this hasn’t created any detritus. You could use a subdirectory under &lt;code&gt;~/&lt;/code&gt;,
but the directory must exist (i.e., you need to create it yourself) before
&lt;code&gt;org&lt;/code&gt; can find it - it won’t make it for you.&lt;/p&gt;
&lt;p&gt;With this done, you can submit code blocks from your org file directly to
&lt;code&gt;slurm&lt;/code&gt; on &lt;code&gt;GPSC&lt;/code&gt;. Here’s my template:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+BEGIN_SRC bash :results output
  sbatch &amp;lt;&amp;lt;SUBMITSCRIPT
  #!/bin/bash
  #SBATCH --job-name=slurm_test_emacs
  #SBATCH --output=slurm_test_emacs.log
  #SBATCH --open-mode=append
  #SBATCH --partition=standard
  #SBATCH --time=0:01:00
  #SBATCH --ntasks=1
  #SBATCH --cpus-per-task=1
  ####SBATCH --mem-per-cpu=1G
  #SBATCH --comment=&amp;quot;&amp;lt;SUBMIT_COMMENT&amp;gt;&amp;quot;
  #SBATCH --account=&amp;lt;ACCOUNT_NAME&amp;gt;

  date
  echo
  echo hello
  echo

  SUBMITSCRIPT
#+END_SRC&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Everything between &lt;code&gt;&amp;lt;&amp;lt;SUBMITSCRIPT&lt;/code&gt; and &lt;code&gt;SUBMITSCRIPT&lt;/code&gt; will get passed to
&lt;code&gt;sbatch&lt;/code&gt; as if it were a separate script file.&lt;/p&gt;
&lt;p&gt;If you do use this approach, note that you must &lt;strong&gt;escape any variables!&lt;/strong&gt;
(e.g., &lt;code&gt;\$VAR&lt;/code&gt;). This won’t work:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+BEGIN_SRC bash :results output
  sbatch &amp;lt;&amp;lt;SUBMITSCRIPT
  #!/bin/bash
  #SBATCH --job-name=bad_HEREDOC
  &amp;lt;...&amp;gt;

  NAME=TYLER
  echo $NAME

  SUBMITSCRIPT
#+END_SRC&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But this will (note the &lt;strong&gt;backslash&lt;/strong&gt; in front of the &lt;code&gt;$&lt;/code&gt;):&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+BEGIN_SRC bash :results output
  sbatch &amp;lt;&amp;lt;SUBMITSCRIPT
  #!/bin/bash
  #SBATCH --job-name=good_HEREDOC
  &amp;lt;...&amp;gt;

  NAME=TYLER
  echo \$NAME

  SUBMITSCRIPT
#+END_SRC&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A further wrinkle: this uses a
&lt;a href=&#34;https://phoenixnap.com/kb/bash-heredoc&#34;&gt;heredoc&lt;/a&gt;, and heredocs need to
write a temp file. By defaul this goes in &lt;code&gt;/tmp&lt;/code&gt;, and in some cases &lt;code&gt;/tmp&lt;/code&gt;
may be full. If that happens, you’ll get an error&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cannot create temp file for here-document: No space left on device&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All users can write to &lt;code&gt;/tmp&lt;/code&gt;, so you can’t fix this yourself. You can
change the location where your heredoc gets written, though:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+BEGIN_SRC bash :results output
  export TMPDIR=/path/to/your/personal/tmp/directory
  sbatch &amp;lt;&amp;lt;SUBMITSCRIPT
  #!/bin/bash
  #SBATCH --job-name=good_HEREDOC
  &amp;lt;...&amp;gt;

  NAME=TYLER
  echo \$NAME

  SUBMITSCRIPT
#+END_SRC&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You may set this permanently by adding the &lt;code&gt;export TMPDIR=...&lt;/code&gt; line to your
&lt;code&gt;.bashrc&lt;/code&gt; on GPSC.&lt;/p&gt;
&lt;p&gt;Once a job is submitted, the ID will appear in your local &lt;code&gt;.org&lt;/code&gt; file,
e.g.:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+RESULTS:
: Submitted batch job 1385545&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can retrieve info on the run with:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+BEGIN_SRC bash :results output 
sacct --jobs=1385545 --format=jobid,jobname,state,elapsed,MaxRSS
#+END_SRC&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In my case, this generated:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+RESULTS:
: JobID           JobName      State    Elapsed     MaxRSS 
: ------------ ---------- ---------- ---------- ---------- 
: 1385545      slurm_tes+  COMPLETED   00:00:07 
: 1385545.bat+      batch  COMPLETED   00:00:07      2096K 
: 1385545.ext+     extern  COMPLETED   00:00:07      2088K &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use the &lt;code&gt;format&lt;/code&gt; argument to request which details to report. &lt;code&gt;MaxRSS&lt;/code&gt; is
the maximum amount of RAM used during the run. Other options are available
via &lt;code&gt;sacct --helpformat&lt;/code&gt;, with more details in the &lt;a href=&#34;https://slurm.schedmd.com/sacct.html&#34;&gt;slurm
manual&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Note that GPSC doesn’t provide the
&lt;a href=&#34;https://docs.alliancecan.ca/wiki/Running_jobs#Completed_jobs&#34;&gt;seff&lt;/a&gt;
command, which you may have used on other clusters.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;linking-to-files-on-the-remote-server&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Linking to files on the remote server&lt;/h2&gt;
&lt;p&gt;It may be more convenient to manage more complex scripts as stand-alone
&lt;code&gt;.sh&lt;/code&gt; files on the GPSC. If the configuration above works for you, you can
insert a link to remote files in your &lt;code&gt;org&lt;/code&gt; file with the syntax:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[[file:/ssh:gpsc:~/path/to/script.sh][My Script]]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will create a ‘hotlink’ in your file you can click to open that file
in your local Emacs. The default keyboard shortcut for entering links is
&lt;code&gt;C-c C-l&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That will allow you to edit the remote file as if it were local. When
you’re ready to submit it, you can do that from your local &lt;code&gt;.org&lt;/code&gt; file:&lt;/p&gt;
&lt;pre class=&#34;org&#34;&gt;&lt;code&gt;#+BEGIN_SRC bash :results output
sbatch script.sh
#+end_src&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the location of your script will be relative to the directory you
listed in your file header.&lt;/p&gt;
&lt;p&gt;I also use org links for data files I might need to refer to or edit (i.e.,
sample indices), and files generated by the jobs themselves.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Notes on Compute Canada Accounts</title>
      <link>https://plantarum.ca/2020/09/21/notes-on-compute-canada-accounts/</link>
      <pubDate>Mon, 21 Sep 2020 00:00:00 +0000</pubDate>
      <author>tyler@plantarum.ca (Tyler Smith)</author>
      <guid>https://plantarum.ca/2020/09/21/notes-on-compute-canada-accounts/</guid>
      <description>&lt;p&gt;I renewed my account with &lt;a href=&#34;https://www.computecanada.ca&#34;&gt;ComputeCanada&lt;/a&gt;, which is available for all Canadian University researchers (professors and adjuncts), and students and postdocs they work with. Here are a few notes that might be handy later.&lt;/p&gt;
&lt;h1 id=&#34;accounts&#34;&gt;Accounts&lt;/h1&gt;
&lt;p&gt;Sign up for an &lt;a href=&#34;https://www.computecanada.ca/research-portal/account-management/apply-for-an-account/&#34;&gt;account&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This will get you access to the &lt;a href=&#34;https://docs.computecanada.ca/wiki/Getting_started#What_resources_are_available.3F&#34;&gt;clusters&lt;/a&gt;&lt;/p&gt;
&lt;h1 id=&#34;login&#34;&gt;Login&lt;/h1&gt;
&lt;p&gt;Login with &lt;code&gt;ssh&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ssh username@beluga.computecanada.ca
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Use the same password as the one for your Compute Canada account here.&lt;/p&gt;
&lt;p&gt;You can use &lt;a href=&#34;https://docs.computecanada.ca/wiki/Using_SSH_keys_in_Linux&#34;&gt;SSH keys&lt;/a&gt; to login without a password. After you&amp;rsquo;ve followed the instructions at that link, you won&amp;rsquo;t have to use your password anymore.&lt;/p&gt;
&lt;p&gt;For a little extra convenience, especially if you use multiple servers with different keys and usernames, add your details to &lt;code&gt;.ssh/config&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Host beluga
     HostName beluga.computecanada.ca
     User username
     IdentityFile ~/.ssh/my_rsa_key
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This will allow me to login to the &lt;code&gt;beluga.computecanada.ca&lt;/code&gt; cluster as user &lt;code&gt;username&lt;/code&gt;, using the private key &lt;code&gt;~/.ssh/my_rsa_key&lt;/code&gt;, with just the following command (and no password):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ssh beluga
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This also allows me to open files on the cluster directly from my local Emacs instance:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;M-x find-file
/ssh:beluga:~/path/to/file/on/beluga
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&#34;working-with-r&#34;&gt;Working with R&lt;/h1&gt;
&lt;h2 id=&#34;modules&#34;&gt;Modules&lt;/h2&gt;
&lt;p&gt;After a long day spent diving through dependencies, I found the following
minimal set of modules necessary to install the packages used our GBS
analysis:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;module load nixpkgs/16.09 gcc/7.3.0 gdal/3.0.1 udunits/2.2.26 proj4-fortran/1.0 proj/6.3.0 r/4.0.2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You run this command (on a single line) at the terminal after logging into
the cluster. After you&amp;rsquo;ve loaded the modules, you can save the collection
for future sessions with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;module save r_modules
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;On our next, and all subsequent sessions, we can load R into an interactive
session via:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;module restore r_modules
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that you may need to add additional modules to support new packages
you install. Sometimes &lt;code&gt;install.packages&lt;/code&gt; will give you an informative
error message. Sometimes you&amp;rsquo;re not so lucky. Check to see which actual
package causes the error (i.e., the one you&amp;rsquo;re installing, or one of its
dependencies), and check the source repository for the problematic package
for additional clues.&lt;/p&gt;
&lt;h2 id=&#34;shared-r-library&#34;&gt;Shared R library&lt;/h2&gt;
&lt;p&gt;I set up a shared drive for everyone in the lab to use. This will save a
lot of time, as installing packages from source on Linux can take a while.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mkdir $HOME/projects/def-tsmith/lab
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;setfacl -d -m g::rwx $HOME/projects/def-tsmith/lab
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;def-tsmith&lt;/code&gt; is my group name, if you don&amp;rsquo;t work with me you&amp;rsquo;ll need to use
your supervisor&amp;rsquo;s project name instead.&lt;/p&gt;
&lt;p&gt;To access this library, &lt;strong&gt;after&lt;/strong&gt; you have loaded the &lt;code&gt;R&lt;/code&gt; modules, execute
the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;export R_LIBS=~/projects/def-tsmith/lab/R/x86_64-pc-linux-gnu-library/${EBVERSIONR%.*}/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;EBVERSIONR&lt;/code&gt; is the version of R installed, including the bugfix release
number (e.g., 4.0.2). We only use the major.minor numbers for the library
directories (4.0), so I&amp;rsquo;ve trimmed off the last number via &lt;a href=&#34;https://tldp.org/LDP/abs/html/parameter-substitution.html&#34;&gt;parameter substitution&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After you&amp;rsquo;ve done this, you can start R in an interactive session via &lt;code&gt;R&lt;/code&gt;.
You&amp;rsquo;ll have access to all the packages I&amp;rsquo;ve already installed, and any new
packages will be installed into the same shared library.&lt;/p&gt;
&lt;h2 id=&#34;jobs&#34;&gt;Jobs&lt;/h2&gt;
&lt;p&gt;To load the modules and access the shared library from your scripts, use
the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/bin/bash
##
##SBATCH settings for the job
##...

module restore r_modules
export R_LIBS=~/projects/def-tsmith/lab/R/x86_64-pc-linux-gnu-library/${EBVERSIONR%.*}/

## &#39;computation.R&#39; contains the code you want to run:
Rscript computation.R
&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
    <item>
      <title>Medium Performance Cluster Computing</title>
      <link>https://plantarum.ca/2014/08/19/medium-performance-cluster-computing/</link>
      <pubDate>Tue, 19 Aug 2014 00:00:00 +0000</pubDate>
      <author>tyler@plantarum.ca (Tyler Smith)</author>
      <guid>https://plantarum.ca/2014/08/19/medium-performance-cluster-computing/</guid>
      <description>&lt;p&gt;I recently ran into a crunch getting some memory-intensive GIS analysis
completed. My work laptop has 2 CPUs and 4GB RAM, and running one instance
of the &lt;a href=&#34;http://grass.osgeo.org&#34;&gt;GRASS GIS&lt;/a&gt; &lt;code&gt;r.horizon&lt;/code&gt; command on a 16GB
map was gobbling up 8GB of virtual RAM, which temporarily ground my machine
to a crawl before the process was killed.&lt;/p&gt;
&lt;p&gt;GRASS is not yet installed on the high performance cluster at work, so I
decided to try setting up my own &lt;em&gt;medium&lt;/em&gt; performance cluster on a
&lt;a href=&#34;https://www.digitalocean.com/?refcode=0c9c59e00cc0&#34;&gt;Digital Ocean&lt;/a&gt;&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; VPS
(which they refer to as &amp;lsquo;droplets&amp;rsquo;).&lt;/p&gt;
&lt;h1 id=&#34;why&#34;&gt;Why?&lt;/h1&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;strong&gt;Price&lt;/strong&gt;&lt;/dt&gt;
&lt;dd&gt;Not only are their prices competitively low, they charge &lt;em&gt;by the hour&lt;/em&gt;.
This means you can have your own virtual machine with 64GB RAM and 20
CPUs for less than $1/hour. What&amp;rsquo;s more, the minimum period is one hour.
Meaning, in theory, you could spin up a droplet, get 20 hours of
processing done, and then shut it all down again with no further
commitment.&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;Quick &amp;amp; Easy Installation&lt;/strong&gt;&lt;/dt&gt;
&lt;dd&gt;They offer a variety of GNU/Linux distributions, and once you&amp;rsquo;ve chosen
you&amp;rsquo;ll be able to log on to your VPS in 60 seconds. This assumes you&amp;rsquo;re
comfortable working on the command line. But if you&amp;rsquo;re doing cluster
computing, if that&amp;rsquo;s not already true you&amp;rsquo;ll need to learn anyways.&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;No Queues&lt;/strong&gt;&lt;/dt&gt;
&lt;dd&gt;No need to worry about submitting batch jobs to a queue or waiting your
turn. It&amp;rsquo;s your VPS, not shared with anyone else.&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;Reuse Your Installation&lt;/strong&gt;&lt;/dt&gt;
&lt;dd&gt;You pay for the time your droplet is available. However, you can save a
&amp;lsquo;snapshot&amp;rsquo;, which is stored in your account. This allows you to destroy
your droplet when you don&amp;rsquo;t need it. Then, simply reload it from the saved
snapshot when you next need to crunch some numbers.&lt;/dd&gt;
&lt;dt&gt;&lt;strong&gt;Nerdy fun&lt;/strong&gt;&lt;/dt&gt;
&lt;dd&gt;I have to admit, I was motivated in part by sheer, unbridled nerdy
curiosity. Who wouldn&amp;rsquo;t want to ssh in to their very own server?&lt;/dd&gt;
&lt;/dl&gt;
&lt;h1 id=&#34;why-not&#34;&gt;Why not?&lt;/h1&gt;
&lt;p&gt;This won&amp;rsquo;t be a practical solution in all cases. The longer your job will
take to run, the more practical a real cluster becomes. It&amp;rsquo;s also worth
noting that the CPUs aren&amp;rsquo;t particularly high-powered. So processes won&amp;rsquo;t
run faster than on a recent laptop, assuming memory isn&amp;rsquo;t limiting. Another
thing to consider is how much data you have to upload. This is not a viable
approach for true &amp;lsquo;big data&amp;rsquo; projects! Sending gigabytes over the open
internet can be a very slow process, which is another point in favour of
using a local HPC cluster.&lt;/p&gt;
&lt;h1 id=&#34;how-to&#34;&gt;How-To&lt;/h1&gt;
&lt;p&gt;With that in mind, here&amp;rsquo;s how I set up my temporary cluster:&lt;/p&gt;
&lt;h2 id=&#34;purchase-the-droplet&#34;&gt;Purchase the droplet&lt;/h2&gt;
&lt;p&gt;Browse over to &lt;a href=&#34;https://digitalocean.com&#34;&gt;Digital Ocean&lt;/a&gt; and sign up. Once
you&amp;rsquo;re logged in, click &amp;lsquo;create&amp;rsquo; and fill in your details:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hostname: it&amp;rsquo;s your server, call it what you like&lt;/li&gt;
&lt;li&gt;Size: they offer everything from 512MB/1 CPU up to 64GB/20 CPUs, with
prices varying accordingly. From my project I selected 32GB/12 CPUs for
$0.476/hour&lt;/li&gt;
&lt;li&gt;Region: pick something close, particularly if you&amp;rsquo;ll be up/downloading a
lot of data. In my case, that&amp;rsquo;s New York.&lt;/li&gt;
&lt;li&gt;Linux Distribution: Choices include Ubuntu, Fedora, Debian, CentOS. I
picked Debian, as that&amp;rsquo;s been my OS for the past decade. Regardless of
the distribution, if you&amp;rsquo;re going to be working with large files, you
will definitely want to select the 64bit version of your OS.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;security&#34;&gt;Security&lt;/h2&gt;
&lt;p&gt;Your root password and dedicated IP address will be emailed to you. Which
means the NSA will know it before you do. So immediately log in and change
your password. Actually, as soon as you log in you will be required to
change your password in any case.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ssh root@123.45.67.89
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You&amp;rsquo;ll probably also want a regular-strength user for non-administrative
work, so add that next:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;adduser tyler
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;At this point, you can log in as root or as your regular user. A more
secure option is to authenticate via rsa keys. If you haven&amp;rsquo;t done this
before, generate the key on your laptop/local computer:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ssh-keygen -t rsa
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note that you can use a blank passphrase here. Doing so will allow you to
log in to the server without entering a password from now on. It also means
that anyone that has physical access to your laptop also be able to log in
to the server without a password. If you&amp;rsquo;ve lost control of your laptop,
this is likely the least of your worries.&lt;/p&gt;
&lt;p&gt;Next, transfer the key to the server:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ssh-copy-id tyler@123.45.67.89
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You&amp;rsquo;ll be asked for your password again here. Now try logging into the
server again:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ssh tyler@123.45.67.89
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If everything is working correctly, you should be logged in to your droplet
without entering a password. If that is the case, we can proceed to shore
up our security. &lt;code&gt;su&lt;/code&gt; to root user, and edit the ssh config files:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;su
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;nano /etc/ssh/sshd_config
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Look for and modify the following lines, then save the file. You need to
remove the comment character (&lt;code&gt;#&lt;/code&gt;)from the beginning of the line, if it&amp;rsquo;s
there, and make sure they say &amp;rsquo;no&amp;rsquo;, not &amp;lsquo;yes&amp;rsquo;. You don&amp;rsquo;t need to modify any
other lines.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;PermitRootLogin no
PasswordAuthentication no
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The second line will prevent anyone from logging in using a password -
you&amp;rsquo;ll only be able to login if you have the correct RSA key on your
computer. This prevents ne&amp;rsquo;er-do-wells from trying to crack your password.&lt;/p&gt;
&lt;p&gt;The first line will prevent anyone (including you!) from logging in
directly as root. Meaning a potential cracker will have to get your RSA key
in order to log on to the machine, and then they&amp;rsquo;ll have to crack the root
password in order to do anything really nasty.&lt;/p&gt;
&lt;p&gt;Note that if you want to access the server from another computer, you&amp;rsquo;ll
have to log in from each computer via password, or at least &lt;code&gt;ssh-copy-id&lt;/code&gt;
the RSA key, before your set &lt;code&gt;PasswordAuthentication no&lt;/code&gt;. Or, afterwards,
simply set it back to &lt;code&gt;PasswordAuthentication yes&lt;/code&gt; briefly from the first
computer long enough for the second computer to log on and &lt;code&gt;ssh-copy-id&lt;/code&gt;
their RSA key.&lt;/p&gt;
&lt;p&gt;One final configuration detail: if you&amp;rsquo;re going to use an X server (to view
graphical windows of any kind), you need to modify &lt;code&gt;/etc/ssh/ssh_config&lt;/code&gt;.
Make sure it includes the following uncommented line:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ForwardX11 yes
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now you need to reload the modified configuration. Still as root:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;/etc/init.d/ssh reload
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Given that we won&amp;rsquo;t have any outward facing servers on this machine, that
should do for our security for now. If you do want to put some servers on
here, you&amp;rsquo;ll definitely want to look into getting at least a firewall, and
probably some intrusion detection software on here. The DigitalOcean
tutorials are quite good in this area.&lt;/p&gt;
&lt;h2 id=&#34;install-software&#34;&gt;Install Software&lt;/h2&gt;
&lt;p&gt;Now that we have a passably secured machine, it&amp;rsquo;s time to install the
software you&amp;rsquo;ll want. Given this is Debian:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;run &lt;code&gt;aptitude&lt;/code&gt; as root&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;u&lt;/strong&gt;pdate&lt;/li&gt;
&lt;li&gt;install any security updates&lt;/li&gt;
&lt;li&gt;select and install your desired programs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In my case, to run GRASS, I needed the following:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;aptitude install grass emacs screen htop avce00 &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  e00compr git mercurial xorg
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;(yes, you can run &lt;code&gt;aptitude&lt;/code&gt; from the command line just like &lt;code&gt;apt-get&lt;/code&gt; if
you like!)&lt;/p&gt;
&lt;h2 id=&#34;setup-grass&#34;&gt;Setup GRASS&lt;/h2&gt;
&lt;p&gt;GRASS will require you to create your database directory on the server
(&lt;strong&gt;not&lt;/strong&gt; as root!):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mkdir ~/grassdata
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Next you need to transfer any files you need from your &lt;em&gt;local&lt;/em&gt; machine:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;rsync -az --progress --compresslevel&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;9&lt;/span&gt; --partial &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  grassdata/location tyler@123.45.67.89:grassdata/
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The options here include &lt;strong&gt;a&lt;/strong&gt;, which among other things will transfer
directories recursively, &lt;strong&gt;z&lt;/strong&gt;, which will compress files prior to transfer
(which dramatically reduces upload times), &lt;strong&gt;compresslevel=9&lt;/strong&gt;, which uses
the greatest amount of compression, and &lt;strong&gt;partial&lt;/strong&gt; which allows rsync to
pick up where it left off in case the connection is interrupted.&lt;/p&gt;
&lt;h2 id=&#34;running-grass-inside-screen&#34;&gt;Running GRASS Inside Screen&lt;/h2&gt;
&lt;p&gt;Finally, we begin. Now we&amp;rsquo;re ready to use X windows, so when you log back
in you&amp;rsquo;ll want to use the &lt;strong&gt;X&lt;/strong&gt; and &lt;strong&gt;C&lt;/strong&gt; flags to &lt;code&gt;ssh&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ssh -XC tyler@123.45.67.89
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;After logging back into your server, run &lt;code&gt;screen&lt;/code&gt;. You&amp;rsquo;ll be transported
from a regular terminal window into a &lt;code&gt;screen&lt;/code&gt; window. It will look almost
exactly the same. But it gives you some super powers, as we&amp;rsquo;ll see shortly.&lt;/p&gt;
&lt;p&gt;Next, start GRASS. In order to conveniently run multiple processes at once,
I prefer to use text mode, hence I start with: &lt;code&gt;grass -text&lt;/code&gt;. Navigate
through the charmingly archaic text windows until you&amp;rsquo;re at the familiar
GRASS text prompt.&lt;/p&gt;
&lt;p&gt;One very helpful thing I discovered about GRASS is that each command is
really a stand-alone program. Which has the lovely side-effect of giving us
quick access to parallel programming. So long as any command &lt;em&gt;foo&lt;/em&gt; does not
require the output of command &lt;em&gt;bar&lt;/em&gt; to run, and vice versa, you can run them
both concurrently. Which means, in my case, I can do things like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;r.slope.aspect elevin&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;dem slope&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;myslope aspect&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;myaspect &amp;amp;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;r.horizon elevin&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;elevation horizonstep&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    bufferzone&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;200&lt;/span&gt; horizon&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;horangle &lt;span style=&#34;color:#ae81ff&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    maxdistance&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2000&lt;/span&gt; &amp;amp;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You might find yourself getting carried away, starting process after
process. You might want to check on the load your server is under, before
you max out your RAM or CPUs. Here is where &lt;code&gt;screen&lt;/code&gt; comes in handy.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://plantarum.ca/images/htop-screen.png&#34; alt=&#34;screen, with GRASS running in the top window and htop in the bottom&#34;&gt;&lt;/p&gt;
&lt;p&gt;Type &lt;code&gt;Ctrl-a c&lt;/code&gt;, and you&amp;rsquo;ll have a new terminal window to work in.
Your GRASS session is still working away in the background, and you can
check on how many processes you&amp;rsquo;ve spun out by calling &lt;code&gt;htop&lt;/code&gt;. To go back
to the GRASS session, &lt;code&gt;Ctrl-a &amp;quot;&lt;/code&gt; brings up a list of all the windows
available inside your &lt;code&gt;screen&lt;/code&gt; instance, which you can select from with the
arrow keys.&lt;/p&gt;
&lt;p&gt;Finally, you may need to shut down your laptop at some point while the
GRASS session is still running. To do this, we &lt;em&gt;detach&lt;/em&gt; the &lt;code&gt;screen&lt;/code&gt;
session, with &lt;code&gt;Ctrl-a d&lt;/code&gt;. This tucks the session away out of sight, but it
continues to run. It will continue to run even after we log out of the
server. When you want to reconnect to the session, simply enter &lt;code&gt;screen -r&lt;/code&gt;
at the command line and you&amp;rsquo;re back in charge.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;screen&lt;/code&gt; can do a lot more than this, check out the docs for details!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&#34;goodbye-but-not-farewell&#34;&gt;Goodbye, but not Farewell&lt;/h1&gt;
&lt;p&gt;When you&amp;rsquo;ve completed all the work you need to do, you can save a snapshot
of your server to use later on. Log in to your Digital Ocean account,
select your droplet, and follow the links to create a snapshot. Once that&amp;rsquo;s
done, you can safely destroy the droplet. A destroyed droplet will no
longer accrue charges (and obviously it won&amp;rsquo;t be doing any processing
either). To reinstate your droplet, follow the same steps you used above to
create a droplet, but instead of selecting a Linux Distribution, select
your snapshot from the &lt;em&gt;My Images&lt;/em&gt; tab.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Comments or questions? Ping me on &lt;a href=&#34;https://ottawa.place/@plantarum&#34;&gt;mastodon&lt;/a&gt;,
or send me an email (address in sidebar)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Full disclaimer: this link uses my referral code, so if you sign up through here I&amp;rsquo;ll get a small kick-back from Digital Ocean. I hope this won&amp;rsquo;t lower your confidence in what some random guy on the internet has written.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item>
    
  </channel>
</rss>
