18 April 2012

117. Sorting out framebuffer in linux (debian)

If you have /dev/fb0 you're fine -- you have a working frame buffer, and that was the case on my laptop and my optiplex 990. However, my homebuilt boxes didn't have any framebuffer devices.

This is how to set up framebuffer:

sudo apt-get install hwinfo
sudo hwinfo --framebuffer

02: None 00.0: 11001 VESA Framebuffer                        
  [Created at bios.464]
  Unique ID: rdCR.fRULN9k9OD4
  Hardware Class: framebuffer
  Model: "Intel(r)Cantiga Graphics Controller"
  Vendor: "Intel Corporation"
  Device: "Intel(r)Cantiga Graphics Controller"
  SubVendor: "Intel(r)Cantiga Graphics Chip Accelerated VGA BIOS"
  SubDevice:
  Revision: "Hardware Version 0.0"
  Memory Size: 127 MB + 960 kB
  Memory Range: 0xd0000000-0xd7feffff (rw)
  Mode 0x0360: 848x480 (+896), 8 bits
  Mode 0x0361: 848x480 (+1728), 16 bits
  Mode 0x0362: 848x480 (+3392), 24 bits
  Mode 0x0305: 1024x768 (+1024), 8 bits
  Mode 0x0317: 1024x768 (+2048), 16 bits
  Mode 0x0318: 1024x768 (+4096), 24 bits  Mode 0x0312: 640x480 (+2560), 24 bits
  Mode 0x0314: 800x600 (+1600), 16 bits
  Mode 0x0315: 800x600 (+3200), 24 bits
  Mode 0x0301: 640x480 (+640), 8 bits
  Mode 0x0303: 800x600 (+832), 8 bits
  Mode 0x0311: 640x480 (+1280), 16 bits
  Config Status: cfg=new, avail=yes, need=no, active=unknown
Pick a mode e.g. 0x0318

Edit your /etc/default/grub

Add vga=0x0318 to the GRUB...DEFAULT line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet nouveau.modeset=0 vga=0x0318"

If there's a nomodeset command, delete it.

Do
sudo update-grub

and reboot. You're done.

There should now be a /dev/fb0 and your resolution when working in a TTY* should be different.

*the terminal you get to by doing alt+f1, alt+f2 etc.

What to do with framebuffers?
Apart from making your ttys look a lot nicer and work at higher resolution, they'll also allow you to use w3m-img for ncurses based browsing with images (w3m+w3m-img; sometimes it's useful), and to take screenshots of the terminal in terminal mode. But mostly, it just makes your terminal experience better through being at higher resolution.


More modes:
02: None 00.0: 11001 VESA Framebuffer                        
  [Created at bios.464]
  Unique ID: rdCR.efxRnBcYXs5
  Hardware Class: framebuffer
  Model: "NVIDIA GF108 Board - 1071v0p1"
  Vendor: "NVIDIA Corporation"
  Device: "GF108 Board - 1071v0p1"
  SubVendor: "NVIDIA"
  SubDevice:
  Revision: "Chip Rev"
  Memory Size: 14 MB
  Memory Range: 0xd7000000-0xd7dfffff (rw)

  Mode 0x0300: 640x400 (+640), 8 bits
  Mode 0x0301: 640x480 (+640), 8 bits
  Mode 0x0303: 800x600 (+800), 8 bits
  Mode 0x0305: 1024x768 (+1024), 8 bits
  Mode 0x0307: 1280x1024 (+1280), 8 bits
  Mode 0x030e: 320x200 (+640), 16 bits
  Mode 0x030f: 320x200 (+1280), 24 bits
  Mode 0x0311: 640x480 (+1280), 16 bits
  Mode 0x0312: 640x480 (+2560), 24 bits
  Mode 0x0314: 800x600 (+1600), 16 bits
  Mode 0x0315: 800x600 (+3200), 24 bits
  Mode 0x0317: 1024x768 (+2048), 16 bits
  Mode 0x0318: 1024x768 (+4096), 24 bits
  Mode 0x031a: 1280x1024 (+2560), 16 bits
  Mode 0x031b: 1280x1024 (+5120), 24 bits
  Mode 0x0330: 320x200 (+320), 8 bits
  Mode 0x0331: 320x400 (+320), 8 bits
  Mode 0x0332: 320x400 (+640), 16 bits
  Mode 0x0333: 320x400 (+1280), 24 bits
  Mode 0x0334: 320x240 (+320), 8 bits
  Mode 0x0335: 320x240 (+640), 16 bits
  Mode 0x0336: 320x240 (+1280), 24 bits
  Mode 0x033d: 640x400 (+1280), 16 bits
  Mode 0x033e: 640x400 (+2560), 24 bits
  Mode 0x0345: 1600x1200 (+1600), 8 bits
  Mode 0x0346: 1600x1200 (+3200), 16 bits
  Mode 0x034a: 1600x1200 (+6400), 24 bits
  Mode 0x0360: 1280x800 (+1280), 8 bits
  Mode 0x0361: 1280x800 (+5120), 24 bits
  Config Status: cfg=new, avail=yes, need=no, active=unknown





Links to this post:
http://pinboard.in/u:greppy

11 April 2012

116. [Solved] Latex bug -- "tcfmgr: config file `tcfmgr.map' (usually in $TEXMFMAIN/texconfig) not found."


Symptom:
When using latexila or texmaker no dvi/ps/pdf is generated. No outright error is report though

