Converting OS X .plist to XML

The failure of my MacBook Pro seems that it didn’t cost much in terms on data loss, actually all the really crucial data were there. There are though some bits here and there that need to be moved over to my Linux box. One of the most important for everyday use the was the feed list for my RSS Aggregator. I was using the elegant, nice and simple NewsFire which uses binary plists (XML-like) for storing the feed list and I was never bothered exporting the feed list to OPML. The plist command in OS X can convert the .plist file into a .xml file, however I had no other Mac to do this operation or copy over the plist and export in OPML from there. Therefore I had to find a workaround for getting the plist working on RSSOwl or Liferea. Found the Perl plutil for Linux which converted the binary plist to standard XML. RSSOwl managed then to import the XML with all the blogs’ feeds as on NewsFire.

Regarding liferea, it wouldn’t import the XML file as it wasn’t proper OPML. But since RSSOwl imported the XMl file, I exported the feed list as OPML, which would be imported into Liferea or any other application.

HFS+ on Linux

My MacBook Pro seems to have died. Its hard disk holds lots of data that have not been backed up anywhere else. The important data have been mostly backed up but latest changes haven’t been backed up. Other than that, I had to check the hard disk for bad sectors etc and since I don’t have another Mac to test it on I had to do it on my Fedora box. My system (Fedora 15) would automatically detect and mount the HFS+ hard disk on read only mode. It was also missing the fsck tool for HFS+ partitions. Getting the fsck tool for HFS+ required downloading and installing hfsplus-tools via yum.However, fsck.hfs will not allow you, except if you use the –force option, to scan the partition if it has journalling on, which is the case with HFS+ partitions by default.

But how would I turn off journalling when I don’t have a Mac system to attach my disk on? After a couple of minutes I came across a post on the Ubuntu forum which linked to this blog. The author has a C code that turns journalling off. A fixed version of this code can be found here. The compiled code results in an executable which gets as its only argument the partition that you want to get journalling off.

# gcc journalling_off.c -o journalling_off
# ./journalling_off /dev/sdg2

Next step was to perform the fsck check on the target disk

# fsck.hfs /dev/sdg2
** /dev/sdg2
** Checking HFS Plus volume.
** Checking Extents Overflow file.
** Checking Catalog file.
** Checking multi-linked files.
** Checking Catalog hierarchy.
** Checking Extended Attributes file.
** Checking volume bitmap.
** Checking volume information.
** The volume OS X appears to be OK.

Disk looks OK. Next step is to mount it with read-write permissions:

# mount -t hfplus -o rw,user /dev/sdg2 /mnt/osx

Next issue encountered was the different UIDs between my account on the OS X system and that on the Linux system. Therefore, next step was to change the UIDs under the whole user directory on the OS X disk so I could access without problem with write permissions from my Linux box:

# find panoskrt/ -uid 501 -exec chown panoskrt {} \;

Speedup and efficiency shell calculator

The following script can be used to calculate the speedup and efficiency of a parallel code when compared to its serial version. Pretty much straight forward process. This script can be used either individually or as part of another script to automate the process of generating the required results. It accepts three arguments: 1) serial execution time 2) parallel execution time 3) number of processors.

./SEcalc.sh <serial> <parallel> <procs>

Script:

############################################################################
# Copyright (C) 2011  Panagiotis Kritikakos <panoskrt@gmail.com>           #
#                                                                          #
#    This program is free software: you can redistribute it and/or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation, either version 3 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>. #
############################################################################

#!/bin/bash

if [ "$#" -eq "3" ]; then
   runtime1proc=$1
   runtimeNproc=$2
   totalprocs=$3
   speedup=`echo "${runtime1proc}/${runtimeNproc}" | bc -l`;
   efficiency=`echo "${speedup}/${totalprocs}" | bc -l`;

   printf "\n Total processors: ${totalprocs}\n\n";
   printf " Runtime for serial code: ${runtime1proc}\n Runtime for parallel code: \
   ${runtimeNproc}\n\n";
   printf " Speedup: ${speedup}\n Efficiency: ${efficiency}\n\n";
