Optimizing your C++ code for molecular dynamics

While working with the molecular dynamics project in FYS4460 I decided to learn more about how to optimize my C++ code for performance. As always, I follow Donald Knuth’s famous quote as a guideline to optimization:

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil”[2]

And this has proved to be as true as ever in my efforts to optimize my code. There are a bunch of things that I have tried that didn’t turn out to be as effective as I had thought, and some other that I would never think could be so important. I’ve listed most of these in this post so you too may learn from my experience. They are all listed in the order from most useful to most wasteful:

Continue reading Optimizing your C++ code for molecular dynamics

Modifying keys on a Norwegian Linux keyboard to resemble those on a Mac

A friend of mine is switching between a Mac and a Linux machine, causing some readjustment whenever he switches keyboards. The most urgent fixes were to move the curly and square braces together with the backslash and dollar sign. Basically to map the keys as follows:

ALT + 8 = [
SHIFT + ALT + 8 = {
SHIFT + ALT + 7 = \
SHIFT + 4 = $

To set up these fixes, the first thing you need to do is to go to System Settings and Keyboard Layout (might be hidden under Region and Language) and select advanced options. Here you need to enable “Key to choose third level: Left Alt”.

The next is to run the following commands:

xmodmap -e "keycode 13 = 4 dollar 4 currency dollar onequarter"
xmodmap -e "keycode 16 = 7 slash 7 slash braceleft backslash"
xmodmap -e "keycode 17 = 8 parenleft 8 8 bracketleft braceleft"
xmodmap -e "keycode 18 = 9 parenright 8 8 bracketright braceright"

To store these settings permanently, create a file named .bashrc in your home folder and add them to this file.

How to get things done with todo.txt

The simple answer to how you get things done is to actually do them. However, to do things in an organized manner is more easily said than done. Why? Because it is way too easy to drift away with less important stuff when you’re supposed to do anything you have to.

What solved my problem: Todo.txt. Why?

The solution for me has always been to have a todo list that I can look up whenever I’m wondering about what to do next. It is way too hard to stay focused on a task if I have to remind myself about what’s next all the time. Leaving later tasks in an organized list makes it possible for me to avoid these constant reminders and let me focus peacefully on one task at a time, knowing that I won’t forget the next important task.

However, keeping such a list can introduce another problem to solve: How can I store the list in an easily accessible place that makes it easy to review it, cross things off it, list only one project at a time and maybe only the top priorities?

The best option for availability is to have the list on a whiteboard next to my computer, but that reveals several problems. The whiteboard will be way too small no matter how large a whiteboard I buy, and it will not be easily synchronized. In other words, I will most likely need something that runs on my computer.

Several applications are available for this purpose, but I have yet to find one that works well on all my systems with synchronization. I’ve tried to set up manual synchronization of folders using services like Dropbox, Ubuntu One and SpiderOak, but after Getting Things Gnome on my laptop wrote over all my changes from my desktop and Tasque failed on me while syncing via Remember The Milk, I decided to go back to the good old “todo.txt” file in a folder on my computer.

This works fine, but it lacks some options to sort tasks after priority or project. However, there is a beautiful script application that has come to the rescue for me. Visit todo.txt to see what I’m talking about.

It’s basically a simple script that lets you keep your todo-list in a file for compatibility and availability between systems, while giving you the options to view, add and delete tasks via the command line.

This solves all problems with syncing and availability. Now I can leave the syncing to a system such as Ubuntu One without worrying about compatibility between my phone and my computer, and even be able to view, add and delete tasks without ever leaving the terminal.

And should I ever be on a system without the todo.txt script, I can always open the file in vim or view it with cat.

Task lists from code comments

What about task lists from code comments? I often leave comments in LaTeX-files, code files and Python scripts like this:

// TODO: Make a cup of coffee

Well, as I said, I’ve often got a terminal open when working on anything, so the best solution for me would be never to leave the terminal:

cat <<anyfileyoulike>> | grep TODO

This simply lists all the TODO-comments in my code or text file, so that I can easily review the ones that are not yet done. Simple as that.