When trying to generate the pdf in the terminal using latex e.g.

me@beryllium:~$ latex nature_draft.tex
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
kpathsea: Running mktexfmt latex.fmt
tcfmgr: config file `tcfmgr.map' (usually in $TEXMFMAIN/texconfig) not found.
I can't find the format file `latex.fmt'!
 kpsewhich -expand-var='$TEXMFMAIN'
gives
/usr/share/texmf/

which is the correct file structure as defined by texmf.cnf

kpsewhich texmf.cnf
/usr/share/texmf/web2c/texmf.cnf

So what the heck is going on? I've written articles, reviews and book in latex and never had a problem until now. Also, it only happens on one computer.

Solution:
I ended up just fooling around. What solved it was doing
sudo texconfig rehash
mktexlsr: Updating /var/lib/texmf/ls-R-TEXMFMAIN...
mktexlsr: Updating /var/lib/texmf/ls-R-TEXLIVE...
mktexlsr: Updating /var/lib/texmf/ls-R...
mktexlsr: Done.
That's all. Really.

Minor note:
you can run texonfig interactively as well. Just make sure to run it using sudo.



Links to this post:
http://tex.stackexchange.com/questions/64894/error-i-cant-find-the-format-file-pdflatex-fmt

27 March 2012

115. Very Simple Python Queue Manager

I suppose we can call it the VSPQM, which sounds a bit like a Roman initialism, akin to SPQR.

I've spent the past few days trying to get to grips with the Sun Gridengine (SGE) but have given up for now. While it seems capable, it's just overkill for my purposes, especially taking into account the difficulties in simply configuring it. It's a bit similar to my experience with OpenDX, a very capable plotting program, but which I couldn't make work to satisfaction in spite of being one of the lucky few in possession of the "Open DX -- Paths to Visualisation" book.

Long story short -- I wrote a small script in python. It
- reads a file, list, with the name of shell scripts
- the shell scripts, job1.sh..jobn.sh, are executed sequentially - when the execution of one script is finished, the next one is executed
- jobs can be added and removed from list during execution

It's a 'dumb' script -- it does not try to balance jobs across nodes or look for idle cpus/cores. It just executes one job after the other, and mark jobs as done after execution.

To test it:
create a file called list and put the following lines in it:
pi40.sh
pi400.sh
pi2000.sh
The scripts are the following:

pi40.sh
echo "pi to 40 decimals"
echo "scale=40; 4*a(1)" | bc -l -q
echo "done"
pi400.sh
echo "scale=400; 4*a(1)" | bc -l -q
pi200.sh
 echo "scale=2000; 4*a(1)" | bc -l -q
The python code for vspqm.py is below

I've aliased my vspqm (edit ~/.bashrc):
alias vspqm='/home/me/work/vspqm/vspqm.py'
Then sourced ~/.bashrc

Launch in the directory you keep your list file using
me@beryllium:~/work/vspqm/jobs$ vspqm list > log &
[1] 23925
me@beryllium:~/work/vspqm/jobs$ cat log
pi to 40 decimals
3.1415926535897932384626433832795028841968
done
3.141592653589793238462643383279502884197169399375105820974944592307\
[..]
3.141592653589793238462643383279502884197169399375105820974944592307\
81640628620899862803482534211706798214808651328230664709384460955058\
[..]

An nwchem example would be
list:
ac.sh
bn.sh
ac.sh:
cd acetone/
mpirun -n 4 nwchem ac.nw>ac.out
cd ../
bn.sh:
cd benzene/
mpirun -n 4 nwchem bn.nw>bn.out
cd ../


Our python queue manager (which we'll call vspqm.py and chmod +x to make executable) is below. Don't forget to change #!/usr/bin/python2.4 if necessary -- I use 2.4 on ROCKS and 2.7 on Debian testing/wheezy

#!/usr/bin/python2.4
# rudimentary queue manager. Handles a single node,
# submitting a series of jobs in sequence. use python v2.4-2.7
import os
import time
import sys
infile=sys.argv[1]
print "pyqm v 0.0.3"
def launchjob(job):
        i=0
        print "######"
        job=job.rstrip('\n')
     
        i=os.system("sh "+job)
        if i==0:
                print "Job successful"
        else:
                print "Job failed"
        print "######"
        return i
def remake_list(infile):
        qfile=open(infile,"w")
        bakfile=open(infile+".bak",'r')
        for i in bakfile:
                qfile.write(i)
        return 0
def rewind(infile):
        qfile=open(infile,"w")
        bakfile=open(infile+".bak",'r')
        for i in bakfile:
                qfile.write(i[1:])
        return 0
def get_next_job(infile):
        qfile=open(infile,"r")
        bakfile=open(infile+".bak",'w')
        lines=""
        job=""
        for line in qfile:
                if line[0]=="*":
                        print "Marked as done: ",line[1:]
                if line[0]!="*" and job=="":
                        print "Launching: ", line
                        job=line
                        line="*"+line
                lines+=line
        bakfile.write(lines)
        qfile.close
        bakfile.close
        return job
def main(infile):
        jobs=1
        while (jobs==1):
                newjob=get_next_job(infile)
                remake_list(infile)
                if newjob!="":
                        jobs=1
                        echojob=launchjob(newjob)
                else:
                        print "No more jobs found at "+str(time.asctime())    
                        jobs=0
        return 0

if __name__ == "__main__":
        main(infile)
        rewind(infile)