Old site

There is a lot of information that I’m probably going to leave on my old site, so I don’t think I’m going to close it. I’ve disabled editing on the Wiki I had on there and hopefully have “locked it down.”

Just in case anyone was wondering, to make an ErfurtWiki “read-only” (that is, disable editing) you can add to config.php:

unset($ewiki_plugins["action"]["edit"]);

In case you don’t remember, my old site was available at old.tamasrepus.hotnudiegirls.com.

Topic: 

Splitting a Sequence into Subsequences with Python

I’m writing a load balancing algorithm for this cluster I’m working on, and have a bunch of things in a Python list sequence. So came the issue, how to divide the list into sublists for each node in the cluster to compute? I came up with the algorithm:

def split_seq_stride(l, n):
  """Splits a sequence l into a list of subsequences containing at least n
  elements each, not preserving order. The first few subsequences may contain
  n+1 elements, containing the last few elements. (Algorithm is good for load
  balancing)"""
  r=[]
  k=len(l)/n
  [r.append(l[i::k]) for i in range(k)]
  return r

which behaves like:


>>> l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> print split_seq_stride(l, 3)
[[1, 4, 7, 10], [2, 5, 8], [3, 6, 9]]

Assuming each task is an equal amount of work, this algorithm is a good load balancing algorithm. it prevents any node from having to do any less significant work than the others.

Probably useful for someone: what about splitting up a sequence in-order, with the last subsequence containing fewer elements? This code segment does just that:


def split_seq(l, n):
  """Splits a sequence l into a list of subsequences containing at most n
  elements each, preserving order. The last subsequence may contain less
  than n elements."""
  r=[]
  [r.append(l[s:s+n]) for s in range(0, len(l), n)]
  return r

which behaves like:


>>> l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> print split_seq(l, 3)
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]

Thanks to yason and others on EFnet’s #python for pointers.

The semantics of a fork, followed by setsid, and another fork

So I came across a piece of code that looked like this:

if (fork() != 0)
  exit(0);
setsid();
if (fork() != 0)
  exit(0);

What each individual system call can easily be looked up and understood (well, maybe not setsid), but what the entire block of code is doing is not clear at all

…and I really can’t say I understand the mechanics of it all to explain myself. But this python code segment’s comments does a good job of what the entire block of code is trying to do—daemonize a process completely.

Topic: 

NVIDIA 6800 Ultra power usage

For some odd reason, NVIDIA gives the power requirements for their video cards in watts. Watts aren’t a very good quantitative measurement for this–there are both “good” and “bad” power supplies that have the same wattage rating, however they usually measure differently.

An article over at Spode’s Abode measures the power requirements of the 6800 Ultra. His consensus is that a 6800 Ultra requires a current of 5 amps at load, and can use a max of 124 watts power.

My 6800 GT is probably not far off. Along with the consideration that a modern high-end CPU will need 8 amps, and hard disks require ~2 amps each, I can plan my power requirements for a new system I’m building. More on that later.

Pages

Subscribe to Samat Says RSS