Jekyll2023-04-23T02:40:12+00:00/feed.xmlRichard BergerHigh-Performance Computing Specialist, Research Software Engineer, MechatronicNew Position at LANL2022-03-26T11:52:00+00:002022-03-26T11:52:00+00:00/blog/lanl/2022/03/26/new-position<p>After many good years at Temple University, it was time for me to move on and
look for new challenges.</p>
<p>On February 22, 2022 I started at Los Alamos National Lab as Scientist to work
on a new generation of HPC C++ codes such as <a href="https://flecsi.github.io/flecsi/">FleCSI</a>
and DevOps in various other projects.</p>After many good years at Temple University, it was time for me to move on and look for new challenges.LAMMPS Virtual Workshop and Symposium 20212021-09-02T18:54:00+00:002021-09-02T18:54:00+00:00/blog/lammps/2021/09/02/lammps-workshop<p>This year, the bi-annual LAMMPS workshop and symposium was held completely
virtual and hosted by Temple University via Zoom.</p>
<p>In total we had more than 700 participants from over 55 countries all over the
world. In case you missed it, here is its website which includes video recordings:</p>
<p><a href="https://www.lammps.org/workshops/Aug21/">https://www.lammps.org/workshops/Aug21/</a></p>
<p><img style="width: 50%" src="/assets/img/lammps-workshop-2021.png" /></p>This year, the bi-annual LAMMPS workshop and symposium was held completely virtual and hosted by Temple University via Zoom.Using LAMMPS on Windows 102020-07-20T21:30:00+00:002020-07-20T21:30:00+00:00/blog/lammps/wsl/2020/07/20/lammps-on-windows-10<p>It’s always been tricky for us to have LAMMPS users and developers work on
Windows. We primarily develop LAMMPS to run on Linux clusters. To teach
LAMMPS in workshop settings, we’ve usually had to redirect Windows users to
Linux Virtual Machines such as VirtualBox or Unix-like compilation with
Cygwin.</p>
<p>With the latest updates in Windows 10 (Version 2004, Build 19041 or higher),
Microsoft has added a new way to work on Linux-based code. The Windows
Subsystem for Linux (WSL). With WSL Version 2, you now get a Linux Virtual
Machine that transparently integrates into Windows. All you need is to ensure
you have the latest Windows updates installed and enable this new feature.
Linux VMs are then easily installed using the Microsoft Store.</p>
<p>In this post, I’ll show you how to set up and compile LAMMPS for both serial
and MPI usage in WSL2.</p>
<h2 id="installation">Installation</h2>
<ol>
<li><a href="#upgrade-to-the-latest-windows-10">Upgrade to the latest Windows 10</a></li>
<li><a href="#enable-wsl">Enable WSL</a></li>
<li><a href="#update-the-wsl-kernel-component">Update the WSL kernel component</a></li>
<li><a href="#set-wsl2-as-default">Set WSL2 as default</a></li>
<li><a href="#install-a-linux-distribution">Install a Linux Distribution</a></li>
</ol>
<h3 id="upgrade-to-the-latest-windows-10">Upgrade to the latest Windows 10</h3>
<p>Type “Updates” in Windows Start and select “Check for Updates”.</p>
<p><img src="/assets/img/lammps/wsl/Updates.png" alt="Check for Updates" /></p>
<p>Install all pending updates and reboot your system as many times as
necessary. Continue until your Windows installation is updated.</p>
<p><img src="/assets/img/lammps/wsl/WindowsUpdate.png" alt="Windows Update" /></p>
<p>Verify your system has at least <strong>version 2004 and build 19041 or later</strong>. You
can find this information by clicking on “OS build info”.</p>
<p><img src="/assets/img/lammps/wsl/osinfo.png" alt="OS Info" /></p>
<h3 id="enable-wsl">Enable WSL</h3>
<p>Next, we must install two additional Windows features to enable WSL support. Open a PowerShell window as an administrator. Type “PowerShell” in Windows Start and select “Run as Administrator”.</p>
<p><img src="/assets/img/lammps/wsl/PowerShell.png" alt="PowerShell" /></p>
<p>Windows will ask you for administrator access. After you accept a new command
line window will appear. Type in the following command to install WSL:</p>
<div class="language-powershell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">dism.exe</span><span class="w"> </span><span class="nx">/online</span><span class="w"> </span><span class="nx">/enable-feature</span><span class="w"> </span><span class="nx">/featurename:Microsoft-Windows-Subsystem-Linux</span><span class="w"> </span><span class="nx">/all</span><span class="w"> </span><span class="nx">/norestart</span><span class="w">
</span></code></pre></div></div>
<p><img src="/assets/img/lammps/wsl/wsl_install1.png" alt="Screenshot of PowerShell Output" /></p>
<p>Next, enable the VirtualMachinePlatform feature using the following command:</p>
<div class="language-powershell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">dism.exe</span><span class="w"> </span><span class="nx">/online</span><span class="w"> </span><span class="nx">/enable-feature</span><span class="w"> </span><span class="nx">/featurename:VirtualMachinePlatform</span><span class="w"> </span><span class="nx">/all</span><span class="w"> </span><span class="nx">/norestart</span><span class="w">
</span></code></pre></div></div>
<p><img src="/assets/img/lammps/wsl/wsl_install2.png" alt="Screenshot of PowerShell Output" /></p>
<p>Finally, reboot your system.</p>
<h3 id="update-wsl-kernel-component">Update WSL kernel component</h3>
<p>Download and install the <a href="https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi">WSL Kernel Component Update</a>. Afterwards, reboot your system.</p>
<h3 id="set-wsl2-as-default">Set WSL2 as default</h3>
<p>Again, open PowerShell as administrator and run the following command:</p>
<div class="language-powershell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">wsl</span><span class="w"> </span><span class="nt">--set-default-version</span><span class="w"> </span><span class="nx">2</span><span class="w">
</span></code></pre></div></div>
<p>This command ensures that all future Linux installations will use WSL version 2.</p>
<p><img src="/assets/img/lammps/wsl/wsl_install3.png" alt="Screenshot of PowerShell Output" /></p>
<h3 id="install-a-linux-distribution">Install a Linux Distribution</h3>
<p>Next, we need to install a Linux distribution via the Microsoft Store.
Install <a href="ms-windows-store://pdp/?ProductId=9n6svws3rx71">Ubuntu 20.04 LTS</a>.
Once installed, you can launch it like any other application from the Start
Menu.</p>
<p><img src="/assets/img/lammps/wsl/UbuntuInStore.png" alt="Ubuntu 20.04 LTS in the Microsoft Store" /></p>
<h3 id="initial-setup">Initial Setup</h3>
<p>The first time you launch the Ubuntu Linux console, it will prompt you for a
UNIX username and password. You will need this password to perform <code class="language-plaintext highlighter-rouge">sudo</code>
commands later. Once completed, your Linux shell is ready for use. All your
actions and commands will run as the Linux user you specified.</p>
<p><img src="/assets/img/lammps/wsl/FirstLogin.png" alt="First Login" /></p>
<h2 id="windows-explorer--wsl-integration">Windows Explorer / WSL integration</h2>
<p>Your Linux installation will have its own Linux filesystem, which contains
the Ubuntu files. Your Linux user will have a regular Linux home directory in
<code class="language-plaintext highlighter-rouge">/home/<USERNAME></code>. This directory is different from your Windows User
directory. Windows and Linux filesystems are connected through WSL.</p>
<p>All hard drives in Windows are accessible in the <code class="language-plaintext highlighter-rouge">/mnt</code> directory in Linux.
E.g., WSL maps the <code class="language-plaintext highlighter-rouge">C:\</code> hard drive to the <code class="language-plaintext highlighter-rouge">/mnt/c</code> directory. That means you
can access your Windows User directory in <code class="language-plaintext highlighter-rouge">/mnt/c/Users/<WINDOWS_USERNAME></code>.</p>
<p>The Windows Explorer can also access the Linux filesystem. To illustrate this
integration, open an Ubuntu console and navigate to a directory of your
choice. To view this location in Windows Explorer, use the <code class="language-plaintext highlighter-rouge">explorer.exe .</code>
command (do not forget the dot!).</p>
<p><img src="/assets/img/lammps/wsl/WSLIntegration.png" alt="WSL Integration" /></p>
<hr />
<h2 id="compiling-lammps">Compiling LAMMPS</h2>
<p>You now have a fully functioning Ubuntu installation and can follow most
guides to install LAMMPS on a Linux system. Here are some of the essential
steps to follow:</p>
<h3 id="install-prerequisite-packages">Install prerequisite packages</h3>
<p>Before we can begin, we need to download the necessary compiler toolchain and
libraries to compile LAMMPS. In our Ubuntu-based Linux installation, we will
use the <code class="language-plaintext highlighter-rouge">apt</code> package manager to install additional packages.</p>
<p>First, upgrade all existing packages using <code class="language-plaintext highlighter-rouge">apt update</code> and <code class="language-plaintext highlighter-rouge">apt upgrade</code>.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt update
<span class="nb">sudo </span>apt upgrade <span class="nt">-y</span>
</code></pre></div></div>
<p>Next, install the following packages with <code class="language-plaintext highlighter-rouge">apt install</code>:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt <span class="nb">install</span> <span class="nt">-y</span> cmake build-essential ccache gfortran openmpi-bin libopenmpi-dev <span class="se">\</span>
libfftw3-dev libjpeg-dev libpng-dev python3-dev python3-pip <span class="se">\</span>
python3-virtualenv libblas-dev liblapack-dev libhdf5-serial-dev <span class="se">\</span>
hdf5-tools
</code></pre></div></div>
<h3 id="download-lammps">Download LAMMPS</h3>
<p>Obtain a copy of the LAMMPS source code and go into it using <code class="language-plaintext highlighter-rouge">cd</code>.</p>
<h4 id="option-1-download-a-lammps-tarball-using-wget">Option 1: Download a LAMMPS tarball using wget</h4>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>wget https://github.com/lammps/lammps/archive/stable_3Mar2020.tar.gz
<span class="nb">tar </span>xvzf stable_3Mar2020.tar.gz
<span class="nb">cd </span>lammps
</code></pre></div></div>
<h4 id="option-2-download-a-lammps-development-version-from-github">Option 2: Download a LAMMPS development version from GitHub</h4>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone <span class="nt">--depth</span><span class="o">=</span>1 https://github.com/lammps/lammps.git
<span class="nb">cd </span>lammps
</code></pre></div></div>
<h3 id="configure-and-compile-lammps-with-cmake">Configure and Compile LAMMPS with CMake</h3>
<p>A beginner-friendly way to compile LAMMPS is to use CMake. Create a <code class="language-plaintext highlighter-rouge">build</code>
directory to compile LAMMPS and move into it. This directory will store the
build configuration and any binaries generated during compilation.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">mkdir </span>build
<span class="nb">cd </span>build
</code></pre></div></div>
<p>There are countless ways to compile LAMMPS. It is beyond the scope of this
tutorial. If you want to find out more about what can be enabled, please
consult the extensive
<a href="https://lammps.sandia.gov/doc/Build_cmake.html">documentation</a>.</p>
<p>To compile a minimalistic version of LAMMPS, we’re going to use a preset.
Presets are a way to specify a collection of CMake options using a file.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cmake ../cmake/presets/minimal.cmake ../cmake
</code></pre></div></div>
<p>This command configures the build and generates the necessary Makefiles. To compile the binary, run the make command.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>make <span class="nt">-j</span> 4
</code></pre></div></div>
<p>The <code class="language-plaintext highlighter-rouge">-j</code> option specifies how many parallel processes will perform the
compilation. This option can significantly speed up compilation times. Use a
number that corresponds to the number of processors in your system.</p>
<p>After the compilation completes successfully, you will have an executable
called <code class="language-plaintext highlighter-rouge">lmp</code> in the <code class="language-plaintext highlighter-rouge">build</code> directory.</p>
<p><img src="/assets/img/lammps/wsl/compilation_result.png" alt="Compilation result" /></p>
<p>Please take note of the absolute path of your <code class="language-plaintext highlighter-rouge">build</code> directory. You will
need to know the location to execute the LAMMPS binary later.</p>
<p>One way of getting the absolute path of the current directory is through the
<code class="language-plaintext highlighter-rouge">$PWD</code> variable:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># prints out the current value of the PWD variable</span>
<span class="nb">echo</span> <span class="nv">$PWD</span>
</code></pre></div></div>
<p>Let us save this value in a temporary variable <code class="language-plaintext highlighter-rouge">LAMMPS_BUILD_DIR</code> for future use:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">LAMMPS_BUILD_DIR</span><span class="o">=</span><span class="nv">$PWD</span>
</code></pre></div></div>
<p>The full path of the LAMMPS binary then is <code class="language-plaintext highlighter-rouge">$LAMMPS_BUILD_DIR/lmp</code>.</p>
<hr />
<h2 id="running-an-example-script">Running an example script</h2>
<p>Now that we have a LAMMPS binary, we will run a script from the examples folder.</p>
<p>Switch into the <code class="language-plaintext highlighter-rouge">examples/melt</code> folder:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> ../examples/melt
</code></pre></div></div>
<p>To run this example in serial, use the following command line:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$LAMMPS_BUILD_DIR</span>/lmp <span class="nt">-in</span> <span class="k">in</span>.melt
</code></pre></div></div>
<p>To run the same script in parallel using MPI with 4 processes, do the following:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mpirun <span class="nt">-np</span> 4 <span class="nv">$LAMMPS_BUILD_DIR</span>/lmp <span class="nt">-in</span> <span class="k">in</span>.melt
</code></pre></div></div>
<p>If you run LAMMPS for the first time, the Windows Firewall might prompt you
to confirm access. LAMMPS is accessing the network stack to enable parallel
computation. Allow the access.</p>
<p><img src="/assets/img/lammps/wsl/WindowsFirewall.png" alt="Windows Firewall Warning" /></p>
<p>In either serial or MPI case, LAMMPS executes and will output something similar to this:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>LAMMPS (30 Jun 2020)
...
...
...
Total # of neighbors = 151513
Ave neighs/atom = 37.878250
Neighbor list builds = 12
Dangerous builds not checked
Total wall time: 0:00:00
</code></pre></div></div>
<p><strong>Congratulations! You’ve successfully compiled and executed LAMMPS on WSL.</strong></p>
<h3 id="final-steps">Final steps</h3>
<p>It is cumbersome to always specify the path of your LAMMPS binary. You can
avoid this by adding the absolute path of your <code class="language-plaintext highlighter-rouge">build</code> directory to your PATH
environment variable.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">export </span><span class="nv">PATH</span><span class="o">=</span><span class="nv">$LAMMPS_BUILD_DIR</span>:<span class="nv">$PATH</span>
</code></pre></div></div>
<p>You can then run LAMMPS input scripts like this:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lmp <span class="nt">-in</span> <span class="k">in</span>.melt
</code></pre></div></div>
<p>or</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mpirun <span class="nt">-np</span> 4 lmp <span class="nt">-in</span> <span class="k">in</span>.melt
</code></pre></div></div>
<p><strong>Note:</strong> the value of this <code class="language-plaintext highlighter-rouge">PATH</code> variable will disappear once you close your
console window. To persist this setting edit the <code class="language-plaintext highlighter-rouge">$HOME/.bashrc</code> file using your
favorite text editor and add this line:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">export </span><span class="nv">PATH</span><span class="o">=</span>/full/path/to/your/lammps/build:<span class="nv">$PATH</span>
</code></pre></div></div>
<h4 id="example">Example:</h4>
<p>If the LAMMPS executable <code class="language-plaintext highlighter-rouge">lmp</code> has the following absolute path:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/home/<USERNAME>/lammps/build/lmp
</code></pre></div></div>
<p>the <code class="language-plaintext highlighter-rouge">PATH</code> variable should be:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">export </span><span class="nv">PATH</span><span class="o">=</span>/home/<USERNAME>/lammps/build:<span class="nv">$PATH</span>
</code></pre></div></div>
<p>Once set up, all your Ubuntu consoles will always have access to your <code class="language-plaintext highlighter-rouge">lmp</code>
binary without having to specify its location.</p>
<h2 id="conclusion">Conclusion</h2>
<p>I hope this gives you good overview on how to start compiling and running LAMMPS on
Windows. WSL makes preparing and running scripts on Windows a much better
experience.</p>
<p>If you are completely new to Linux, I highly recommend investing some time in
studying Linux online tutorials. E.g., Tutorials about Bash Shell and Basic
Unix commands (e.g., <a href="https://linuxjourney.com/">Linux Journey</a>). Acquiring these skills will make you
much more productive in this environment.</p>
<h2 id="further-reading">Further reading</h2>
<ul>
<li><a href="https://docs.microsoft.com/en-us/windows/wsl/">Windows Subsystem for Linux Documentation</a></li>
</ul>It’s always been tricky for us to have LAMMPS users and developers work on Windows. We primarily develop LAMMPS to run on Linux clusters. To teach LAMMPS in workshop settings, we’ve usually had to redirect Windows users to Linux Virtual Machines such as VirtualBox or Unix-like compilation with Cygwin.Welcome to my website!2020-05-18T17:47:30+00:002020-05-18T17:47:30+00:00/blog/update/2020/05/18/welcome-to-my-website<p>If you ever find this website, chances are you just stumbled on some random
person’s blog while searching for a solution for a technical problem online.
Been there many times myself. Welcome :-)</p>
<p>What you’ll find here is my personal space online to host my resume, showcase
some of my projects and blog posts about topics that interest me. I’ve needed a
space to write down things I often need myself or I keep explaining to other
people over and over again. I also want to use it to go down the
memory lane to record certain things. It’s best to write down stories when they
are fresh, and you’ll never know who else can benefit from your own
experiences.</p>
<p>In that spirit, thank you for reading and I hope you enjoy some of the stuff
you find here.</p>
<p>Cheers,</p>
<p>Richard</p>If you ever find this website, chances are you just stumbled on some random person’s blog while searching for a solution for a technical problem online. Been there many times myself. Welcome :-)