Category Archives: Computing

Crypto-currency mining

I’m curious, because I’m a tech enthusiast. But I don’t have free power so it’s not a feasible proposition.

But this current craze is annoying me for another pair of reasons: lack of supply of GPUs and hiked prices.

I’m currently looking at building a small, powerful-but-portable system based around a Ryzen CPU. Because AMD cards don’t do CUDA, I’m stuck buying nVidia. That doesn’t bother me that much… but the 50% price hike I’ve seen the GTX 1070 undergo in the last fortnight is… vexing. In fact, I was so annoyed I was thinking about buying a 1060 instead… oh, wait, they’re all out of stock! So in desperation, I looked at 1080s… which is far more than I wanted to spend… they’re OoS as well.

1050’s aren’t, but they’re not even as powerful as my laptop. I have no pressing desire for a “downgrade”-upgrade.

Sigh.

Headless RaspPi: Tell Me Where You Are

I like several of the little SBC (Single Board Computer) systems that are available, despite having a love/hate relationship with my favourite – the ODROID C2. For the minute I’m stuck with just a Raspberry Pi 3 as a little SBC, so needs must when the devil, etc etc…

Anyway, when you control your own network, as I used to, it doesn’t really matter what IP DHCP decides to assign to each system. I could look it up on the router easily enough, or even fix an IP address based on MAC address.

OK, fine… but what if you don’t control your router?

Well, you could brute-force scan the entire known IP range of the network using NMAP… (nmap -sS xxx.yyy.zzz.0/24) but that seems a little extreme. It works in a pinch, though, and might be the only way of finding it that all important first time.

Once you know where it is, however, how can you keep it? On a network you don’t control, you can get jumped around the IP range depending on how the router is feeling and how many others are connected. Not very useful.

Here’s a little script modified from another one that didn’t work for me… (requires Python 2, not Python 3…)

Ah, and I found where the mods come from…!

This will send you an e-mail telling you your headless systems’ IP when the RPi boots.

Just add this to a file with vi bootupEmail.py, then chmod +x it:

import subprocess
import smtplib
import socket
from email.mime.text import MIMEText
import datetime
# Change to your own account information
to = 'me@example.com'
gmail_user = 'test@gmail.com'
gmail_password = 'yourpassword'
smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_password)
today = datetime.date.today()
# Very Linux Specific
arg='ip route list'
p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
data = p.communicate()
split_data = data[0].split()
ipaddr = split_data[split_data.index('src')+1]
my_ip = 'Your ip is %s' %  ipaddr
msg = MIMEText(my_ip)
msg['Subject'] = 'IP For RaspberryPi on %s' % today.strftime('%b %d %Y')
msg['From'] = gmail_user
msg['To'] = to
smtpserver.sendmail(gmail_user, [to], msg.as_string())
smtpserver.quit()

You’ll also need to add python /home/user/bin/scripts/bootupEmail.py to your rc.local, just before the exit 0 at the end.

IMPORTANT: Obviously, since you just put your Gmail password in a plain text file (really, really bad security practice!) just set up a gmail account to only do this one thing. Or, if you want, you could set up a mailserver on your Pi.

That may become the topic of a future post. In fact, it probably will, because I can’t believe I just suggested putting a password in plaintext.

Linux Ping Script… (Finally…)

Anyone reading this may remember I was having intermittent – but regular and extremely annoying – network dropouts in my accommodation.

Well, I finally got twenty minutes (and a network switch so I can have more than one thing plugged in to the LAN at once) to get my act together and update my little Raspberry Pi 3 so it can sit and (low power) ping a server and let me know when the network drops out.

Just like the Windows version, this only writes to the log file when it can’t connect – so if your network never drops out, you’ll never even see the log file get created. You can test it by changing the sleep time and what it greps for (if you change sleep to 1 and grep unknown to grep PING, you can check it works…)

Just save it somewhere sensible, like /home/user/bin/scripts or similar, chmod +x it, and run it from the terminal. Force it to the background and you can log out and leave it ticking over.

#!/bin/bash
while true; do
     x=`ping -c1 www.google.com 2>&1 | grep unknown`
     if [ ! "$x" = "" ]; then
         date >> brokentimes-pingtest.txt
     fi
sleep 30
done

Debian 8 Upgrade to Debian 9: Key Error

There is no public key available for the following key IDs:
EF0F382A1A7B6500