else
   printf "\n Usage: SEcalc.sh   \n\n";
   printf " SEcalc.sh 0.350 0.494 2\n\n";
fi

Running Fortran on ARM

Generally and very briefly, there is no official Fortran compiler available for the ARM architecture. The easiest way to get Fortran code (specifically Fortran 77) to run on the ARM architecture, or any other architecture that doesn’t have a Fortran compiler, is to convert the Fortran code to C. In order to do that efficiently, we can use Netlib’s f2c command line tool, available for Linux, Unix and Windows.

The steps that need to be followed are:

1) Compile the library – source at http://www.netlib.org/f2c/libf2c.zip
Rename makefile.u to makefile and do make. Copy the generated libf2c.a to /usr/lib and the f2c.h header under /usr/include.
2) Compile the binary – source at http://www.netlib.org/f2c/src/
Rename makefile.u to makefile and do make. Copy the binary f2c under /usr/local/bin.

Supposing we have the foo.f file we can generate the C version by running f2c foo.f, giving us foo.c. It can now be compiled using ‘gcc foo.c -o foo -lf2c‘.

In order to automate this process a while, the following script can be used. It accepts only one argument, the Fortran source file.

#!/bin/bash
fortranFile=$1
fileName=`echo $1 | sed 's/\(.*\)\..*/\1/'`
echo $fileName
f2c $fortranFile
gcc ${fileName}.c -o $fileName -lf2c

UPDATE: There is GCC Fortran compiler for ARM Fedora and Debian and I presume for other distros as well. The issue now is that these distributions are compiled for ARMv5, while the latest ARM processors (Cortex-A8, A9, A15) are of the ARMv7 architecture. The compilers, and the OS in general is therefore unable to make use of the additional instructions sets and FPU. Other distros, such as Slackware, are compiled on even older architecture, ARMv4.

GPU programming in a glance

On my MacBook I have a nVIDIA GeForce 8600M GT which is CUDA enabled, something I never bothered checking until very recently. nVIDIA provides online the required driver, SDK and additional “CUDA Developer”, as they call it, resources with lots of sample files to test the hardware of your system as well as actual code, including some parallel samples.

The CUDA toolkit seem to provide all you need to start with:

  • C/C++ compiler
  • Visual Profiler
  • GPU-accelerated BLAS library
  • GPU-accelerated FFT library
  • GPU-accelerated Sparse Matrix library
  • GPU-accelerated RNG library
  • Additional tools and documentation

It does also include OpenCL samples to play about. However, the OpenCL driver will need to be installed at first place. There’s a pre-release version and in order to download it you’d need to register yourself with nVIDIA. They have also published a book, “CUDA by example”, which is not for free apart from some fragments. Nevertheless, the sample codes of the book are free to download.

AMD / ATI have also their answer to CUDA, “ATI Stream“. From what I got it seems to support only OpenCL. I don’t have a Stream-supported ATI card at the moment so I couldn’t try that one.

To close this, there’s an interesting presentation that covers basics of GPUs and how to program them (CUDA based): Programming and optimization of applications for multiple GPU

Restarting VMware Fusion functionality

I just tried to boot my FreeBSD-7.2 VM on VMware Fusion and got an error message that it will not have any network availability as “network bridge on device /dev/vmnet0 is not running“. I checked and indeed, there was no vmnet* interface up. A look in /Library/Application Support/VMware Fusion reveals the file boot.sh, which happens to be the only available script.