If you’re getting an error like the above when attempting to upgrade to Debian 9 (the new Stable version), it’s an easy fix:

sudo apt-get install debian-keyring debian-archive-keyring

Complaints about keys scare me something chronic, as it can be a sign that the repo (or worse, your OS) has been compromised… so I always look for a way to solve it.

Fortunately this one was easy.

ORCA & OpenMPI: File Descriptor Limits

I’ve just been tinkering around with an interesting issue: ORCA, the computational chemistry program I’ve been using because I can’t afford Gaussian, crashes during geometry optimisation of a (moderately) complex molecule because of OpenMPI.

OpenMPI is complaining about running out of file descriptors. Eh? Seriously? OK…

Turns out that Ubuntu 16.04 (even the server version) sets the open file limit at what is frankly a little on the low side – 1024 open files. That sounds like a lot, until you think that when running something via MPI it can be crunching across a lot of temporary files and so on… and it suddenly doesn’t seem so many. Interestingly, I never had this problem before because I was running Ubuntu 14.04 previously which (from what the internet says) had a limit of 4096. I checked with the latest release (14.04.5) which had a limit of 1024, so I’ll assume for now that the 4096 limit was in an older release…

I’ll be honest, since this is the first time I’ve encountered this issue, I’ve never actually checked previously…

Anyway, there appear to be two fixes that work, one on a per-user basis, one on a system-wide basis. Pick your poison.

The user-level fix is super easy, add the following to your .bashrc:

if [ $USER = "paramagnetic" ]; then
ulimit -n [pick-a-big-number, eg; 32768]
fi

Can also be added to /etc/profile

At the system level, it’s a little more difficult, but still totally doable. Edit /etc/security/limits.conf

* soft nofile 32768
* hard nofile 32768
root soft nofile32768
root hard nofile 32768

Then add:

session required pam_limits.so

To /etc/pam.d/common-sessions and /etc/pam.d/common-sessions-noninteractive

And reboot in all cases. If you have another form of system management software running, it might overrule you, which is annoying, but outside of the scope of this post.

Python, Windows and PyMol

So I was chatting with an ex-colleague who had been having some fun getting PyMol to install on Windows. So I thought I’d do a quick write-up.

To start with, you need four things:

  1. The latest (C)Python installation package (AMD64 for 64-bit Windows 10)
  2. The NumPy+MKL wheel from Christoph Gohlke’s collection for AMD64
  3. The PyMol wheel from the same for AMD64
  4. The PyMol Launcher wheel from the same (optional) for AMD64

Install Python:

Make sure to tick “add to path” also, disable the pathlength limit, since it’s an option:

Open a commandline: (shift+right click)

Use pip to install wheel:

Then install NumPy+MKL:

Then PyMol: (this will also pull in Pmw)

Then PyMol Launcher (if you want)

Then find where PyMol is installed: (a ‘cheat’ here is %appdata% in the address bar!)

And create a shortcut on the Desktop/Start Menu/Task Bar (to your taste)…

Protein loaded is 5XA7, a recent submission and nothing whatsoever to do with me. I just picked it for demonstration purposes.

And now it should work! In all honesty, I find the pip install system far more trouble than just finding and installing the relevant libraries used to be…

NWChem: Headaches

Been struggling to get NWChem to compile today. I think I’ve nearly got it, but I’m calling it a day for now because otherwise I’ll still be working on it at 0500…

For the record, it compiles fine if I don’t want CUDA or OpenBLAS (the internal BLAS libraries are horribly slow, by the developers’ own admission) but it’s getting CUDA and a faster MKL in place that is causing me grief.

Basically, I’m hoping that it can provide me some speedup over a CPU computational chemistry package – I’ve had the chance to test TeraChem, which I actually think is awesome… it’s just that it doesn’t like Pascal generation GPUs, so it’s fine on my laptop with a 980m (well, if you call the GPU sitting at frighteningly high temperatures “fine”) but doesn’t want to know about the twin GTX1080’s I’ve got in a sort-of-but-not-workstation.

So, anyway, as soon as I’ve figured out what compile flags I need to get it working properly, I’ll update this post.

How To: Intel GPU for monitor, nVidia GPUs for CUDA

There are lots of methods for getting this working spread over the internet. Some work, but are a mess (and involve faking monitor connections to the nVidia GPUs using some Xorg trickery) or just flat out don’t work.

This method works great, provided you don’t want fan control over the GPUs. So just get some decent case fans and you’re golden.

I used the nVidia Ubuntu PPA for drivers; you can use the binary blob .run file, and frankly it’ll probably save you headaches in the long run (like, for example, when the drivers update and freakin’ break everything! /rant)

First, I got a more up-to-date kernel on Ubuntu 16.04…

apt-get install linux-headers-4.10 linux-headers-4.10-generic linux-image-4.10-generic linux-image-extras-4.10-generic

You should have dkms installed, but if not, pull it in with:

apt-get install dkms

reboot

Add nVidia drivers PPA:

add-apt-repository ppa:graphics-drivers/ppa

apt-get update

apt-get install nvidia-375

apt-get install nvidia-settings nvidia-prime

reboot

at this point, the graphics may work, or they may not. If they do, great. if they don:t, well, it:s easy to fix by reinstalling nvidia-settings and nvidia-prime.

Set the focus GPU to intel via the system tray nvidia settings app. log out, log back in again. 3d accel should still work.

Download the CUDA repo .deb (I used network, but local works too) and install using dpkg. there should not be any dependencies unmet or conflicting.

dpkg -i [cudarepofile.deb]

apt-get update

apt-get install cuda

This will pull in CUDA8.0. Again, like I said, you can always use the local .run file, which will save you updating headaches.

Now, at this point, CUDA wants to reinstall the gpu driver. I let it. It’ll break 3d acceleration, but reinstall nvidia-settings and nvidia-prime to fix it again.

At this point, nvidia-smi (the nvidia system management interface) will stop working. This is because it can’t cope with the idea of you not using the nVidia GPUs for Xorg. Dumb, given the drive nVidia has been putting into GPGPU, but nevertheless true.

To get it working again, do the following; you can either remove or rename the link in /usr/bin. I rename, others might remove:

mv /usr/bin/nvidia-smi /usr/bin/nvidia-smi.backup

then, place the following script in a file called “nvidia-smi”

vi /usr/bin/nvidia-smi

#!/bin/bash
LD_PRELOAD=/usr/lib/nvidia-375/libnvidia-ml.so /etc/alternatives/x86_64-linux-gnu_nvidia_smi "$@"

OK. Now, you need to change the /nvidia-375/ bit to whatever driver version you are using. If it’s 375, awesome. If it’s 378, you’ll get an error until you change it.

The “$@” bit is necessary as nvidia-smi for the correct parsing of the command; without it, it’ll throw a nasty error.

So, nvidia-smi works, but some things will still throw up wobblers. To fix this, add;

# CUDA stuff
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH

# Fixing Intel/nVidia conflict (nVidia for compute, Intel for display)
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/lib/nvidia-375:$LD_LIBRARY_PATH

To your .bashrc

To get persistence working (that is, power state management, which will allow the card to clock down when it’s not being used) edit the following:

vi /etc/rc.local

and add

/usr/bin/nvidia-smi -i 0,1 -pm ENABLED

above the “exit 0”

This tells nvidia-smi to select both GPUs and enable persistence mode so that GPUs actually freakin’ work properly. This has the side effect of making the nvidia-smi command instant again (it wasn’t when switching to Intel iGPU). Obviously, if you’ve only got a single GPU, you just tell it -i 0… if you’ve got three or four, you can add accordingly. The GPU count is always from 0.

Whenever you have a driver update occur, it’ll replace the nvidia-smi script with the actual program again. Let it. CUDA will break when you reboot (so long as drivers don’t update, it’ll survive any kernel updates without breaking) and it’s easy enough to remove the symlink in /usr/bin/nvidia-smi and replace with that little script again.

I’m using this to drive a 4K@60Hz monitor via the iGPU while using a pair of GTX1080’s for compute.

The only thing I can’t get working is fan control. I’d rather have my GPUs loud, than I would have them cooking. But I compensate with some fairly chunky intake fans pointing straight across the GPUs.

I’ve seen people (some fairly high-ranking Professors, as well) suggest watercooling. Well, yes, that is a possible solution. It’s just a shame that I’m a little shy about watercooling 24/7 systems that are largely unattended, because… I’ve had two watercooling pumps, of different types, die on me recently. I was fortunate that one system was idle when it happened, but it still reached “idle” at 66 degrees C. That was with full-copper (read: expensive) waterblocks, and CPU only. I don’t doubt that GPUs would be dead if that had happened to them.

So, yeah, I’m a little leery of watercooling systems for high compute loads unless backed by manufacturer warranty. Haha.