$ ls -lrt
total 16944
drwxr-xr-x   3 root  wheel      102 12 Jul  2007 licenses
drwxr-xr-x   6 root  wheel      204 12 Jul  2007 kexts
-rw-r--r--   1 root  wheel      373 30 Oct  2007 license.fusion.site.6.0.200610
drwxr-xr-x   3 root  wheel      102  2 Nov  2007 vmx
-rwxr-xr-x   1 root  wheel  3590412 19 Apr  2008 vmware-vdiskmanager
-rwsr-xr-x   1 root  wheel   366264 19 Apr  2008 vmware-authd
-rwsr-xr-x   1 root  wheel  3194884 19 Apr  2008 vmware-rawdiskCreator
-rwxr-xr-x   1 root  wheel   200968 19 Apr  2008 vmware-ntfs
-rwxr-xr-x   1 root  wheel   152533 19 Apr  2008 vmware-config-net.pl
-rwxr-xr-x   1 root  wheel    74916 19 Apr  2008 vmnet-sniffer
-rwxr-xr-x   1 root  wheel    61428 19 Apr  2008 vmnet-netifup
-rwxr-xr-x   1 root  wheel   501632 19 Apr  2008 vmnet-natd
-r--r--r--   1 root  wheel     1241 19 Apr  2008 vmnet-nat.conf
-r--r--r--   1 root  wheel      742 19 Apr  2008 vmnet-dhcpd.conf
-rwxr-xr-x   1 root  wheel   333464 19 Apr  2008 vmnet-dhcpd
-rwxr-xr-x   1 root  wheel   120612 19 Apr  2008 vmnet-bridge
-rwxr-xr-x   1 root  wheel     7932 19 Apr  2008 vm-support.tool
-rwxr-xr-x   1 root  wheel    17186 19 Apr  2008 boot.sh
drwxr-xr-x   7 root  wheel      238 15 May  2008 tools-upgraders
drwxr-xr-x   6 root  wheel      204 15 May  2008 messages
drwxr-xr-x  13 root  wheel      442 15 May  2008 isoimages
drwxr-xr-x  17 root  wheel      578 15 May  2008 vnckeymap
drwxr-xr-x   5 root  wheel      170 15 May  2008 vmnet8
drwxr-xr-x   3 root  wheel      102 15 May  2008 vmnet1
-rw-r--r--   1 root  wheel     5612 15 May  2008 locations
-rw-r--r--   1 root  wheel       81 15 May  2008 config
drwxr-xr-x   3 root  wheel      102 15 May  2008 Uninstall VMware Fusion.app

Its execution pretty simply:

$ ./boot.sh
Usage: ./boot.sh {--start|--stop|--restart}
$ sudo boot.sh --start
VMware Fusion 87978: Starting VMware Fusion:
kextload: extension /Library/Application Support/VMware Fusion/kexts/vmmon.kext is already loaded
kextload: /Library/Application Support/VMware Fusion/kexts/vmci.kext loaded successfully
kextload: /Library/Application Support/VMware Fusion/kexts/vmioplug.kext loaded successfully
kextload: extension /Library/Application Support/VMware Fusion/kexts/vmnet.kext is already loaded
Internet Software Consortium DHCP Server 2.0
Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.
All rights reserved.

Please contribute if you find this software useful.
For info, please visit http://www.isc.org/dhcp-contrib.html

Configured subnet: 172.16.17.0
Setting vmnet-dhcp IP address: 172.16.17.254
Opened: ??
Recving on     VNet/vmnet8/172.16.17.0
Sending on     VNet/vmnet8/172.16.17.0
Internet Software Consortium DHCP Server 2.0
Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.
All rights reserved.

Please contribute if you find this software useful.
For info, please visit http://www.isc.org/dhcp-contrib.html

Configured subnet: 172.16.123.0
Setting vmnet-dhcp IP address: 172.16.123.254
Opened: ??
Recving on     VNet/vmnet1/172.16.123.0
Sending on     VNet/vmnet1/172.16.123.0

Once finished, the VM could start again without complains and gets its IP via LAN’s DHCP.

Counting words in TeX/LaTeX

I was trying to find an easy way to count the words in LaTeX documents. I guess there must be clients that do this for you, but I don’t use such a client and many times I’m using vi to edit LaTeX documents.

An way to go with it is to use a filter to strip as much as possible the TeX/LaTeX commands from the .tex file. This can be easily done with the detex command and the wc command:

detex report.tex | wc -w

Another way to filter the .tex document is to use untex in the same way as detex. This link describes lists also an alternative way of counting the words by converting the .dvi file to a plain text file:

dvips -o - report.dvi | ps2ascii | wc -w

However, this way doesn’t seem to filter the .dvi file that good so you may count more commands as words.